VS dos界面双人五子棋

  • W8_808901
    了解作者
  • 260.1KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-16 12:19
    上传日期
自己编写的五子棋游戏,游戏环境是dos界面,不过没写AI算法,只能两人玩,但是dos界面自认为做的比较精美,请大家多多指点
五子棋.rar
  • jh
  • jh
  • Debug
  • cl.command.1.tlog
    694B
  • jh.exe.embed.manifest.res
    472B
  • jh.exe.intermediate.manifest
    381B
  • link.4560-cvtres.read.1.tlog
    2B
  • rc.command.1.tlog
    534B
  • CL.read.1.tlog
    8.7KB
  • vc100.idb
    203KB
  • mt.read.1.tlog
    354B
  • link-cvtres.read.1.tlog
    2B
  • link.read.1.tlog
    2.9KB
  • link.4560.write.1.tlog
    2B
  • rc.read.1.tlog
    326B
  • link.write.1.tlog
    892B
  • CL.write.1.tlog
    408B
  • jh_manifest.rc
    194B
  • vc100.pdb
    236KB
  • jh.exe.embed.manifest
    406B
  • link.command.1.tlog
    1.5KB
  • mt.write.1.tlog
    354B
  • jh.lastbuildstate
    95B
  • link.4560.read.1.tlog
    2B
  • mt.command.1.tlog
    382B
  • rc.write.1.tlog
    334B
  • link-cvtres.write.1.tlog
    2B
  • link.4560-cvtres.write.1.tlog
    2B
  • l.obj
    63.1KB
  • jh.log
    2.2KB
  • l.cpp
    5.2KB
  • jh.vcxproj.user
    143B
  • jh.vcxproj.filters
    939B
  • jh.vcxproj
    3.8KB
  • Debug
  • jh.ilk
    500.1KB
  • jh.exe
    41.5KB
  • jh.pdb
    635KB
  • jh.sln
    873B
  • jh.suo
    10KB
