飞道的博客

C++游戏game | 井字棋游戏坤坤版(配资源+视频)【赋源码,双人对战】

816人阅读  评论(0)

 

博主主页:Yu·仙笙🦄

专栏:C++游戏game

资源:C++井字棋游戏,双人对战源码【编译通过】

视频:C++井字棋坤坤版

如果不想看代码制作过程及原理,想直接play者,请自行划到文末取源码

目录

一、前期准备

二、获取时间

三、游戏初始背景

四、玩家信息录入

五、玩家投掷骰子确定出手先后

六、玩家选择棋子样式

六、游戏正文执行部分

七、游戏后期处理

源码:


井字棋(Tic Tac Toe),又称井字游戏、"连城"游戏、OX棋,是一种供两人玩的纸笔游戏。两个玩家轮流在九个空格中画上代表自己的O或X,谁先将自己的符号连成一线(横连、竖连、斜连皆可),即获得胜利。倘若在游戏过程中,双方都采取最佳策略,那么游戏往往会以平局告终。井字棋也被应用于人工智能与博弈论的研究。


蔡徐坤(KUN),1998年8月2日出生,中国内地男歌手、演员。

2012年4月,蔡徐坤因参加综艺节目《向上吧!少年》进入全国200强而进入娱乐圈;8月,参演个人首部偶像剧《童话二分之一》。2014年3月,参演个人首部电影《完美假妻168》;2015年7月,蔡徐坤参加真人秀节目《星动亚洲》,并成功进入全国前十五强;2016年10月,蔡徐坤通过10人男子组合SWIN正式出道;2018年1月,参加爱奇艺重点打造的中国首档偶像男团竞演养成类真人秀《偶像练习生》。2018年4月6日,在《偶像练习生》决赛中,蔡徐坤最终排名第一,作为Nine Percent组合成员正式出道。6月15日,参加的纪录片《NINEPERCENT花路之旅》在爱奇艺上线。2018年8月2日,入选福布斯2018年中国“30位30岁以下精英”榜单。8月18日,随组合参加2018微博粉丝嘉年华线下活动。12月18日,担任2019年北京卫视春晚代言人。同年12月,获第十二届音乐盛典咪咕汇年度“最佳彩铃销量歌手”、年度十大金曲《WaitWaitWait》、搜狐时尚盛典“年度人气男明星”以及今日头条年度盛典“年度偶像人物”。2019年2月,首登北京台春晚便包揽词曲,为其创作歌曲《那年春天》。2019年2月19日,蔡徐坤合约案胜诉,与原公司经纪合约解除。3月22日,发布海外公演主题曲《Bigger》。4月19日,发布单曲《Hard To Get》。12月25日,加盟《青春有你第二季》担任青春制作人代表。

---------------------------------------------------------------------------------------------------------------------------------

如果不想看代码制作过程及原理,想直接play者,请自行划到文末取源码

一、前期准备


  
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdlib>
  4. #include<cstdio>
  5. #include<ctime>
  6. using namespace std;
  7. char play[ 9] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };

二、获取时间


  
  1. void system()
  2. {
  3. system( "color FD");
  4. system( "date/t");
  5. system( "time/t");
  6. system( "title 井字棋 Ver:1.0.0");
  7. }

