鱼C论坛

 找回密码
 立即注册
查看: 2870|回复: 9

[技术交流] 阶段考核五子棋独立完成了-附源码

[复制链接]
发表于 2016-12-5 22:40:42 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
QQ拼音截图未命名.png
  1. #include <windows.h>
  2. #include <winuser.h>
  3. #define bool unsigned short
  4. #define true 1
  5. #define false 0
  6. #define CHESSBOARD_NUMBER 15//棋盘规格
  7. #define BLACK_CHESS_PIECES 1//定义黑色棋子 值为1
  8. #define WHITE_CHESS_PIECES 2  //定义白色棋子  值为2
  9. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  10. int pr_chess_color;//待下棋子颜色
  11. int z_DrawChessMap(HDC hdc,int extent,int cxClient,int cyClient);//绘制棋盘(设备环境句柄,棋盘规格extent*extent,客户区宽度,客户区高度)
  12. int z_initialise_chessboard(struct st_chess_pieces arr_chessboard[CHESSBOARD_NUMBER][CHESSBOARD_NUMBER], int cxClient, int cyClient, bool is_initialise); // 初始化棋盘, 更新棋盘坐标, 需提供客户区大小, 如果is_initialise值为true, 则初始化棋盘颜色
  13. int z_Draw_chesspieces(struct st_chess_pieces arr_chessboard[CHESSBOARD_NUMBER][CHESSBOARD_NUMBER], HDC hdc,HWND hwnd);//绘制棋子
  14. int z_xiaqi(struct st_chess_pieces arr_chessboard[CHESSBOARD_NUMBER][CHESSBOARD_NUMBER], int x, int y, HWND hwnd);//下棋
  15. int z_is_ok(struct st_chess_pieces arr_chessboard[CHESSBOARD_NUMBER][CHESSBOARD_NUMBER]);//判断是否赢棋,黑子赢返回1,白棋赢返回2

  16. struct st_chess_pieces
  17. {
  18.         int extra;//预留
  19.         int chess_color;//棋子颜色(RGB)
  20.         POINT x_y;//棋子坐标
  21. };
  22. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
  23. {
  24.         static TCHAR szAppName[] = TEXT("MyWindows");
  25.         HWND hwnd;
  26.         MSG msg;
  27.         WNDCLASS wndclass;

  28.         wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  29.         wndclass.lpfnWndProc = WndProc;
  30.         wndclass.cbClsExtra = 0;
  31.         wndclass.cbWndExtra = 0;
  32.         wndclass.hInstance = hInstance;
  33.         wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  34.         wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  35.         wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  36.         wndclass.lpszMenuName = NULL;
  37.         wndclass.lpszClassName = szAppName;

  38.         if (!RegisterClass(&wndclass))
  39.         {
  40.                 MessageBox(NULL, TEXT("这个程序需要在 Windows NT 才能执行!"), szAppName, MB_ICONERROR);
  41.                 return 0;
  42.         }

  43.         hwnd = CreateWindow(szAppName,
  44.                 TEXT("   ↓当前落子颜色     五子棋"),
  45.                 WS_OVERLAPPEDWINDOW,
  46.                 CW_USEDEFAULT,
  47.                 CW_USEDEFAULT,
  48.                 600,
  49.                 600,
  50.                 NULL,
  51.                 NULL,
  52.                 hInstance,
  53.                 NULL);
  54.        
  55.         ShowWindow(hwnd, iCmdShow);
  56.         UpdateWindow(hwnd);

  57.         while (GetMessage(&msg, NULL, 0, 0))
  58.         {
  59.                 TranslateMessage(&msg);
  60.                 DispatchMessage(&msg);
  61.         }

  62.         return msg.wParam;
  63. }

  64. LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  65. {
  66.         static HDC hdc;
  67.         PAINTSTRUCT ps;
  68.         RECT rect;
  69.         POINT cursor_point;
  70.         int iGainer;//胜棋者
  71.         static cx_Client;
  72.         static cy_Client;
  73.         static bool bChessBoard_invalidate;//表示棋盘是否能下棋,true不能下,false能下
  74.         static struct st_chess_pieces arr_chessboard[CHESSBOARD_NUMBER][CHESSBOARD_NUMBER];//棋盘数组

  75.         switch (message)
  76.         {
  77.         case WM_PAINT:
  78.                 hdc = BeginPaint(hwnd, &ps);
  79.                 GetClientRect(hwnd, &rect);
  80.                 z_DrawChessMap(hdc, CHESSBOARD_NUMBER, rect.right, rect.bottom);//绘制棋盘
  81.                 z_Draw_chesspieces(arr_chessboard, hdc,hwnd);//绘制棋子
  82.                 EndPaint(hwnd, &ps);
  83.                 return 0;
  84.         case WM_SIZE:
  85.                 cx_Client = LOWORD(lParam);
  86.                 cy_Client = HIWORD(lParam);
  87.                 z_initialise_chessboard(arr_chessboard, cx_Client ,cy_Client, false);
  88.                 return 0;
  89.         case WM_CREATE:
  90.                 pr_chess_color=WHITE_CHESS_PIECES;
  91.                 return 0;
  92.         case WM_LBUTTONUP://下棋
  93.                 if (bChessBoard_invalidate == true)//棋盘不能下棋,直接返回
  94.                 {
  95.                         return 0;
  96.                 }
  97.                 GetCursorPos(&cursor_point);//获取鼠标在屏幕内坐标
  98.                 ScreenToClient(hwnd, &cursor_point);//将鼠标在屏幕内坐标转换为窗口客户区坐标
  99.                 z_xiaqi(arr_chessboard, cursor_point.x, cursor_point.y, hwnd);//将鼠标坐标传入下棋函数
  100.                 InvalidateRect(hwnd, NULL, true);//发送客户区失效,重绘客户区
  101.                 iGainer = z_is_ok(arr_chessboard);
  102.                 if (iGainer == 1)//黑子胜
  103.                 {
  104.                         MessageBox(hwnd, TEXT("黑子胜!\n双击鼠标左键重新开盘!"), TEXT("提示:"), MB_OK);
  105.                         bChessBoard_invalidate = true;
  106.                 }else if(iGainer ==2 )//白子胜
  107.                 {
  108.                         MessageBox(hwnd,TEXT("白子胜!\n双击鼠标左键重新开盘!"),TEXT("提示:"),MB_OK);
  109.                         bChessBoard_invalidate = true;
  110.                 }

  111.                 return 0;
  112.         case WM_LBUTTONDBLCLK://鼠标左键双击
  113.                 if (MessageBox(hwnd, TEXT("是否重新开局!"), TEXT("提示:"), MB_YESNO) == IDYES)
  114.                 {
  115.                         z_initialise_chessboard(arr_chessboard, cx_Client, cy_Client, true);//初始化棋盘
  116.                         InvalidateRect(hwnd, NULL, true);//发送客户区失效,重绘客户区
  117.                         bChessBoard_invalidate = false;//
  118.                         pr_chess_color = WHITE_CHESS_PIECES;
  119.                 }
  120.                 return 0;
  121.         case WM_DESTROY:
  122.                 PostQuitMessage(0);
  123.                 return 0;
  124.                
  125.         }

  126.         return DefWindowProc(hwnd, message, wParam, lParam);
  127. }


  128. int z_DrawChessMap(HDC hdc,int extent,int cxClient,int cyClient)//绘制棋盘(设备环境句柄,棋盘规格extent*extent,客户区宽度,客户区高度)
  129. {
  130.         int start_x, start_y,end_x,end_y,i;
  131.         POINT rect_x_y[4];//棋盘矩形坐标
  132.         rect_x_y[0].x = cxClient / (extent + 1) - 2;
  133.         rect_x_y[0].y = cyClient / (extent + 1) - 2;
  134.         rect_x_y[1].x = ((cxClient / (extent + 1))*extent) + 2;
  135.         rect_x_y[1].y = cyClient / (extent + 1) - 2;
  136.         rect_x_y[2].x = ((cxClient / (extent + 1))*extent) + 2;
  137.         rect_x_y[2].y = ((cyClient / (extent + 1))*extent) + 2;
  138.         rect_x_y[3].x = cxClient / (extent + 1) - 2;
  139.         rect_x_y[3].y = ((cyClient / (extent + 1))*extent) + 2;
  140.         Polygon(hdc, rect_x_y, 4);//绘制棋盘边框
  141.         //画横线
  142.         for (i = 0; i < extent; i++)
  143.         {
  144.                 start_x = cxClient / (extent+1);
  145.                 start_y =i*(cyClient / (extent + 1)) + (cyClient / (extent + 1));
  146.                 end_x = (cxClient / (extent + 1))*extent;
  147.                 end_y= i*(cyClient / (extent + 1)) + (cyClient / (extent + 1));
  148.                 MoveToEx(hdc, start_x, start_y, NULL);
  149.                 LineTo(hdc, end_x, end_y);
  150.         }
  151.         //画竖线
  152.         for (i = 0; i < extent; i++)
  153.         {
  154.                 start_x = i*(cxClient / (extent + 1))+ (cxClient / (extent + 1));
  155.                 start_y = cyClient / (extent + 1);
  156.                 end_x = (cxClient / (extent + 1))*i+ (cxClient / (extent + 1));
  157.                 end_y =( cyClient / (extent + 1))*extent;
  158.                 MoveToEx(hdc, start_x, start_y, NULL);
  159.                 LineTo(hdc, end_x, end_y);
  160.         }
  161.        
  162.         return 0;
  163. }

  164. int z_initialise_chessboard(struct st_chess_pieces arr_chessboard[CHESSBOARD_NUMBER][CHESSBOARD_NUMBER],int cxClient,int cyClient,bool is_initialise)//初始化棋盘,更新棋盘坐标,需提供客户区大小,如果is_initialise值为true,则初始化棋盘颜色
  165. {
  166.         int i, j;
  167.         int x,y;
  168.         for (i = 0; i < CHESSBOARD_NUMBER; i++)
  169.         {
  170.                 for (j = 0; j < CHESSBOARD_NUMBER; j++)
  171.                 {
  172.                        
  173.                         x = j*(cxClient / (CHESSBOARD_NUMBER+1)) + (cxClient / (CHESSBOARD_NUMBER+1));
  174.                         y = i*(cyClient / (CHESSBOARD_NUMBER+1)) + (cyClient / (CHESSBOARD_NUMBER+1));
  175.                         arr_chessboard[i][j].x_y.x = x;
  176.                         arr_chessboard[i][j].x_y.y = y;
  177.                         if (is_initialise == true)
  178.                         {
  179.                                 arr_chessboard[i][j].chess_color = (int)NULL;
  180.                                 //以下为实验代码
  181.                                 //arr_chessboard[i][j].chess_color = WHITE_CHESS_PIECES;
  182.                         }
  183.                 }
  184.         }
  185.         return 0;
  186. }

  187. int z_Draw_chesspieces(struct st_chess_pieces arr_chessboard[CHESSBOARD_NUMBER][CHESSBOARD_NUMBER], HDC hdc,HWND hwnd)//绘制棋子
  188. {
  189.         int i, j;
  190.         RECT rect;
  191.         int chess_pieces_width;//棋子宽度
  192.         int chess_pieces_height;//棋子高度
  193.         HBRUSH white_brush, black_brush, Old_brush;
  194.         HPEN black_pen, white_pen, Old_pen;
  195.         white_brush = CreateSolidBrush(RGB(255, 255,255));//创建白色画刷
  196.         black_brush = CreateSolidBrush(RGB(64, 25, 43));//创建黑色画刷
  197.         black_pen = CreatePen(PS_SOLID, 1, RGB(34, 14, 23));//创建黑色画笔
  198.         white_pen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));//创建黑白色画笔
  199.         GetClientRect(hwnd, &rect);//获取客户矩形
  200.         chess_pieces_width = (int)(rect.right / (CHESSBOARD_NUMBER + 1))*(double)(1.2 / 3.0);//计算棋子宽度半径
  201.         chess_pieces_height = (int)(rect.bottom / (CHESSBOARD_NUMBER + 1))*(double)(1.2 / 3.0);//计算棋子高度半径
  202.          //绘制棋盘加粗点
  203.         Old_brush = SelectObject(hdc, black_brush);
  204.         Old_pen = SelectObject(hdc, white_pen);
  205.         Ellipse(hdc, arr_chessboard[3][3].x_y.x -5, arr_chessboard[3][3].x_y.y - 5, \
  206.                 arr_chessboard[3][3].x_y.x + 5, arr_chessboard[3][3].x_y.y + 5);
  207.         Ellipse(hdc, arr_chessboard[3][11].x_y.x - 5, arr_chessboard[3][11].x_y.y - 5, \
  208.                 arr_chessboard[3][11].x_y.x + 5, arr_chessboard[3][11].x_y.y + 5);
  209.         Ellipse(hdc, arr_chessboard[11][3].x_y.x - 5, arr_chessboard[11][3].x_y.y - 5, \
  210.                 arr_chessboard[11][3].x_y.x + 5, arr_chessboard[11][3].x_y.y + 5);
  211.         Ellipse(hdc, arr_chessboard[11][11].x_y.x -5, arr_chessboard[11][11].x_y.y - 5, \
  212.                 arr_chessboard[11][11].x_y.x + 5, arr_chessboard[11][11].x_y.y + 5);
  213.         Ellipse(hdc, arr_chessboard[7][7].x_y.x - 5, arr_chessboard[7][7].x_y.y - 5, \
  214.                 arr_chessboard[7][7].x_y.x + 5, arr_chessboard[7][7].x_y.y + 5);
  215.         ////绘制待下棋子
  216.         if (pr_chess_color == WHITE_CHESS_PIECES)//绘制白棋
  217.         {
  218.                 Old_brush = SelectObject(hdc, white_brush);
  219.                 Old_pen = SelectObject(hdc, black_pen);
  220.                 Ellipse(hdc, arr_chessboard[0][0].x_y.x, \
  221.                         arr_chessboard[0][0].x_y.y - (chess_pieces_height * 2), \
  222.                         arr_chessboard[0][0].x_y.x + (chess_pieces_width * 2), \
  223.                         arr_chessboard[0][0].x_y.y -3);
  224.                 SelectObject(hdc, Old_brush);
  225.                 SelectObject(hdc, Old_pen);
  226.         }
  227.         else//绘制黑棋
  228.         {
  229.                 Old_brush = SelectObject(hdc, black_brush);
  230.                 Old_pen = SelectObject(hdc, white_pen);
  231.                 Ellipse(hdc, arr_chessboard[0][0].x_y.x, \
  232.                         arr_chessboard[0][0].x_y.y - (chess_pieces_height*2), \
  233.                         arr_chessboard[0][0].x_y.x + (chess_pieces_width*2), \
  234.                         arr_chessboard[0][0].x_y.y -3);
  235.                 SelectObject(hdc, Old_brush);
  236.                 SelectObject(hdc, Old_pen);
  237.         }
  238.         //绘制待下棋子end
  239.         SelectObject(hdc, Old_brush);
  240.         SelectObject(hdc, Old_pen);

  241.         for (i = 0; i < CHESSBOARD_NUMBER; i++)
  242.         {
  243.                 for (j = 0; j < CHESSBOARD_NUMBER; j++)
  244.                 {
  245.                         if (arr_chessboard[i][j].chess_color == WHITE_CHESS_PIECES)//绘制白棋
  246.                         {
  247.                                 //MessageBox(0, TEXT("hellow"), TEXT("Hi"), MB_OK);
  248.                                 Old_brush = SelectObject(hdc, white_brush);
  249.                                 Old_pen = SelectObject(hdc, black_pen);
  250.                                 Ellipse(hdc, arr_chessboard[i][j].x_y.x - chess_pieces_width, \
  251.                                         arr_chessboard[i][j].x_y.y - chess_pieces_height, \
  252.                                         arr_chessboard[i][j].x_y.x + chess_pieces_width, \
  253.                                         arr_chessboard[i][j].x_y.y + chess_pieces_height);
  254.                                 SelectObject(hdc, Old_brush);
  255.                                 SelectObject(hdc, Old_pen);
  256.                         }
  257.                         else if (arr_chessboard[i][j].chess_color == BLACK_CHESS_PIECES)//绘制黑棋
  258.                         {
  259.                                
  260.                                 Old_brush = SelectObject(hdc, black_brush);
  261.                                 Old_pen = SelectObject(hdc, white_pen);
  262.                                 Ellipse(hdc, arr_chessboard[i][j].x_y.x - chess_pieces_width, \
  263.                                         arr_chessboard[i][j].x_y.y - chess_pieces_height, \
  264.                                         arr_chessboard[i][j].x_y.x + chess_pieces_width, \
  265.                                         arr_chessboard[i][j].x_y.y + chess_pieces_height);
  266.                                 SelectObject(hdc, Old_brush);
  267.                                 SelectObject(hdc, Old_pen);
  268.                         }

  269.                 }
  270.                
  271.         }
  272.        
  273.         DeleteObject(white_pen);
  274.         DeleteObject(white_brush);
  275.         DeleteObject(black_pen);
  276.         DeleteObject(black_brush);
  277.         return 0;
  278. }

  279. int z_xiaqi(struct st_chess_pieces arr_chessboard[CHESSBOARD_NUMBER][CHESSBOARD_NUMBER], int x, int y,HWND hwnd)//下棋
  280. {
  281.         int i, j;
  282.         RECT rect;
  283.         int chess_pieces_width;//棋子宽度
  284.         int chess_pieces_height;//棋子高度
  285.         GetClientRect(hwnd, &rect);//获取客户矩形
  286.         chess_pieces_width = (int)(rect.right / (CHESSBOARD_NUMBER + 1))*(double)(1 / 3.0);//计算棋子宽度
  287.         chess_pieces_height = (int)(rect.bottom / (CHESSBOARD_NUMBER + 1))*(double)(1 / 3.0);//计算棋子高度
  288.         for (i = 0; i < CHESSBOARD_NUMBER; i++)
  289.         {
  290.                 for (j = 0; j < CHESSBOARD_NUMBER; j++)
  291.                 {
  292.                         if ((arr_chessboard[i][j].x_y.x - chess_pieces_width<x) &\
  293.                                 (arr_chessboard[i][j].x_y.y - chess_pieces_height<y) &\
  294.                                 (arr_chessboard[i][j].x_y.x + chess_pieces_width>x) &\
  295.                                 (arr_chessboard[i][j].x_y.y + chess_pieces_height>y) & \
  296.                                 ((arr_chessboard[i][j].chess_color!= WHITE_CHESS_PIECES) \
  297.                                         & (arr_chessboard[i][j].chess_color != BLACK_CHESS_PIECES)))
  298.                         {
  299.                                
  300.                                
  301.                                         arr_chessboard[i][j].chess_color = pr_chess_color;
  302.                                         if (pr_chess_color == WHITE_CHESS_PIECES)
  303.                                         {
  304.                                                 pr_chess_color = BLACK_CHESS_PIECES;
  305.                                         }
  306.                                         else if (pr_chess_color == BLACK_CHESS_PIECES)
  307.                                         {
  308.                                                 pr_chess_color = WHITE_CHESS_PIECES;
  309.                                         }
  310.                                

  311.                         }
  312.                        
  313.                 }
  314.         }
  315.         return 0;
  316. }

  317. int z_is_ok(struct st_chess_pieces arr_chessboard[CHESSBOARD_NUMBER][CHESSBOARD_NUMBER])//判断是否赢棋,黑子赢返回1,白棋赢返回2
  318. {
  319.         int x, y=0, old_x,old_y=0;//
  320.         int black_pieces_count=0;//黑子连子数量
  321.         int white_pieces_count=0;//白子连子数量
  322.         for (x = 0; x <= CHESSBOARD_NUMBER; x++)//左上到右下扫描
  323.         {
  324.                 if (x == CHESSBOARD_NUMBER)
  325.                 {
  326.                         x = CHESSBOARD_NUMBER - 1;
  327.                 }
  328.                 old_x = x;//保存x值,因为while循环中需要改变x值
  329.                 //初始化棋子连子数量为0
  330.                 white_pieces_count = 0;
  331.                 black_pieces_count = 0;
  332.                 while (1)
  333.                 {
  334.                         if (arr_chessboard[x][y].chess_color == WHITE_CHESS_PIECES)//白子连子
  335.                         {
  336.                                 white_pieces_count++;
  337.                                 black_pieces_count = 0;
  338.                         }
  339.                         if (arr_chessboard[x][y].chess_color == BLACK_CHESS_PIECES)//黑子连子
  340.                         {
  341.                                 black_pieces_count++;
  342.                                 white_pieces_count = 0;
  343.                         }
  344.                         else if ((arr_chessboard[x][y].chess_color != WHITE_CHESS_PIECES) & (arr_chessboard[x][y].chess_color != BLACK_CHESS_PIECES))
  345.                          { black_pieces_count = 0; white_pieces_count = 0; }//既不是白子连子也不是黑子连子

  346.                         if (black_pieces_count == 5)//黑子胜,返回1
  347.                         {
  348.                                 return 1;
  349.                         }

  350.                         if(white_pieces_count == 5)//白子胜,返回2
  351.                         {
  352.                                 return 2;
  353.                         }
  354.                         if ((y == (CHESSBOARD_NUMBER - 1)) & (x == (CHESSBOARD_NUMBER - 1)))//判断已寻找到最右下角坐标,结束循环
  355.                         {
  356.                                 goto one;
  357.                         }

  358.                         if((++y>(CHESSBOARD_NUMBER-1)) | (--x<0))//x轴或y轴超出范围,结束当前扫描
  359.                         {
  360.                                 break;
  361.                         }
  362.                        
  363.                 }
  364.                 x = old_x;//还原x进while循环前的值
  365.                 if (x == CHESSBOARD_NUMBER-1)
  366.                 {
  367.                         old_y++;
  368.                         y = old_y;
  369.                 }
  370.                 else
  371.                 {
  372.                         y = 0;
  373.                 }
  374.         }
  375.         one:old_x = 0;
  376.         y = CHESSBOARD_NUMBER-1;
  377.         x = 0;
  378.         while (1)//左下到右上扫描
  379.         {
  380.                 if (y == 0)
  381.                 {
  382.                         y = 0;
  383.                 }
  384.                 white_pieces_count = 0;
  385.                 black_pieces_count = 0;
  386.                 old_y = y;
  387.                 while (1)
  388.                 {
  389.                         if (arr_chessboard[x][y].chess_color == WHITE_CHESS_PIECES)//白子连子
  390.                         {
  391.                                 white_pieces_count++;
  392.                                 black_pieces_count = 0;
  393.                         }
  394.                         if (arr_chessboard[x][y].chess_color == BLACK_CHESS_PIECES)//黑子连子
  395.                         {
  396.                                 black_pieces_count++;
  397.                                 white_pieces_count = 0;
  398.                         }
  399.                         else if ((arr_chessboard[x][y].chess_color != WHITE_CHESS_PIECES) & (arr_chessboard[x][y].chess_color != BLACK_CHESS_PIECES))
  400.                         {
  401.                                 black_pieces_count = 0; white_pieces_count = 0;
  402.                         }//既不是白子连子也不是黑子连子

  403.                         if (black_pieces_count == 5)//黑子胜,返回1
  404.                         {
  405.                                 return 1;
  406.                         }

  407.                         if (white_pieces_count == 5)//白子胜,返回2
  408.                         {
  409.                                 return 2;
  410.                         }
  411.                         if ((y == 0) & (x == (CHESSBOARD_NUMBER - 1)))//判断已寻找到最右上角坐标,结束循环
  412.                         {
  413.                                 goto two;
  414.                         }

  415.                         if ((++y > (CHESSBOARD_NUMBER - 1)) | (++x >(CHESSBOARD_NUMBER - 1)))//x轴或y轴超出范围,结束当前扫描
  416.                         {
  417.                                 break;
  418.                         }

  419.                 }
  420.                 if (old_y == 0)
  421.                 {
  422.                         old_x++;
  423.                         x = old_x;
  424.                         y = 0;
  425.                 }
  426.                 else
  427.                 {
  428.                         x = 0;
  429.                         y = --old_y;
  430.                 }
  431.                
  432.         }
  433. two:       
  434.         for (y = 0; y <= (CHESSBOARD_NUMBER - 1); y++)//横向扫描
  435.         {
  436.                 white_pieces_count = 0;
  437.                 black_pieces_count = 0;
  438.                 for(x=0;x<=(CHESSBOARD_NUMBER-1);x++)
  439.                 {
  440.                         if (arr_chessboard[x][y].chess_color == WHITE_CHESS_PIECES)//白子连子
  441.                         {
  442.                                 white_pieces_count++;
  443.                                 black_pieces_count = 0;
  444.                         }
  445.                         if (arr_chessboard[x][y].chess_color == BLACK_CHESS_PIECES)//黑子连子
  446.                         {
  447.                                 black_pieces_count++;
  448.                                 white_pieces_count = 0;
  449.                         }
  450.                         else if ((arr_chessboard[x][y].chess_color != WHITE_CHESS_PIECES) & (arr_chessboard[x][y].chess_color != BLACK_CHESS_PIECES))
  451.                         {
  452.                                 black_pieces_count = 0; white_pieces_count = 0;
  453.                         }//既不是白子连子也不是黑子连子

  454.                         if (black_pieces_count == 5)//黑子胜,返回1
  455.                         {
  456.                                 return 1;
  457.                         }

  458.                         if (white_pieces_count == 5)//白子胜,返回2
  459.                         {
  460.                                 return 2;
  461.                         }
  462.                 }
  463.         }
  464.         for (x = 0; x <= (CHESSBOARD_NUMBER - 1); x++)//竖向扫描
  465.         {
  466.                 white_pieces_count = 0;
  467.                 black_pieces_count = 0;
  468.                 for (y = 0; y <= (CHESSBOARD_NUMBER - 1); y++)
  469.                 {
  470.                         if (arr_chessboard[x][y].chess_color == WHITE_CHESS_PIECES)//白子连子
  471.                         {
  472.                                 white_pieces_count++;
  473.                                 black_pieces_count = 0;
  474.                         }
  475.                         if (arr_chessboard[x][y].chess_color == BLACK_CHESS_PIECES)//黑子连子
  476.                         {
  477.                                 black_pieces_count++;
  478.                                 white_pieces_count = 0;
  479.                         }
  480.                         else if ((arr_chessboard[x][y].chess_color != WHITE_CHESS_PIECES) & (arr_chessboard[x][y].chess_color != BLACK_CHESS_PIECES))
  481.                         {
  482.                                 black_pieces_count = 0; white_pieces_count = 0;
  483.                         }//既不是白子连子也不是黑子连子

  484.                         if (black_pieces_count == 5)//黑子胜,返回1
  485.                         {
  486.                                 return 1;
  487.                         }

  488.                         if (white_pieces_count == 5)//白子胜,返回2
  489.                         {
  490.                                 return 2;
  491.                         }
  492.                 }
  493.         }
  494.         return 0;
  495. }
复制代码

评分

参与人数 2荣誉 +10 鱼币 +10 贡献 +6 收起 理由
梦想绘制者 + 5 + 5 + 3 支持楼主!先收藏了以后学习一下。
小甲鱼 + 5 + 5 + 3 不得不点赞!

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-12-6 00:32:03 | 显示全部楼层
不错!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-12-6 06:38:29 | 显示全部楼层
真厉害
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-12-6 09:30:16 | 显示全部楼层
厉害了,一步步写。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-12-6 14:50:29 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-12-6 21:08:06 | 显示全部楼层
直接可以运行吗?我没有运行成功欸,是因为哪里出了问题吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-12-6 23:13:15 | 显示全部楼层
厉害啊!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-12-6 23:15:05 | 显示全部楼层
GrievedFool 发表于 2016-12-6 21:08
直接可以运行吗?我没有运行成功欸,是因为哪里出了问题吗?

我是用VS2015编译的,
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-12-7 19:30:31 | 显示全部楼层
mfc编程吗? 最近正好在学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-12-8 19:13:20 | 显示全部楼层
happypiggy 发表于 2016-12-7 19:30
mfc编程吗? 最近正好在学习

是SDK
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-25 19:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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