内容介绍
#include <iostream> #include <stdlib.h> using namespace std; const int M=15; //规定棋盘大小 const int N=5; //玩几子棋 void InitChess(char *chess ) { int i; for(i=0;i<=M*M-1;i++) { switch(i){ case 0: chess[i]='1'; break; case 14: chess[i]='2'; break; case 210: chess[i]='3'; break; case 224: chess[i]='4'; break; } if(i>0&&i<14) chess[i]='S'; else if(i>210&&i<224) chess[i]='X'; else if(i>0&&i%15==0&&i<210) chess[i]='Z'; else if(i>14&&(i+1)%15==0&&i<224) chess[i]='Y'; else if(i!=0&&i!=14&&i!=210&&i!=224) chess[i]='K'; } } void BlackMove(char *chess) { int x,y,z; cout<<"-----------player1 please input the x y----------\n"; cin>>x>>y; if(x>15||y>15) { cout<<"Error\n"; BlackMove(chess); } else { z = 15*(x-1)+y-1; if(chess[z]!='1'&&chess[z]!='2'&&chess[z]!='3'&&chess[z]!='4'&&chess[z]!='S'&&chess[z]!='X'&&chess[z]!='Z'&&chess[z]!='Y'&&chess[z]!='K') { cout<<"error,there have one\n"; BlackMove(chess); } if(chess[z]=='1'||chess[z]=='2'&&chess[z]!='3'||chess[z]=='4'||chess[z]=='S'||chess[z]=='X'||chess[z]=='Z'||chess[z]=='Y'||chess[z]=='K') { chess[z]='B'; cout<<endl; } } }; void WhiteMove(char *chess) { int x,y,z; cout<<"-----------player2 please input the x y----------\n"; cin>>x>>y; if(x>15||y>15) { cout<<"Error\n"; WhiteMove(chess); } else { z = 15*(x-1)+y-1; if(chess[z]!='1'&&chess[z]!='2'&&chess[z]!='3'&&chess[z]!='4'&&chess[z]!='S'&&chess[z]!='X'&&chess[z]!='Z'&&chess[z]!='Y'&&chess[z]!='K') { cout<<"error\n"; WhiteMove(chess); } if(chess[z]=='1'||chess[z]=='2'&&chess[z]!='3'||chess[z]=='4'||chess[z]=='S'||chess[z]=='X'||chess[z]=='Z'||chess[z]=='Y'||chess[z]=='K') { chess[z]='W'; cout<<endl; } } }; void ShowChess(char *chess) { int i,j; cout<<" ⒈⒉⒊⒋⒌⒍⒎⒏⒐⒑⒒⒓⒔⒕⒖"<<endl; for(i=0;i<=M*M-1;i++) { if(i%15==0) { j=i/15; switch(j){ case 0: cout<<"⒈"; break; case 1: cout<<"⒉"; break; case 2: cout<<"⒊"; break; case 3: cout<<"⒋"; break; case 4: cout<<"⒌"; break; case 5: cout<<"⒍"; break; case 6: cout<<"⒎"; break; case 7: cout<<"⒏"; break; case 8: cout<<"⒐"; break; case 9: cout<<"⒑"; break; case 10: cout<<"⒒"; break; case 11: cout<<"⒓"; break; case 12: cout<<"⒔"; break; case 13: cout<<"⒕"; break; case 14: cout<<"⒖"; break; } } switch(chess[i]){ case '1': cout<<"┏"; break; case '2': cout<<"┓"<<endl; break; case '3': cout<<"┗"; break; case '4': cout<<"┛"; break; case 'Z': cout<<"┠"; break; case 'S': cout<<"┯"; break; case 'Y': cout<<"┨"<<endl; break; case 'X': cout<<"┷"; break; case 'K': cout<<"┼"; break; case 'B': cout<<"○"; break; case 'W': cout<<"●"; break; } } }; char WinCheck(char *chess) { int i,j,k; for(i=0;i<=M*M;i++) { for(j=0;j<=14;j++) { if(i>=15*j&&i<=15*j+10) { if(chess[i]=='B'&&chess[i+1]=='B'&&chess[i+2]=='B'&&chess[i+3]=='B'&&chess[i+4]=='B') return 'B'; } } if(i<=164) { if((chess[i]=='B')&&(chess[i+15]=='B')&&(chess[i+30]=='B')&&(chess[i+45]=='B')&&(chess[i+60]=='B')) return 'B'; } for(k=4;k<=14;k++) if(i>=k*15&&i<=k*15+10) { if(chess[i]=='B'&&chess[i-14]=='B'&&chess[i-28]=='B'&&chess[i-42]=='B'&&chess[i-56]=='B') return 'B'; } for(k=0;k<=11;k++) if(i<=k*15+10&&i>=k*15) { if(chess[i]=='B'&&chess[i+16]=='B'&&chess[i+32]=='B'&&chess[i+48]=='B'&&chess[i+64]=='B') return 'B'; } } for(i=0;i<=M*M;i++) { for(j=0;j<=14;j++) { if(i>=15*j&&i<=15*j+10) { if(chess[i]=='W'&&chess[i+1]=='W'&&chess[i+2]=='W'&&chess[i+3]=='W'&&chess[i+4]=='W') return 'W'; } } if(i<=164) { if((chess[i]=='W')&&(chess[i+15]=='W')&&(chess[i+30]=='W')&&(chess[i+45]=='W')&&(chess[i+60]=='W')) return 'W'; } for(k=4;k<=14;k++) if(i>=k*15&&i<=k*15+10) { if(chess[i]=='W'&&chess[i-14]=='W'&&chess[i-28]=='W'&&chess[i-42]=='W'&&chess[i-56]=='W') return 'W'; } for(k=0;k<=11;k++) if(i<=k*15+10&&i>=k*15) { if(chess[i]=='W'&&chess[i+16]=='W'&&chess[i+32]=='W'&&chess[i+48]=='W'&&chess[i+64]=='W') return 'W'; } } return '*'; }; int main(void) { char chess[M*M]; char done; cout<<"---Game of Chess---"<<endl; cout<<"player1 against player2"<<endl; done ='*'; InitChess(chess); do{ ShowChess(chess); cout<<endl; BlackMove(chess); system("cls"); done = WinCheck(chess); //检查是否有赢家 if(done!= '*') break; //如有赢家,则跳出循环 ShowChess(chess); cout<<endl; WhiteMove(chess); system("cls"); done = WinCheck(chess); //检查是否有赢家 } while(done== '*'); ShowChess(chess); //显示棋局最终状态 if(done=='B') cout<<endl<<"*********Black won!********"<<endl; else if(done=='W') cout<<endl<<"*********White won!********"<<endl; system("PAUSE"); return 0; }
评论
    相关推荐