久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2585|回復(fù): 1
收起左側(cè)

基于嵌入式C的游戲小程序2048代碼

[復(fù)制鏈接]
ID:373861 發(fā)表于 2018-7-18 10:26 | 顯示全部樓層 |閱讀模式
  1. #if defined(UNICODE) && !defined(_UNICODE)
  2.     #define _UNICODE
  3. #elif defined(_UNICODE) && !defined(UNICODE)
  4.     #define UNICODE
  5. #endif
  6. #include <tchar.h>
  7. #include <windows.h>
  8. /*  Declare Windows procedure  */
  9. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  10. /*  Make the class name into a global variable  */
  11. TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");
  12. int WINAPI WinMain (HINSTANCE hThisInstance,
  13.                      HINSTANCE hPrevInstance,
  14.                      LPSTR lpszArgument,
  15.                      int nCmdShow)
  16. {
  17.     HWND hwnd;               /* This is the handle for our window */
  18.     MSG messages;            /* Here messages to the application are saved */
  19.     WNDCLASSEX wincl;        /* Data structure for the windowclass */
  20.     /* The Window structure */
  21.     wincl.hInstance = hThisInstance;
  22.     wincl.lpszClassName = szClassName;
  23.     wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  24.     wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  25.     wincl.cbSize = sizeof (WNDCLASSEX);
  26.     /* Use default icon and mouse-pointer */
  27.     wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  28.     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  29.     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  30.     wincl.lpszMenuName = NULL;                 /* No menu */
  31.     wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  32.     wincl.cbWndExtra = 0;                      /* structure or the window instance */
  33.     /* Use Windows's default colour as the background of the window */
  34.     wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  35.     /* Register the window class, and if it fails quit the program */
  36.     if (!RegisterClassEx (&wincl))
  37.         return 0;
  38.     /* The class is registered, let's create the program*/
  39.     hwnd = CreateWindowEx (
  40.            0,                   /* Extended possibilites for variation */
  41.            szClassName,         /* Classname */
  42.            _T("Code::Blocks Template Windows App"),       /* Title Text */
  43.            WS_OVERLAPPEDWINDOW, /* default window */
  44.            CW_USEDEFAULT,       /* Windows decides the position */
  45.            CW_USEDEFAULT,       /* where the window ends up on the screen */
  46.            544,                 /* The programs width */
  47.            375,                 /* and height in pixels */
  48.            HWND_DESKTOP,        /* The window is a child-window to desktop */
  49.            NULL,                /* No menu */
  50.            hThisInstance,       /* Program Instance handler */
  51.            NULL                 /* No Window Creation data */
  52.            );
  53.     /* Make the window visible on the screen */
  54.     ShowWindow (hwnd, nCmdShow);
  55.     /* Run the message loop. It will run until GetMessage() returns 0 */
  56.     while (GetMessage (&messages, NULL, 0, 0))
  57.     {
  58.         /* Translate virtual-key messages into character messages */
  59.         TranslateMessage(&messages);
  60.         /* Send message to WindowProcedure */
  61.         DispatchMessage(&messages);
  62.     }
  63.     /* The program return-value is 0 - The value that PostQuitMessage() gave */
  64.     return messages.wParam;
  65. }

  66. /*  This function is called by the Windows function DispatchMessage()  */
  67. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  68. {
  69.     switch (message)                  /* handle the messages */
  70.     {
  71.         case WM_DESTROY:
  72.             PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
  73.             break;
  74.         default:                      /* for messages that we don't deal with */
  75.             return DefWindowProc (hwnd, message, wParam, lParam);
  76.     }
  77.     return 0;
  78. }
  79. /*
  80. * Copyright (C) Judge Young
  81. * E-mail: [url=mailto:yjjtc@126.com]yjjtc@126.com[/url]
  82. * Version: 1.0
  83. */
  84. #include <stdio.h>
  85. #include <time.h>    /* 包含設(shè)定隨機(jī)數(shù)種子所需要的time()函數(shù) */
  86. #include <conio.h>   /* 包含Windows平臺上完成輸入字符不帶回顯和回車確認(rèn)的getch()函數(shù) */
  87. #include <windows.h> /* 包含Windows平臺上完成設(shè)定輸出光標(biāo)位置達(dá)到清屏功能的函數(shù) */
  88.     int word[19][60]=
  89. {
  90.    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  91.    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  92.    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  93.    {0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,},
  94.    {0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,},
  95.    {0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,},
  96.    {0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,},
  97.    {0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,},
  98.    {0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,},
  99.    {0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,},
  100.    {0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,},
  101.    {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,},
  102.    {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,},
  103.    {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,},
  104.    {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,},
  105.    {0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,},
  106.    {0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,},
  107.    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
  108.    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}
  109. };
  110. void start_game(); /* 開始游戲 */
  111. void reset_game(); /* 重置游戲 */
  112. /* 往左右上下四個方向移動 */
  113. void move_left();
  114. void move_right();
  115. void move_up();
  116. void move_down();
  117. void refresh_show();    /* 刷新界面顯示 */
  118. void add_rand_num();    /* 生成隨機(jī)數(shù),本程序中僅生成2或4,概率之比設(shè)為2:1 */
  119. void check_game_over(); /* 檢測是否輸?shù)粲螒颍O(shè)定游戲結(jié)束標(biāo)志 */
  120. int get_null_count();   /* 獲取游戲面板上空位置數(shù)量 */
  121. int board[4][4];     /* 游戲數(shù)字面板,抽象為二維數(shù)組 */
  122. int score;           /* 游戲的分 */
  123. int best;            /* 游戲最高分 */
  124. int if_need_add_num; /* 是否需要生成隨機(jī)數(shù)標(biāo)志,1表示需要,0表示不需要 */
  125. int if_game_over;    /* 是否游戲結(jié)束標(biāo)志,1表示游戲結(jié)束,0表示正常 */
  126. /* main函數(shù) 函數(shù)定義 */
  127. int main()
  128. {
  129.     start_game();
  130. }
  131. void printwall()
  132.     {
  133.         HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
  134.     SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
  135.     printf("■");
  136.     }
  137. void DrawMapstart()
  138. {
  139.     //遍歷二維數(shù)組  //
  140.    int i,j;
  141.     for ( i = 0; i < 19; i++)
  142.     {
  143.         for (j = 0; j < 60; j++)
  144.         {
  145.             //if  else  switch
  146.             switch (word[i][j])
  147.             {
  148.             case 0:
  149.                 printf("  ");
  150.                 break;
  151.             case 1:
  152.                 printwall();//紅
  153.                // printf("■");
  154.                 break;

  155.             }
  156.         }
  157.     }
  158. }
  159. /* 開始游戲 函數(shù)定義 */
  160. void start_game()
  161. {
  162.     int id;
  163.     DrawMapstart();
  164.     scanf("%d",&id);
  165.     reset_game();
  166.     char cmd;
  167.     while (1)
  168.     {
  169.         cmd = getch(); /* 接收標(biāo)準(zhǔn)輸入流字符命令 */
  170.         if (if_game_over) /* 判斷是否需已經(jīng)輸?shù)粲螒?*/
  171.         {
  172.             if (cmd == 'y' || cmd == 'Y') /* 重玩游戲 */
  173.             {
  174.                 reset_game();
  175.                 continue;
  176.             }
  177.             else if (cmd == 'n' || cmd == 'N') /* 退出 */
  178.             {
  179.                 return;
  180.             }
  181.             else
  182.             {
  183.                 continue;
  184.             }
  185.         }
  186.         if_need_add_num = 0; /* 先設(shè)定不默認(rèn)需要生成隨機(jī)數(shù),需要時再設(shè)定為1 */
  187.         switch (cmd) /* 命令解析,w,s,a,d字符代表上下左右命令 */
  188.         {
  189.         case 'a':
  190.         case 'A':
  191.         case 75 :
  192.             move_left();
  193.             break;
  194.         case 's':
  195.         case 'S':
  196.         case 80 :
  197.             move_down();
  198.             break;
  199.         case 'w':
  200.         case 'W':
  201.         case 72 :
  202.             move_up();
  203.             break;
  204.         case 'd':
  205.         case 'D':
  206.         case 77 :
  207.             move_right();
  208.             break;
  209.         }
  210.         score > best ? best = score : 1; /* 打破得分紀(jì)錄 */
  211.         if (if_need_add_num) /* 默認(rèn)為需要生成隨機(jī)數(shù)時也同時需要刷新顯示,反之亦然 */
  212.         {
  213.             add_rand_num();
  214.             refresh_show();
  215.         }
  216.     }
  217. }
  218. /* 重置游戲 函數(shù)定義 */
  219. void reset_game()
  220. {
  221.     score = 0;
  222.     if_need_add_num = 1;
  223.     if_game_over = 0;
  224.     /* 了解到游戲初始化時出現(xiàn)的兩個數(shù)一定會有個2,所以先隨機(jī)生成一個2,其他均為0 */
  225.     int n = rand() % 16;
  226.     for (int i = 0; i < 4; i++)
  227.     {
  228.         for (int j = 0; j < 4; j++)
  229.         {
  230.             board[i][j] = (n-- == 0 ? 2 : 0);
  231.         }
  232.     }
  233.     /* 前面已經(jīng)生成了一個2,這里再生成一個隨機(jī)的2或者4,且設(shè)定生成2的概率是4的兩倍 */
  234.     add_rand_num();
  235.     /* 在這里刷新界面并顯示的時候,界面上已經(jīng)默認(rèn)出現(xiàn)了兩個數(shù)字,其他的都為空(值為0) */
  236.     system("cls");
  237.     refresh_show();
  238. }
  239. /* 生成隨機(jī)數(shù) 函數(shù)定義 */
  240. void add_rand_num()
  241. {
  242.     srand(time(0));
  243.     int n = rand() % get_null_count();/* 確定在何處空位置生成隨機(jī)數(shù) */
  244.     for (int i = 0; i < 4; i++)
  245.     {
  246.         for (int j = 0; j < 4; j++)
  247.         {
  248.             if (board[i][j] == 0 && n-- == 0) /* 定位待生成的位置 */
  249.             {
  250.                 board[i][j] = (rand() % 3 ? 2 : 4);/* 確定生成何值,設(shè)定生成2的概率是4的概率的兩倍 */
  251.                 return;
  252.             }
  253.         }
  254.     }
  255. }
  256. /* 獲取空位置數(shù)量 函數(shù)定義 */
  257. int get_null_count()
  258. {
  259.     int n = 0;
  260.     for (int i = 0; i < 4; i++)
  261.     {
  262.         for (int j = 0; j < 4; j++)
  263.         {
  264.             board[i][j] == 0 ? n++ : 1;
  265.         }
  266.     }
  267.     return n;
  268. }
  269. /* 檢查游戲是否結(jié)束 函數(shù)定義 */
  270. void check_game_over()
  271. {
  272.     for (int i = 0; i < 4; i++)
  273.     {
  274.         for (int j = 0; j < 3; j++)
  275.         {
  276.             /* 橫向和縱向比較挨著的兩個元素是否相等,若有相等則游戲不結(jié)束 */
  277.             if (board[i][j] == board[i][j+1] || board[j][i] == board[j+1][i])
  278.             {
  279.                 if_game_over = 0;
  280.                 return;
  281.             }
  282.         }
  283.     }
  284.     if_game_over = 1;
  285. }
  286. /*
  287. * 如下四個函數(shù),實(shí)現(xiàn)上下左右移動時數(shù)字面板的變化算法
  288. * 左和右移動的本質(zhì)一樣,區(qū)別僅僅是列項(xiàng)的遍歷方向相反
  289. * 上和下移動的本質(zhì)一樣,區(qū)別僅僅是行項(xiàng)的遍歷方向相反
  290. * 左和上移動的本質(zhì)也一樣,區(qū)別僅僅是遍歷時行和列互換
  291. */
  292. /* 左移 函數(shù)定義 */
  293. void move_left()
  294. {
  295.     /* 變量i用來遍歷行項(xiàng)的下標(biāo),并且在移動時所有行相互獨(dú)立,互不影響 */
  296.     for (int i = 0; i < 4; i++)
  297.     {
  298.         /* 變量j為列下標(biāo),變量k為待比較(合并)項(xiàng)的下標(biāo),循環(huán)進(jìn)入時k<j */
  299.         for (int j = 1, k = 0; j < 4; j++)
  300.         {
  301.             if (board[i][j] > 0) /* 找出k后面第一個不為空的項(xiàng),下標(biāo)為j,之后分三種情況 */
  302.             {
  303.                 if (board[i][k] == board[i][j]) /* 情況1:k項(xiàng)和j項(xiàng)相等,此時合并方塊并計(jì)分 */
  304.                 {
  305.                     score += board[i][k++] <<= 1;
  306.                     board[i][j] = 0;
  307.                     if_need_add_num = 1; /* 需要生成隨機(jī)數(shù)和刷新界面 */
  308.                 }
  309.                 else if (board[i][k] == 0) /* 情況2:k項(xiàng)為空,則把j項(xiàng)賦值給k項(xiàng),相當(dāng)于j方塊移動到k方塊 */
  310.                 {
  311.                     board[i][k] = board[i][j];
  312.                     board[i][j] = 0;
  313.                     if_need_add_num = 1;
  314.                 }
  315.                 else /* 情況3:k項(xiàng)不為空,且和j項(xiàng)不相等,此時把j項(xiàng)賦值給k+1項(xiàng),相當(dāng)于移動到k+1的位置 */
  316.                 {
  317.                     board[i][++k] = board[i][j];
  318.                     if (j != k) /* 判斷j項(xiàng)和k項(xiàng)是否原先就挨在一起,若不是則把j項(xiàng)賦值為空(值為0) */
  319.                     {
  320.                         board[i][j] = 0;
  321.                         if_need_add_num = 1;
  322.                     }
  323.                 }
  324.             }
  325.         }
  326.     }
  327. }
  328. /* 右移 函數(shù)定義 */
  329. void move_right()
  330. {
  331.     /* 仿照左移操作,區(qū)別僅僅是j和k都反向遍歷 */
  332.     for (int i = 0; i < 4; i++)
  333.     {
  334.         for (int j = 2, k = 3; j >= 0; j--)
  335.         {
  336.             if (board[i][j] > 0)
  337.             {
  338.                 if (board[i][k] == board[i][j])
  339.                 {
  340.                     score += board[i][k--] <<= 1;
  341.                     board[i][j] = 0;
  342.                     if_need_add_num = 1;
  343.                 }
  344.                 else if (board[i][k] == 0)
  345.                 {
  346.                     board[i][k] = board[i][j];
  347.                     board[i][j] = 0;
  348.                     if_need_add_num = 1;
  349.                 }
  350.                 else
  351.                 {
  352.                     board[i][--k] = board[i][j];
  353.                     if (j != k)
  354.                     {
  355.                         board[i][j] = 0;
  356.                         if_need_add_num = 1;
  357.                     }
  358.                 }
  359.             }
  360.         }
  361.     }
  362. }
  363. /* 上移 函數(shù)定義 */
  364. void move_up()
  365. {
  366.     /* 仿照左移操作,區(qū)別僅僅是行列互換后遍歷 */
  367.     for (int i = 0; i < 4; i++)
  368.     {
  369.         for (int j = 1, k = 0; j < 4; j++)
  370.         {
  371.             if (board[j][i] > 0)
  372.             {
  373.                 if (board[k][i] == board[j][i])
  374.                 {
  375.                     score += board[k++][i] <<= 1;
  376.                     board[j][i] = 0;
  377.                     if_need_add_num = 1;
  378.                 }
  379.                 else if (board[k][i] == 0)
  380.                 {
  381.                     board[k][i] = board[j][i];
  382.                     board[j][i] = 0;
  383.                     if_need_add_num = 1;
  384.                 }
  385.                 else
  386.                 {
  387.                     board[++k][i] = board[j][i];
  388.                     if (j != k)
  389.                     {
  390.                         board[j][i] = 0;
  391.                         if_need_add_num = 1;
  392.                     }
  393.                 }
  394.             }
  395.         }
  396.     }
  397. }
  398. /* 下移 函數(shù)定義 */
  399. void move_down()
  400. {
  401.     /* 仿照左移操作,區(qū)別僅僅是行列互換后遍歷,且j和k都反向遍歷 */
  402.     for (int i = 0; i < 4; i++)
  403.     {
  404.         for (int j = 2, k = 3; j >= 0; j--)
  405.         {
  406.             if (board[j][i] > 0)
  407.             {
  408.                 if (board[k][i] == board[j][i])
  409.                 {
  410.                     score += board[k--][i] <<= 1;
  411.                     board[j][i] = 0;
  412.                     if_need_add_num = 1;
  413.                 }
  414.                 else if (board[k][i] == 0)
  415.                 {
  416.                     board[k][i] = board[j][i];
  417.                     board[j][i] = 0;
  418.                     if_need_add_num = 1;
  419.                 }
  420.                 else
  421.                 {
  422.                     board[--k][i] = board[j][i];
  423.                     if (j != k)
  424.                     {
  425.                         board[j][i] = 0;
  426.                         if_need_add_num = 1;
  427.                     }
  428.                 }
  429.             }
  430.         }
  431.     }
  432. }

  433. /* 刷新界面 函數(shù)定義 */
  434. void refresh_show()
  435. {
  436.     /* 重設(shè)光標(biāo)輸出位置方式清屏可以減少閃爍,system("cls")為備用清屏命令,均為Windows平臺相關(guān)*/
  437.     COORD pos = {0, 0};
  438.     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
  439.     printf("\n\n\n\n");
  440.     printf("                GAME: 2048     SCORE: %06d    BEST: %06d\n", score, best);
  441.     printf("             --------------------------------------------------\n\n");
  442.     /* 繪制表格和數(shù)字 */
  443.     printf("                        ┌─--─┬─--─┬─--─┬─--─┐\n");
  444.     for (int i = 0; i < 4; i++)
  445.     {
  446.         printf("                        │");
  447.         for (int j = 0; j < 4; j++)
  448.         {
  449.             if (board[i][j] != 0)
  450.             {
  451.                 if (board[i][j] < 10)
  452.                 {
  453.                     printf("  %d │", board[i][j]);
  454.                 }
  455.                 else if (board[i][j] < 100)
  456.                 {
  457.                     printf(" %d │", board[i][j]);
  458.                 }
  459.                 else if (board[i][j] < 1000)
  460.                 {
  461.                     printf(" %d│", board[i][j]);
  462.                 }
  463.                 else if (board[i][j] < 10000)
  464.                 {
  465.                     printf("%4d│", board[i][j]);
  466.                 }
  467.                 else
  468.                 {
  469.                     int n = board[i][j];
  470.                     for (int k = 1; k < 20; k++)
  471.                     {
  472.                         n >>= 1;
  473.                         if (n == 1)
  474.                         {
  475.                             printf("2^%02d│", k); /* 超過四位的數(shù)字用2的冪形式表示,如2^13形式 */
  476.                             break;
  477.                         }
  478.                     }
  479.                 }
  480.             }
  481.             else printf("    │");
  482.         }
  483.         if (i < 3)
  484.         {
  485.             printf("\n                        ├─--─┼─--─┼─--─┼─--─┤\n");
  486.         }
  487.         else
  488.         {
  489.             printf("\n                        └──--┴─--─┴─--─┴──--┘\n");
  490.         }
  491.     }
  492.     printf("\n");
  493.     printf("             --------------------------------------------------\n");
  494.     printf("                            W↑  A←  →D  ↓S");
  495.     if (get_null_count() == 0)
  496.     {
  497.         check_game_over();
  498.         if (if_game_over) /* 判斷是否輸?shù)粲螒?*/
  499.         {
  500.             printf("\r                    GAME OVER! TRY THE GAME AGAIN? [Y/N]");
  501.         }
  502.     }
  503. }
復(fù)制代碼
回復(fù)

使用道具 舉報

ID:1 發(fā)表于 2018-7-19 03:31 | 顯示全部樓層
此貼需要補(bǔ)全說明后才可獲取積分
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 中文字幕日韩欧美 | a级免费黄色片 | 婷婷综合 | 在线免费小视频 | 一本久久a久久精品亚洲 | 日本欧美黄色片 | 精品国产伦一区二区三区观看体验 | 久久久久久国产 | 日本视频免费 | 免费黄色在线观看 | 伊人久久综合 | 丝袜美腿一区 | 国产在线精品一区二区三区 | a a毛片| 久久精品免费观看 | www.一区二区三区.com | 亚洲一区二区久久 | 在线看黄免费 | 国产精品成人国产乱一区 | 国产福利网站 | 天堂av在线影院 | 国产精品成人一区二区 | 国产色网| 成人激情视频在线播放 | 久草热播 | 亚洲国产精品99久久久久久久久 | 狠狠色狠狠色综合系列 | 97精品国产 | 日批日韩在线观看 | 黄色香蕉视频在线观看 | 午夜网| 狠狠做深爱婷婷综合一区 | 国产成人小视频 | 亚洲精品大全 | 九九热免费在线观看 | 91免费福利视频 | 欧美日韩视频在线 | 999观看免费高清www | 91免费入口 | 天天操 夜夜操 | 亚洲国产一区二区三区在线观看 |