三、游戏初始背景


  
  1. void CSH()
  2. {
  3. cout << "######井字棋小游戏######" << endl;
  4. cout << "(*游戏规则:先掷骰子选出优先下子者,然后轮流下子,任一方若有三子连成一线,该方即获胜)" << endl;
  5. cout << "+---+---+---+\n"
  6. "| " << play[ 0] << " | " << play[ 1] << " | " << play[ 2] << " |\n"
  7. "+---+---+---+\n"
  8. "| " << play[ 3] << " | " << play[ 4] << " | " << play[ 5] << " |\n"
  9. "+---+---+---+\n"
  10. "| " << play[ 6] << " | " << play[ 7] << " | " << play[ 8] << " |\n"
  11. "+---+---+---+\n"<<endl;
  12. cout<< "鸡你太美"<<endl;
  13. cout<< "你干嘛,哎呦"<<endl;
  14. cout<< "-------------------------------------------------------"<<endl;
  15. }
  16. void return_CSH()
  17. {
  18. memset(play, 0, 9);
  19. play[ 0] = '1';
  20. play[ 1] = '2';
  21. play[ 2] = '3';
  22. play[ 3] = '4';
  23. play[ 4] = '5';
  24. play[ 5] = '6';
  25. play[ 6] = '7';
  26. play[ 7] = '8';
  27. play[ 8] = '9';
  28. }

