课程设计报告-三子连珠

上传人:人*** 文档编号:487143496 上传时间:2024-01-10 格式:DOC 页数:8 大小:349KB
返回 下载 相关 举报
课程设计报告-三子连珠_第1页
第1页 / 共8页
课程设计报告-三子连珠_第2页
第2页 / 共8页
课程设计报告-三子连珠_第3页
第3页 / 共8页
课程设计报告-三子连珠_第4页
第4页 / 共8页
课程设计报告-三子连珠_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《课程设计报告-三子连珠》由会员分享,可在线阅读,更多相关《课程设计报告-三子连珠(8页珍藏版)》请在金锄头文库上搜索。

1、精选优质文档-倾情为你奉上 课程设计报告 -三子连珠理学院应用物理系 1 郝小龙 课题要求:1.将程序改写成类 。 2.将棋盘扩充成4*4。 3.统计输赢结果并打印输出。进一步改进程序:将if else if 语句改为 for 语句 程序的源代码: /*第2题TICTACTOE游戏-源代码及关键源代码注解如下:*/#include #include void PrintBoard(); / game boardvoid PrintInfo(); / some info about the rules of the game is printedvoid PrintStats(int, int,

2、 int); / prints the stats of the matchvoid IfError(int&, int&); / When invalid input is entered, prints the errorvoid ChoiceOfChar(char&); / Asks the users if they want to play againvoid PromptTurnO(int&, int&); / Prompts the first user for datavoid PromptTurnX(int&, int&); / Second user has to inpu

3、t coordinateschar board33; / array definitionint main() int ROW; / elements of 2 dimensional array! int COLUMN; int FirstPlayer; / number of winning games for first player int SecondPlayer; int Draws; / number of draws in a game FirstPlayer = 0; SecondPlayer = 0; Draws = 0; char choice; choice = Y;

4、/ Initial value is Y in order to initialize the main loop PrintInfo(); while(choice = Y) / In case the players want to play again / this is the main loop for (ROW = 0; ROW 3; ROW+) / these forloops are used to process the array for (COLUMN = 0; COLUMN 3; COLUMN+) / by row and column boardROWCOLUMN=

5、; / blank characters as initial values int x; / (x,y) coordinates entered by the users int y; int SpotsOnBoard; / this is the sum of spots available on the game board SpotsOnBoard = 0; while ( SpotsOnBoard = 9) / because there is only 9 characters available on the board if (SpotsOnBoard = 0) PrintBo

6、ard(); / This function draws initialy the blank game board / so it is easier for the user to pick the x and y values PromptTurnO(x, y); IfError(x, y); / If the users input is invalid, this function prints / the error message and prompts for correction boardx - 1y - 1= O; / actually the array starts

7、from 0, NOT from 1 SpotsOnBoard+; / (as entered by the user) / so the program have to fix the input PrintBoard(); / If 3 coordintates are Os in one of 8 possible /winning combinations, then O wins if (board00= O & board11= O & board22= O) cout O player wins the game endl; FirstPlayer+; break; else i

8、f (board20= O & board11= O & board02= O) cout O player wins the game endl; FirstPlayer+; break; else if (board00= O & board10= O & board20 = O) cout O player wins the game endl; FirstPlayer+; break; else if (board01= O & board11= O & board21= O) cout O player wins the game endl; FirstPlayer+; break;

9、 else if (board02= O & board12= O & board22= O) cout O player wins the game endl; FirstPlayer+; break; else if (board00= O & board01= O & board02= O) cout O player wins the game endl; FirstPlayer+; break; else if (board10= O & board11= O & board12= O) cout O player wins the game endl; FirstPlayer+;

10、break; else if (board20= O & board21= O & board22= O) cout O player wins the game endl; FirstPlayer+; / counts the number of won games break; / break statement is used to make sure that only one possibility / will be processed else if (SpotsOnBoard = 9) cout Draw! endl; Draws+; break; / Without this

11、 brake statement it was not working propertly PromptTurnX(x, y); IfError(x, y); boardx - 1y - 1= X; SpotsOnBoard+; PrintBoard(); if (board00= X & board11= X & board22= X) cout X player is victorious endl; SecondPlayer+; else if (board20= X & board11= X & board02= X) cout X player is victorious endl; SecondPlayer+; else if (board00= X & board10= X & board20= X) cout X player is victorious endl; SecondPlayer+; else if (board01= X & board11= X & board21= X) cout

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 教学/培训

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号