Discuz! Board

 找回密码
 立即注册
查看: 560|回复: 0

2048

[复制链接]

661

主题

847

帖子

243万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2435564

烈空座 Lv:100
发表于 2022-10-22 17:14:04 | 显示全部楼层 |阅读模式
  1. #include<iostream>
  2. #include<vector>
  3. #include<ctime>
  4. #include<conio.h>
  5. #include <windows.h>
  6. #include<cstdlib>

  7. using namespace std;

  8. void gotoxy(HANDLE hout, int x, int y);
  9. void getRand();                                                          //棋盘中随机数生成
  10. void printBoard();                          //打印棋盘
  11. bool judgeOver();                           //判断游戏是否结束
  12. void slide();                               //滑动
  13.                        
  14. int m=4, n=4;                                 
  15. int board[100][100];                                //棋盘
  16. char op;                                   //用户操作

  17. bool judgeLeftSlide();
  18. void leftSlide();                            //左滑动

  19. bool judgeRightSlide();
  20. void rightSlide();

  21. bool judgeUpSlide();
  22. void upSlide();

  23. bool judgeDownSlide();
  24. void downSlide();
  25. void reStart();

  26. int main()
  27. {
  28.         HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
  29.     getRand();
  30.     printBoard();
  31.     while (!judgeOver())
  32.     {
  33.         slide();
  34.         gotoxy(hout,0,0);
  35.         getRand();
  36.         printBoard();
  37.     }
  38.     cout << "游戏结束!!!\n";
  39.     system("pause");/**/
  40.     return 0;
  41. }

  42. void slide()
  43. {
  44.    
  45. }


  46. void getRand()
  47. {
  48.     srand(time(0));
  49.     int x, y,val;
  50.     do
  51.     {
  52.         x = rand() % m;
  53.         y = rand() % n;
  54.     } while (board[x][y] != 0);
  55.     val = (rand() % 2 + 1)*2;
  56.     board[x][y] = val;
  57. }

  58. void printBoard()
  59. {
  60.     for (int i = 0; i < m; i++) {
  61.         for (int j = 0; j < n; j++) {
  62.             cout << board[i][j];
  63.             if (j < n-1)
  64.             {
  65.                 cout << "—";
  66.             }
  67.             if (j == n-1 && i < m-1)
  68.             {
  69.                 cout << endl;
  70.                 int count = 0;
  71.                 while (count++ < n-1)
  72.                 {
  73.                     cout << "|  ";
  74.                 }
  75.                 cout << "|" << endl;
  76.             }
  77.         }
  78.     }
  79. }

  80. bool judgeOver()
  81. {
  82.    
  83.         
  84. }

  85. void gotoxy(HANDLE hout, int x, int y){
  86.   COORD pos;
  87.   pos.X = x;
  88.   pos.Y = y;
  89.   SetConsoleCursorPosition(hout, pos);
  90. }

  91. void upSlide()
  92. {
  93.    
  94. }

  95. bool judgeUpSlide(bool mark)
  96. {

  97. }


  98. void reStart()
  99. {
  100.     for (int i = 0; i < m; i++)
  101.         for (int j = 0; j < n; j++) {
  102.             board[i][j] = 0;
  103.         }
  104. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-5-30 12:26 , Processed in 0.062761 second(s), 27 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.. 技术支持 by 巅峰设计

快速回复 返回顶部 返回列表