如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
C++编写五子棋本人写的五子棋是在控制台上面可以玩的输入时仅需要输入两个字母表示下棋的行与列,比如下在一行二列,只需要输入ab即可。这里写的是遍历整个棋盘的,所以效率不算太高,但基本能实现五子棋的逻辑。如果需要C语言实现的,可以搜索本人的《C语言编写五子棋》,如果需要黑白棋,可以搜索本人的《C++编写黑白棋》。/********************************************************************created:2012/03/12created:12:3:20128:55filename:e:\VisualStudio2005\Projects\gobang\gobang\gobang.cppfilepath:e:\VisualStudio2005\Projects\gobang\gobangfilebase:gobangfileext:cppauthor:terranlong*********************************************************************/#include<iostream>usingnamespacestd;#defineROW0#defineCOL1#defineARR_DIAGONAL2#defineATH_DIAGONAL3classGobang{public:Gobang(){init();}voidinit(){count=0;playerid=0;inti,j;for(i=0;i<chessboard_size;i++){for(j=0;j<chessboard_size;j++){chessboard[i][j]='+';}}}voidgamestart();voidprint();voidinput();boollinksame(constchar*head,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::print(){inti,j;printf("abcdefghijklmno\n");for(i=0;i<chessboard_size;i++){printf("%c",i+'a');for(j=0;j<chessboard_size;j++){printf("%c",chessboard[i][j]);if(j!=chessboard_size-1){printf("-");}}printf("\n");}}voidGobang::input(){charix,iy;intx,y;printf("player%d:",playerid);scanf("%c%c",&ix,&iy);getchar();x=ix-'a';y=iy-'a';while(x<0||x>=chessboard_size||y<0||y>=chessboard_size||chessboard[x][y]!='+'){printf("inputerror!!\npleaseinputagain:");scanf("%c%c",&ix,&iy);getchar();x=ix-'a';y=iy-'a';}chessboard[x][y]=playerid+1;count++;playerid=count%2;}boolGobang::linksame(constchar*head,intdirection){inti;if(*head=='+'){return0;}switch(direction){caseROW: