#includeiostream#includeconio.husingnamespacestd;#defineWIDE_AND_LONG20//棋盘的长和宽#defineNAME_LEN20//输入姓名的长度typedefclassGobang{public:intInitPlayerName(char*,char*);intCheckInput(char,int);intCheckIndexInput(char,char,char);intGetPlayerName();intInitBoard();intWriteBoard(char,char,bool);intBeginOrNot();intCheckRow();intCheckColumn();intCheckTopLeft();intCheckTopRight();intCheckDownLeft();intCheckDownRight();intCheckDraw();intCheckFinish();intChess();intShowBoard();private:characBoard[WIDE_AND_LONG][WIDE_AND_LONG];characPlayerOneName[NAME_LEN];characPlayerTwoName[NAME_LEN];}GOBANG;//初始化姓名的缺省值intGOBANG::InitPlayerName(char*pPlayerOne,char*pPlayerTwo){strcpy(acPlayerOneName,pPlayerOne);strcpy(acPlayerTwoName,pPlayerTwo);return0;}//检查输入姓名时是否含非法字符空格和Tab键intGOBANG::CheckInput(charch,intiNameLen){if(''==ch||'\t'==ch){cout含有非法字符!endl;return-1;}if(iNameLenNAME_LEN-1){cout输入超出限定长度!endl;return-1;}return0;}//将棋子放到棋盘中intGOBANG::WriteBoard(charcRow,charcColumn,boolbJudge){intiRow=0;intiColumn=0;if(cRow='0'&&cRow='9'){iRow=static_castint(cRow-'0');}elseif(cRow='A'&&cRow=static_castchar('A'+WIDE_AND_LONG-10-1)){iRow=static_castint((cRow-'A')+10);}else{iRow=static_castint((cRow-'a')+10);}if(cColumn='0'&&cColumn='9'){iColumn=static_castint(cColumn-'0');}elseif(cColumn='A'&&cColumn=static_castchar('A'+WIDE_AND_LONG-10-1)){iColumn=static_castint((cColumn-'A')+10);}else{iColumn=static_castint((cColumn-'a')+10);}if('+'!=acBoard[iRow][iColumn]){cout此处已有棋子!endl;return-1;}if(!bJudge){acBoard[iRow][iColumn]=static_castchar(1);}else{acBoard[iRow][iColumn]=static_castchar(2);}return0;}//检查坐标输入是否合法intGOBANG::CheckIndexInput(charcRow,charcSeparator,charcColumn){if(!cRow||!cSeparator||!cColumn){return-1;}if(!((cRow='0'&&cRow='9')||\(cRow='A'&&cRow=static_castchar('A'+WIDE_AND_LONG-10-1))||\(cRow='a'&&cRow=static_castchar('a'+WIDE_AND_LONG-10-1)))){return-1;}if(''!=cSeparator&&'\t'!=cSeparator&&','!=cSeparator){return-1;}if(!((cColumn='0'&&cColumn='9')||\(cColumn='A'&&cColumn=static_castchar('A'+WIDE_AND_LONG-10-1))||\(cColumn='a'&&cColumn=static_castchar('a'+WIDE_AND_LONG-10-1)))){return-1;}return0;}//获取玩家的昵称intGOBANG::GetPlayerName(){fflush(stdin);charcTemp=0;intiNameLen=0;cout是否自己定义昵称?是(Y),否(任意键):;cTemp=getch();coutendl;if(('y'!=cTemp)&&('Y'!=cTemp)){return0;}fflush(stdin);memset(acPlayerOneName,0,sizeof(acPlayerOneName));memset(acPlayerTwoName,0,sizeof(acPlayerTwoName));cout请玩家一输入昵称:;while('\n'!=(cTemp=getchar())){if(-1==CheckInput(cTemp,iNameLen)){fflush(stdin);cout请玩家一输入昵称:;continue;}acPlayerOneName[iNameLen]=cTemp;iNameLen++;}if(0==iNameLen){strcpy(acPlayerOneName,玩家一);}iNameLen=0;fflush(stdin);cout请玩家二输入昵称:;while('\n'!=(cTemp=getchar())){if(-1==CheckInput(cTemp,iNameLen)){fflush(stdin);cout请玩家二输入昵称:;continue;}acPlayerTwoName[iNameLen]=cTemp;iNameLen++;}if(0==iNameLen){strcpy(acPlayerTwoName,玩家一);}return0;}//初始化棋盘intGOBANG::InitBoard(){intiRow=0;intiColumn=0;for(iRow=0;iRowWIDE_AND_LONG;iRow++){for(iColumn=0;iColumnWIDE_AND_LONG;iColumn++){acBoard[iRow][iColumn]='+';}}return0;}//检查棋盘横向是否存在五子连珠intGOBANG::CheckRow(){intiRow=0;intiColumn=0;intiPlayerOneLen=0;intiPlayerTwoLen=0;for(iRow=0;iRowWIDE_AND_LONG;iRow++){while(iColumnWIDE_AND_LONG){if(static_castchar(1)==acBoard[iRow][iColumn]){iPlayerOneLen++;iPlayerTwoLen=0;}elseif(static_castchar(2)==acBoard[iRow][iColumn]){iPlayerTwoLen++;iPlayerOneLen=0;}else{iPlayerTwoLen=0;iPlayerOneLen=0;}iColumn++;}if(iPlayerOneLen=5){return1;}if(iPlayerTwoLen=5){return2;}iPlayerOneLen=0;iPlayerTwoLen=0;iColumn=0;}return0;}//检查棋盘竖向是否存在五子连珠intGOBANG::CheckColumn(){intiRow=0;intiColumn=0;intiPlayerOneLen=0;intiPlayerTwoLen=0;for(iColumn=0;iColumnWIDE_AND_LONG;iColumn++){while(iRowWIDE_AND_LONG){if(static_castchar(1)==acBoard[iRow][iColumn]){iPlayerOneLen++;iPlayerTwoLen=0;}elseif(static_castchar(2)==acBoard[iRow][iColumn]){iPlayerTwoLen++;iPlayerOneLen=0;}else{iPlayerTwoLen=0;iPlayerOneLen=0;}iRow++;}if(iPlayerOneLen=5){return1;}if(iPlayerTwoLen=5){return2;}iPlayerOneLen=0;iPlayerTwoLen=0;iRow=0;}return0;}//检查棋盘左上方(包括对角线)是否存在五子连珠intGOBANG::CheckTopLeft(){intiRow=0;intiTempRow=0;intiColumn=0;intiPlayerOneLen=0;intiPlayerTwoLen=0;for(iRow=4;iRowWIDE_AND_LONG;iRow++){iTempRow=iRow;while(iTempRow=0){if(static_castchar(1)==acBoard[iTempRow][iColumn]){iPlayerOneLen++;iPlayerTwoLen=0;if(iPlayerOneLen=5){return1;}}elseif(static_castchar(2)==acBoard[iTempRow][iColumn]){iPlayerTwoLen++;iPlayerOneLen=0;if(iPlayerTwoLen=5){return2;}}else{iPlayerTwoLen=0;iPlayerOneLen=0;}iTempRow--;iColumn++;}iPlayerOneLen=0;iPlayerTwoLen=0;iColumn=0;}return0;}//检查棋盘右上方(包括对角线)是否存在五子连珠intGOBANG::CheckTopRight(){intiRow=0;intiColumn=0;intiTempColumn=0;intiPlayerOneLen=0;intiPlayerTwoLen=0;for(iColumn=0;iColumnWIDE_AND_LONG-4;iColumn++){iTempColumn=iColumn;while(iTempColumnWIDE_AND_LONG){if(static_castchar(1)==acBoard[iRow][iTempColumn]){iPlayerOneLen++;iPlayerTwoLen=0;if(iPlayerOneLen=5){return1;}}elseif(static_castchar(2)==acBo