四、玩家信息录入


  
  1. class Player {
  2. public:
  3. Player() {}
  4. void Name(int i)
  5. {
  6. cout << "请为玩家" << i << "设置玩家名称:";
  7. cin >> name;
  8. }
  9. void Get_Name()
  10. {
  11. cout << name;
  12. }

五、玩家投掷骰子确定出手先后


  
  1. int Order()
  2. {
  3. cout << "请玩家 " << name << " 掷骰子:";
  4. system( "pause");
  5. srand(( unsigned) time( NULL));
  6. a = rand() % 6 + 1;
  7. cout << a << endl;
  8. return a;
  9. }
  10. int PD()
  11. {
  12. return a;
  13. }

六、玩家选择棋子样式


  
  1. void XQ_1()
  2. {
  3. cout << "******游戏设置******" << endl;
  4. cout << " 1.O 2.X " << endl;
  5. cout << "请玩家 " << name << " 选择执什么棋(1 或者 2):";
  6. while (xq == 0)
  7. {
  8. cin >> xq;
  9. if (xq == 1)
  10. q1 = 'O';
  11. else if (xq == 2)
  12. q1 = 'X';
  13. else
  14. cout << "命令错误!请重新输入合法选项:";
  15. }
  16. }
  17. void XQ_2()
  18. {
  19. cout << "请玩家 " << name << " 选择执什么棋(1 或者 2):";
  20. while (xq == 0)
  21. {
  22. cin >> xq;
  23. if (xq == 1)
  24. q2 = 'O';
  25. else if (xq == 2)
  26. q2 = 'X';
  27. else
  28. cout << "命令错误!请重新输入合法选项:";
  29. }
  30. }

六、游戏正文执行部分


  
  1. void XS_Play()
  2. {
  3. int n;
  4. cout << "请玩家 " << name << " 输入下棋位置:";
  5. cin >> n;
  6. if (play[n - 1] != 'O' && play[n - 1] != 'X'&&n< 10)
  7. {
  8. play[n - 1] = q1;
  9. }
  10. else
  11. {
  12. cout << "位置不合法!请重新选择:";
  13. cin >> n;
  14. if (play[n - 1] != 'O' && play[n - 1] != 'X' && n < 10)
  15. {
  16. play[n - 1] = q1;
  17. }
  18. else
  19. {
  20. cout << "我感觉你是故意的";
  21. exit( 1);
  22. }
  23. }
  24. system( "cls");
  25. cout << "+---+---+---+\n"
  26. "| " << play[ 0] << " | " << play[ 1] << " | " << play[ 2] << " |\n"
  27. "+---+---+---+\n"
  28. "| " << play[ 3] << " | " << play[ 4] << " | " << play[ 5] << " |\n"
  29. "+---+---+---+\n"
  30. "| " << play[ 6] << " | " << play[ 7] << " | " << play[ 8] << " |\n"
  31. "+---+---+---+\n";
  32. }
  33. void HS_Play()
  34. {
  35. int n;
  36. cout << "请玩家 " << name << " 输入下棋位置:";
  37. cin >> n;
  38. if (play[n - 1] != 'O' && play[n - 1] != 'X' && n < 10)
  39. {
  40. play[n - 1] = q2;
  41. }
  42. else
  43. {
  44. cout << "位置不合法!请重新选择:";
  45. cin >> n;
  46. if (play[n - 1] != 'O' && play[n - 1] != 'X' && n < 10)
  47. {
  48. play[n - 1] = q2;
  49. }
  50. else
  51. {
  52. cout << "你又找茬是吧?";
  53. exit( 1);
  54. }
  55. }
  56. system( "cls");
  57. cout << "+---+---+---+\n"
  58. "| " << play[ 0] << " | " << play[ 1] << " | " << play[ 2] << " |\n"
  59. "+---+---+---+\n"
  60. "| " << play[ 3] << " | " << play[ 4] << " | " << play[ 5] << " |\n"
  61. "+---+---+---+\n"
  62. "| " << play[ 6] << " | " << play[ 7] << " | " << play[ 8] << " |\n"
  63. "+---+---+---+\n";
  64. }
  65. friend int Get_Q1(Player& p1);
  66. friend int Get_Q2(Player& p2);
  67. private:
  68. string name;
  69. int a = 0;
  70. int xq = 0;
  71. char q1, q2;
  72. };
  73. int Get_Q1(Player& p1)
  74. {
  75. return p1.q1;
  76. }
  77. int Get_Q2(Player& p2)
  78. {
  79. return p2.q2;
  80. }
  81. int End()
  82. {
  83. if (play[ 0] == play[ 1] && play[ 1] == play[ 2] && play[ 0] != ' ')
  84. {
  85. if (play[ 0] == 'X')
  86. {
  87. return 1;
  88. }
  89. if (play[ 0] == 'O')
  90. {
  91. return 2;
  92. }
  93. }
  94. if (play[ 3] == play[ 4] && play[ 4] == play[ 5] && play[ 3] != ' ')
  95. {
  96. if (play[ 3] == 'X')
  97. {
  98. return 1;
  99. }
  100. if (play[ 3] == 'O')
  101. {
  102. return 2;
  103. }
  104. }
  105. if (play[ 6] == play[ 7] && play[ 7] == play[ 8] && play[ 6] != ' ')
  106. {
  107. if (play[ 6] == 'X')
  108. {
  109. return 1;
  110. }
  111. if (play[ 6] == 'O')
  112. {
  113. return 2;
  114. }
  115. }
  116. if (play[ 0] == play[ 3] && play[ 3] == play[ 6] && play[ 0] != ' ')
  117. {
  118. if (play[ 0] == 'X')
  119. {
  120. return 1;
  121. }
  122. if (play[ 0] == 'O')
  123. {
  124. return 2;
  125. }
  126. }
  127. if (play[ 1] == play[ 4] && play[ 4] == play[ 7] && play[ 1] != ' ')
  128. {
  129. if (play[ 1] == 'X')
  130. {
  131. return 1;
  132. }
  133. if (play[ 1] == 'O')
  134. {
  135. return 2;
  136. }
  137. }
  138. if (play[ 2] == play[ 5] && play[ 5] == play[ 8] && play[ 2] != ' ')
  139. {
  140. if (play[ 1] == 'X')
  141. {
  142. return 1;
  143. }
  144. if (play[ 1] == 'O')
  145. {
  146. return 2;
  147. }
  148. }
  149. if (play[ 0] == play[ 4] && play[ 4] == play[ 8] && play[ 0] != ' ')
  150. {
  151. if (play[ 0] == 'X')
  152. {
  153. return 1;
  154. }
  155. if (play[ 0] == 'O')
  156. {
  157. return 2;
  158. }
  159. }
  160. if (play[ 2] == play[ 4] && play[ 4] == play[ 6] && play[ 2] != ' ')
  161. {
  162. if (play[ 2] == 'X')
  163. {
  164. return 1;
  165. }
  166. if (play[ 2] == 'O')
  167. {
  168. return 2;
  169. }
  170. }
  171. return 0;
  172. }
  173. int main()
  174. {
  175. system();
  176. CSH();
  177. Player p1;
  178. Player p2;
  179. int xz;
  180. int j = 0;
  181. int xs = 0;
  182. p1. Name( 1);
  183. p2. Name( 2);
  184. while (xs == 0)
  185. {
  186. p1. Order();
  187. p2. Order();
  188. if (p1. PD() > p2. PD())
  189. cout << "\n玩家 ", p1. Get_Name(), cout << " 先手\n" << endl, system( "pause"), system( "cls"), xs = 1;
  190. else if (p1. PD() < p2. PD())
  191. cout << "\n玩家 ", p2. Get_Name(), cout << " 先手\n" << endl, system( "pause"), system( "cls"), xs = 2;
  192. else
  193. cout << "双方点数一样大,请重新掷点数:" << endl;
  194. }
  195. if (xs == 1)
  196. {
  197. p1. XQ_1(), p2. XQ_2();
  198. }
  199. else if (xs == 2)
  200. {
  201. p2. XQ_1(), p1. XQ_2();
  202. }
  203. CSH();
  204. while (j < 5)
  205. {
  206. if (xs == 1)
  207. {
  208. p1. XS_Play();
  209. End();
  210. if ( End() != 0)
  211. {
  212. break;
  213. }
  214. p2. HS_Play();
  215. End();
  216. if ( End() != 0)
  217. {
  218. break;
  219. }
  220. }
  221. if (xs == 2)
  222. {
  223. p2. XS_Play();
  224. End();
  225. if ( End() != 0)
  226. {
  227. break;
  228. }
  229. p1. HS_Play();
  230. End();
  231. if ( End() != 0)
  232. {
  233. break;
  234. }
  235. }
  236. j++;
  237. }
  238. system( "cls");
  239. cout<< "******游戏结束******"<<endl;
  240. cout << "+---+---+---+\n"
  241. "| " << play[ 0] << " | " << play[ 1] << " | " << play[ 2] << " |\n"
  242. "+---+---+---+\n"
  243. "| " << play[ 3] << " | " << play[ 4] << " | " << play[ 5] << " |\n"
  244. "+---+---+---+\n"
  245. "| " << play[ 6] << " | " << play[ 7] << " | " << play[ 8] << " |\n"
  246. "+---+---+---+\n";
  247. if ( End() == 1)
  248. {
  249. if ( Get_Q1(p1) == 'x')
  250. cout << "\n玩家 ", p1. Get_Name(), cout << " 获得胜利!"<<endl;
  251. else
  252. cout << "\n玩家 ", p2. Get_Name(), cout << " 获得胜利!"<<endl;
  253. }
  254. if ( End() == 2)
  255. {
  256. if ( Get_Q1(p1) == 'O')
  257. cout << "\n玩家 ", p1. Get_Name(), cout << " 获得胜利!"<<endl;
  258. else
  259. cout << "\n玩家 ", p2. Get_Name(), cout << " 获得胜利!"<<endl;
  260. }

七、游戏后期处理


  
  1. cout<< "------------------------------"<<endl;
  2. cout<< "********是否继续游戏?********"<<endl;
  3. cout<< "1.重新开始 2.退出游戏"<<endl;
  4. cin>>xz;
  5. switch(xz)
  6. {
  7. case 1: return_CSH(), main(); break;
  8. case 2: return 0; break;
  9. default:cout<< "指令错误,游戏终止!"; break;
  10. }
  11. }

