五子棋源代码(C++),完美版.docx
- 【下载声明】
1. 本站全部试题类文档,若标题没写含答案,则无答案;标题注明含答案的文档,主观题也可能无答案。请谨慎下单,一旦售出,不予退换。
2. 本站全部PPT文档均不含视频和音频,PPT中出现的音频或视频标识(或文字)仅表示流程,实际无音频或视频文件。请谨慎下单,一旦售出,不予退换。
3. 本页资料《五子棋源代码(C++),完美版.docx》由用户(四川天地人教育)主动上传,其收益全归该用户。163文库仅提供信息存储空间,仅对该用户上传内容的表现方式做保护处理,对上传内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(点击联系客服),我们立即给予删除!
4. 请根据预览情况,自愿下载本文。本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
5. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007及以上版本和PDF阅读器,压缩文件请下载最新的WinRAR软件解压。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 五子棋 源代码 完美
- 资源描述:
-
1、#in elude #in elude using n amespace std; #defi ne WIDE_AND_LONG 20 / 棋盘的长和宽 #defi ne NAME_LEN20 /输入姓名的长度 typedef class Goba ng public: int In itPlayerName(char *, char *); int Check In put(char,i nt); int Check In dex In put(char, char, char); int GetPlayerName(); int In itBoard(); int WriteBoard(c
2、har, char, bool); int Begi nOr Not(); int CheckRow(); int CheckColum n(); int CheckTopLeft(); int CheckTopRight(); int CheckDow nLeft(); int CheckDow nRight(); int CheckDraw(); int CheckFi ni sh(); int Chess(); int ShowBoard(); private: char acBoardWIDE_AND_LONGWIDE_AND_LONG; char acPlayerO neNameNA
3、ME_LEN; char acPlayerTwoNameNAME_LEN; GOBANG; /初始化姓名的缺省值 int GOBANG:I ni tPlayerName(char *pPlayerO ne,char *pPlayerTwo) strcpy(acPlayerO neName,pPlayerO ne); strcpy(acPlayerTwoName,pPlayerTwo); return 0; 检查输入姓名时是否含非法字符空格和Tab 键 int GOBANG:CheckI nput(char ch, i nt iNameLe n) if( = ch | t = ch) cout含
4、有非法字符! NAME_LEN - 1) cout输入超出限定长度!= 0 else if(cRow = A else iRow = static_cast(cRow - a) + 10); if(cColu mn = 0 else if(cColu mn = A else iColu mn = static_cast(cCol umn - a) + 10); if(+ != acBoardiRowiColum n) cout此处已有棋子!endl; return -1; if(!bJudge) acBoardiRowiColu mn = static_cast(1); else acBoar
5、diRowiColu mn = static_cast(2); return 0; /检查坐标输入是否合法 int GOBANG:Checkl ndexl nput(char cRow,char cSeparator,char cColu mn) if(!cRow | !cSeparator | !cColu mn) return -1; if(!(cRow = O if( != cSeparator if(!(cColu mn = O return 0; 获取玩家的昵称 int GOBANG:GetPlayerName() fflush(stdi n); char cTemp = 0; in
6、t iNameLe n = 0; cout是否自己定义昵称?是(Y),否(任意键):; cTemp = getch(); coute ndl; if(y != cTemp) fflush(stdi n); memset(acPlayer On eName,0,sizeof(acPlayer On eName); memset(acPlayerTwoName,0,sizeof(acPlayerTwoName); cout请玩家一输入昵称:; while(n != (cTemp = getchar() if(-1 = Check In put(cTemp,iNameLe n) fflush(std
7、i n); cout请玩家一输入昵称:; con ti nue; acPlayerO neNameiNameLe n = cTemp; iNameLe n+; if(0 = iNameLe n) strcpy(acPlayerOneName,玩家一); iNameLe n = 0; fflush(stdi n); cout请玩家二输入昵称:; while(n != (cTemp = getchar() if(-1 = Check In put(cTemp,iNameLe n) fflush(stdi n); cout请玩家二输入昵称:; con ti nue; acPlayerTwoNamei
8、NameLe n = cTemp; iNameLe n+; if(0 = iNameLe n) strcpy(acPlayerTwoName,玩家一); return 0; /初始化棋盘 int GOBANG:I ni tBoard() int iRow = 0; int iColu mn = 0; for(iRow = 0; iRow WIDE_AND_LONG; iRow+) for(iColu mn = 0; iColu mn WIDE_AND_LONG; iColum n+) acBoardiRowiColu mn = +; return 0; /检查棋盘横向是否存在五子连珠 int
9、GOBANG:CheckRow() int iRow = 0; int iColu mn = 0; int iPlayerO neLe n = 0; int iPlayerTwoLe n = 0; for(iRow = 0; iRow WIDE_AND_LONG; iRow +) while(iColu mn WIDE_AND_LONG) if(static_cast(1) = acBoardiRowiColu mn) iPlayerO neLe n +; iPlayerTwoLe n = 0; else if(static_cast(2) = acBoardiRowiColu mn) iPl
10、ayerTwoLe n +; iPlayerO neLe n = 0; else iPlayerTwoLe n = 0; iPlayerO neLe n = 0; iColu mn +; if(iPlayerO neLe n = 5) return 1; if(iPlayerTwoLe n = 5) return 2; iPlayerO neLe n = 0; iPlayerTwoLe n = 0; iColu mn = 0; return 0; /检查棋盘竖向是否存在五子连珠 int GOBANG:CheckColum n() int iRow = 0; int iColu mn = 0;
11、int iPlayerO neLe n = 0; int iPlayerTwoLe n = 0; for(iColu mn = 0; iColu mn WIDE_AND_LONG; iColu mn +) while(iRow WIDE_AND_LONG) if(static_cast(1) = acBoardiRowiColu mn) iPlayerO neLe n +; iPlayerTwoLe n = 0; else if(static_cast(2) = acBoardiRowiColu mn) iPlayerTwoLe n +; iPlayerO neLe n = 0; else i
12、PlayerTwoLe n = 0; iPlayerO neLe n = 0; iRow +; if(iPlayerO neLe n = 5) return 1; if(iPlayerTwoLe n = 5) return 2; iPlayerO neLe n = 0; iPlayerTwoLe n = 0; iRow = 0; return 0; 检查棋盘左上方(包括对角线)是否存在五子连珠 int GOBANG:CheckTopLeft() int iRow = 0; int iTempRow = 0; int iColu mn = 0; int iPlayerO neLe n = 0;
13、int iPlayerTwoLe n = 0; for(iRow = 4; iRow = 0) if(static_cast(1) = acBoardiTempRowiColu mn) iPlayerO neLe n +; iPlayerTwoLe n = 0; if(iPlayerO neLe n = 5) return 1; else if(static_cast(2) = acBoardiTempRowiColu mn) iPlayerTwoLe n +; iPlayerO neLe n = 0; if(iPlayerTwoLe n = 5) return 2; else iPlayer
14、TwoLe n = 0; iPlayerO neLe n = 0; iTempRow -; iColu mn +; iPlayerO neLe n = 0; iPlayerTwoLe n = 0; iColu mn = 0; return 0; 检查棋盘右上方(包括对角线)是否存在五子连珠 int GOBANG:CheckTopRight() int iRow = 0; int iColu mn = 0; int iTempColu mn = 0; int iPlayerO neLe n = 0; int iPlayerTwoLe n = 0; for(iColu mn = 0; iColu
展开阅读全文