欢迎来到天天文库
浏览记录
ID:39892606
大小:78.00 KB
页数:6页
时间:2019-07-14
《C++编写五子棋》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、C++编写五子棋本人写的五子棋是在控制台上面可以玩的输入时仅需要输入两个字母表示下棋的行与列,比如下在一行二列,只需要输入ab即可。这里写的是遍历整个棋盘的,所以效率不算太高,但基本能实现五子棋的逻辑。如果需要C语言实现的,可以搜索本人的《C语言编写五子棋》,如果需要黑白棋,可以搜索本人的《C++编写黑白棋》。/********************************************************************created:2012/03/12created:12:3:20128:55filenam
2、e:e:VisualStudio2005Projectsgobanggobanggobang.cppfilepath:e:VisualStudio2005Projectsgobanggobangfilebase:gobangfileext:cppauthor:terranlong*********************************************************************/#includeusingnamespacestd;#defineROW0#defi
3、neCOL1#defineARR_DIAGONAL2#defineATH_DIAGONAL3classGobang{public:Gobang(){init();}voidinit(){count=0;playerid=0;inti,j;for(i=0;i4、d,intdirection);booljudge();boolgameover();private:conststaticintchessboard_size=15;conststaticintlinkcount=5;charchessboard[chessboard_size][chessboard_size];intcount;intplayerid;};voidGobang::gamestart(){while(!gameover()){system("cls");print();input();}}voidGobang::pr5、int(){inti,j;printf("abcdefghijklmno");for(i=0;i6、;scanf("%c%c",&ix,&iy);getchar();x=ix-'a';y=iy-'a';while(x<07、8、x>=chessboard_size9、10、y<011、12、y>=chessboard_size13、14、chessboard[x][y]!='+'){printf("inputerror!!pleaseinputagain:");scanf("%c%c",&ix,&iy);getchar();x=ix-'a';y=iy-'a';}chessboard[x][y]=playerid+1;count++;playerid=cou15、nt%2;}boolGobang::linksame(constchar*head,intdirection){inti;if(*head=='+'){return0;}switch(direction){caseROW:for(i=1;i16、ONAL:for(i=1;i
4、d,intdirection);booljudge();boolgameover();private:conststaticintchessboard_size=15;conststaticintlinkcount=5;charchessboard[chessboard_size][chessboard_size];intcount;intplayerid;};voidGobang::gamestart(){while(!gameover()){system("cls");print();input();}}voidGobang::pr
5、int(){inti,j;printf("abcdefghijklmno");for(i=0;i6、;scanf("%c%c",&ix,&iy);getchar();x=ix-'a';y=iy-'a';while(x<07、8、x>=chessboard_size9、10、y<011、12、y>=chessboard_size13、14、chessboard[x][y]!='+'){printf("inputerror!!pleaseinputagain:");scanf("%c%c",&ix,&iy);getchar();x=ix-'a';y=iy-'a';}chessboard[x][y]=playerid+1;count++;playerid=cou15、nt%2;}boolGobang::linksame(constchar*head,intdirection){inti;if(*head=='+'){return0;}switch(direction){caseROW:for(i=1;i16、ONAL:for(i=1;i
6、;scanf("%c%c",&ix,&iy);getchar();x=ix-'a';y=iy-'a';while(x<0
7、
8、x>=chessboard_size
9、
10、y<0
11、
12、y>=chessboard_size
13、
14、chessboard[x][y]!='+'){printf("inputerror!!pleaseinputagain:");scanf("%c%c",&ix,&iy);getchar();x=ix-'a';y=iy-'a';}chessboard[x][y]=playerid+1;count++;playerid=cou
15、nt%2;}boolGobang::linksame(constchar*head,intdirection){inti;if(*head=='+'){return0;}switch(direction){caseROW:for(i=1;i16、ONAL:for(i=1;i
16、ONAL:for(i=1;i
此文档下载收益归作者所有