源码


  
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdlib>
  4. #include<cstdio>
  5. #include<ctime>
  6. using namespace std;
  7. char play[ 9] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
  8. void system()
  9. {
  10. system( "color FD");
  11. system( "date/t");
  12. system( "time/t");
  13. system( "title 井字棋 Ver:1.0.0");
  14. }
  15. void CSH()
  16. {
  17. cout << "######井字棋小游戏######" << endl;
  18. cout << "(*游戏规则:先掷骰子选出优先下子者,然后轮流下子,任一方若有三子连成一线,该方即获胜)" << endl;
  19. cout << "+---+---+---+\n"
  20. "| " << play[ 0] << " | " << play[ 1] << " | " << play[ 2] << " |\n"
  21. "+---+---+---+\n"
  22. "| " << play[ 3] << " | " << play[ 4] << " | " << play[ 5] << " |\n"
  23. "+---+---+---+\n"
  24. "| " << play[ 6] << " | " << play[ 7] << " | " << play[ 8] << " |\n"
  25. "+---+---+---+\n"<<endl;
  26. cout<< "鸡你太美"<<endl;
  27. cout<< "你干嘛,哎呦"<<endl;
  28. cout<< "-------------------------------------------------------"<<endl;
  29. }
  30. void return_CSH()
  31. {
  32. memset(play, 0, 9);
  33. play[ 0] = '1';
  34. play[ 1] = '2';
  35. play[ 2] = '3';
  36. play[ 3] = '4';
  37. play[ 4] = '5';
  38. play[ 5] = '6';
  39. play[ 6] = '7';
  40. play[ 7] = '8';
  41. play[ 8] = '9';
  42. }
  43. class Player {
  44. public:
  45. Player() {}
  46. void Name(int i)
  47. {
  48. cout << "请为玩家" << i << "设置玩家名称:";
  49. cin >> name;
  50. }
  51. void Get_Name()
  52. {
  53. cout << name;
  54. }
  55. int Order()
  56. {
  57. cout << "请玩家 " << name << " 掷骰子:";
  58. system( "pause");
  59. srand(( unsigned) time( NULL));
  60. a = rand() % 6 + 1;
  61. cout << a << endl;
  62. return a;
  63. }
  64. int PD()
  65. {
  66. return a;
  67. }
  68. void XQ_1()
  69. {
  70. cout << "******游戏设置******" << endl;
  71. cout << " 1.O 2.X " << endl;
  72. cout << "请玩家 " << name << " 选择执什么棋(1 或者 2):";
  73. while (xq == 0)
  74. {
  75. cin >> xq;
  76. if (xq == 1)
  77. q1 = 'O';
  78. else if (xq == 2)
  79. q1 = 'X';
  80. else
  81. cout << "命令错误!请重新输入合法选项:";
  82. }
  83. }
  84. void XQ_2()
  85. {
  86. cout << "请玩家 " << name << " 选择执什么棋(1 或者 2):";
  87. while (xq == 0)
  88. {
  89. cin >> xq;
  90. if (xq == 1)
  91. q2 = 'O';
  92. else if (xq == 2)
  93. q2 = 'X';
  94. else
  95. cout << "命令错误!请重新输入合法选项:";
  96. }
  97. }
  98. void XS_Play()
  99. {
  100. int n;
  101. cout << "请玩家 " << name << " 输入下棋位置:";
  102. cin >> n;
  103. if (play[n - 1] != 'O' && play[n - 1] != 'X'&&n< 10)
  104. {
  105. play[n - 1] = q1;
  106. }
  107. else
  108. {
  109. cout << "位置不合法!请重新选择:";
  110. cin >> n;
  111. if (play[n - 1] != 'O' && play[n - 1] != 'X' && n < 10)
  112. {
  113. play[n - 1] = q1;
  114. }
  115. else
  116. {
  117. cout << "我感觉你是故意的";
  118. exit( 1);
  119. }
  120. }
  121. system( "cls");
  122. cout << "+---+---+---+\n"
  123. "| " << play[ 0] << " | " << play[ 1] << " | " << play[ 2] << " |\n"
  124. "+---+---+---+\n"
  125. "| " << play[ 3] << " | " << play[ 4] << " | " << play[ 5] << " |\n"
  126. "+---+---+---+\n"
  127. "| " << play[ 6] << " | " << play[ 7] << " | " << play[ 8] << " |\n"
  128. "+---+---+---+\n";
  129. }
  130. void HS_Play()
  131. {
  132. int n;
  133. cout << "请玩家 " << name << " 输入下棋位置:";
  134. cin >> n;
  135. if (play[n - 1] != 'O' && play[n - 1] != 'X' && n < 10)
  136. {
  137. play[n - 1] = q2;
  138. }
  139. else
  140. {
  141. cout << "位置不合法!请重新选择:";
  142. cin >> n;
  143. if (play[n - 1] != 'O' && play[n - 1] != 'X' && n < 10)
  144. {
  145. play[n - 1] = q2;
  146. }
  147. else
  148. {
  149. cout << "你又找茬是吧?";
  150. exit( 1);
  151. }
  152. }
  153. system( "cls");
  154. cout << "+---+---+---+\n"
  155. "| " << play[ 0] << " | " << play[ 1] << " | " << play[ 2] << " |\n"
  156. "+---+---+---+\n"
  157. "| " << play[ 3] << " | " << play[ 4] << " | " << play[ 5] << " |\n"
  158. "+---+---+---+\n"
  159. "| " << play[ 6] << " | " << play[ 7] << " | " << play[ 8] << " |\n"
  160. "+---+---+---+\n";
  161. }
  162. friend int Get_Q1(Player& p1);
  163. friend int Get_Q2(Player& p2);
  164. private:
  165. string name;
  166. int a = 0;
  167. int xq = 0;
  168. char q1, q2;
  169. };
  170. int Get_Q1(Player& p1)
  171. {
  172. return p1.q1;
  173. }
  174. int Get_Q2(Player& p2)
  175. {
  176. return p2.q2;
  177. }
  178. int End()
  179. {
  180. if (play[ 0] == play[ 1] && play[ 1] == play[ 2] && play[ 0] != ' ')
  181. {
  182. if (play[ 0] == 'X')
  183. {
  184. return 1;
  185. }
  186. if (play[ 0] == 'O')
  187. {
  188. return 2;
  189. }
  190. }
  191. if (play[ 3] == play[ 4] && play[ 4] == play[ 5] && play[ 3] != ' ')
  192. {
  193. if (play[ 3] == 'X')
  194. {
  195. return 1;
  196. }
  197. if (play[ 3] == 'O')
  198. {
  199. return 2;
  200. }
  201. }
  202. if (play[ 6] == play[ 7] && play[ 7] == play[ 8] && play[ 6] != ' ')
  203. {
  204. if (play[ 6] == 'X')
  205. {
  206. return 1;
  207. }
  208. if (play[ 6] == 'O')
  209. {
  210. return 2;
  211. }
  212. }
  213. if (play[ 0] == play[ 3] && play[ 3] == play[ 6] && play[ 0] != ' ')
  214. {
  215. if (play[ 0] == 'X')
  216. {
  217. return 1;
  218. }
  219. if (play[ 0] == 'O')
  220. {
  221. return 2;
  222. }
  223. }
  224. if (play[ 1] == play[ 4] && play[ 4] == play[ 7] && play[ 1] != ' ')
  225. {
  226. if (play[ 1] == 'X')
  227. {
  228. return 1;
  229. }
  230. if (play[ 1] == 'O')
  231. {
  232. return 2;
  233. }
  234. }
  235. if (play[ 2] == play[ 5] && play[ 5] == play[ 8] && play[ 2] != ' ')
  236. {
  237. if (play[ 1] == 'X')
  238. {
  239. return 1;
  240. }
  241. if (play[ 1] == 'O')
  242. {
  243. return 2;
  244. }
  245. }
  246. if (play[ 0] == play[ 4] && play[ 4] == play[ 8] && play[ 0] != ' ')
  247. {
  248. if (play[ 0] == 'X')
  249. {
  250. return 1;
  251. }
  252. if (play[ 0] == 'O')
  253. {
  254. return 2;
  255. }
  256. }
  257. if (play[ 2] == play[ 4] && play[ 4] == play[ 6] && play[ 2] != ' ')
  258. {
  259. if (play[ 2] == 'X')
  260. {
  261. return 1;
  262. }
  263. if (play[ 2] == 'O')
  264. {
  265. return 2;
  266. }
  267. }
  268. return 0;
  269. }
  270. int main()
  271. {
  272. system();
  273. CSH();
  274. Player p1;
  275. Player p2;
  276. int xz;
  277. int j = 0;
  278. int xs = 0;
  279. p1. Name( 1);
  280. p2. Name( 2);
  281. while (xs == 0)
  282. {
  283. p1. Order();
  284. p2. Order();
  285. if (p1. PD() > p2. PD())
  286. cout << "\n玩家 ", p1. Get_Name(), cout << " 先手\n" << endl, system( "pause"), system( "cls"), xs = 1;
  287. else if (p1. PD() < p2. PD())
  288. cout << "\n玩家 ", p2. Get_Name(), cout << " 先手\n" << endl, system( "pause"), system( "cls"), xs = 2;
  289. else
  290. cout << "双方点数一样大,请重新掷点数:" << endl;
  291. }
  292. if (xs == 1)
  293. {
  294. p1. XQ_1(), p2. XQ_2();
  295. }
  296. else if (xs == 2)
  297. {
  298. p2. XQ_1(), p1. XQ_2();
  299. }
  300. CSH();
  301. while (j < 5)
  302. {
  303. if (xs == 1)
  304. {
  305. p1. XS_Play();
  306. End();
  307. if ( End() != 0)
  308. {
  309. break;
  310. }
  311. p2. HS_Play();
  312. End();
  313. if ( End() != 0)
  314. {
  315. break;
  316. }
  317. }
  318. if (xs == 2)
  319. {
  320. p2. XS_Play();
  321. End();
  322. if ( End() != 0)
  323. {
  324. break;
  325. }
  326. p1. HS_Play();
  327. End();
  328. if ( End() != 0)
  329. {
  330. break;
  331. }
  332. }
  333. j++;
  334. }
  335. system( "cls");
  336. cout<< "******游戏结束******"<<endl;
  337. cout << "+---+---+---+\n"
  338. "| " << play[ 0] << " | " << play[ 1] << " | " << play[ 2] << " |\n"
  339. "+---+---+---+\n"
  340. "| " << play[ 3] << " | " << play[ 4] << " | " << play[ 5] << " |\n"
  341. "+---+---+---+\n"
  342. "| " << play[ 6] << " | " << play[ 7] << " | " << play[ 8] << " |\n"
  343. "+---+---+---+\n";
  344. if ( End() == 1)
  345. {
  346. if ( Get_Q1(p1) == 'x')
  347. cout << "\n玩家 ", p1. Get_Name(), cout << " 获得胜利!"<<endl;
  348. else
  349. cout << "\n玩家 ", p2. Get_Name(), cout << " 获得胜利!"<<endl;
  350. }
  351. if ( End() == 2)
  352. {
  353. if ( Get_Q1(p1) == 'O')
  354. cout << "\n玩家 ", p1. Get_Name(), cout << " 获得胜利!"<<endl;
  355. else
  356. cout << "\n玩家 ", p2. Get_Name(), cout << " 获得胜利!"<<endl;
  357. }
  358. cout<< "------------------------------"<<endl;
  359. cout<< "********是否继续游戏?********"<<endl;
  360. cout<< "1.重新开始 2.退出游戏"<<endl;
  361. cin>>xz;
  362. switch(xz)
  363. {
  364. case 1: return_CSH(), main(); break;
  365. case 2: return 0; break;
  366. default:cout<< "指令错误,游戏终止!"; break;
  367. }
  368. }


转载:https://blog.csdn.net/djfihhfs/article/details/127683917
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场