Advertisement
Alyks

Untitled

Dec 17th, 2020
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 40.46 KB | None | 0 0
  1. #ifndef CHECKERS_GAME_H
  2. #define CHECKERS_GAME_H
  3.  
  4. #include <windows.h>
  5. #include <commctrl.h>
  6. #include <time.h>
  7. #include <math.h>
  8. #include <errno.h>
  9.  
  10. #include "Cell.h"
  11. #include "Player.h"
  12. #include "AiGame.h"
  13. #include "HumanGame.h"
  14. #include "Menu.h"
  15.  
  16. extern RECT rct;
  17.  
  18. static enum GameModes {
  19.     HUMAN, AI
  20. };
  21.  
  22. extern const int offsetX;
  23. extern const int offsetY;
  24. extern const int fieldSize;
  25.  
  26. extern Player *player1;
  27. extern Player *player2;
  28. extern Player *currentPlayer;
  29. extern int humanTurn;
  30. extern Cell **cells;
  31. extern Cell *lastChosenCell;
  32. extern int gameStarted;
  33. extern int playerCanChangeSide;
  34. extern int gameMode;
  35.  
  36. extern HWND hwnd;
  37. extern HDC dc;
  38. extern HDC memDC;
  39. extern HBITMAP memBM;
  40. extern HMENU hFile;
  41. extern HMENU hInf;
  42.  
  43. Cell **createCells();
  44. void drawBorder(HDC dc);
  45. void drawCell(HDC dc, Cell *cell);
  46. void drawCells(HDC memDC, Cell **cells);
  47. HIMAGELIST getImg(char *path);
  48. void placeFigure(HDC dc, Cell *cell);
  49. void placeFigures(HDC dc, Cell **cells);
  50. Cell *findCell(int x, int y);
  51. void getWay(int wayType, Cell *cell);
  52. int countWay(Cell **way);
  53. void clearWay(Cell **way);
  54. void clearRange(Cell **way, int from, int count);
  55. void removeHighlight(Cell **way, int from, int count);
  56. void restoreHighlight();
  57. int getAllValidWays(Cell *cell, int humanTurn);
  58. void clearWays(Cell *cell);
  59. int getAllWays(Cell *cell, int humanTurn);
  60. void highlightCell(HDC dc, Cell *cell);
  61. void hideHighlight(Cell *cell);
  62. void showWays(HDC dc, Cell *cell);
  63. int wayContains(Cell **way, Cell *cell);
  64. Cell **getPath(Cell *cell);
  65. int wayIndexOf(Cell **way, Cell *cell);
  66. int indexOf(Cell **cells, Cell *cell);
  67. int eat(Cell *cell, Cell **way, int king);
  68. int canEat(Cell *cell);
  69. int getTurnsCount(Cell *cell);
  70. int haveTurns(Player *player);
  71. void swapProps(Cell *cell1, Cell *cell2);
  72. int msleep(long msec);
  73. void changeTurn(int ate, Cell *cell);
  74. void defineFiguresSide();
  75. void changeSide();
  76. void freeMem();
  77. void newGame(HDC dc, int mode);
  78.  
  79. #endif
  80.  
  81. // Game.c
  82.  
  83. #include "Game.h"
  84.  
  85. int getKingZone(int k) {
  86.     int kingZone = NONE;
  87.  
  88.     if (k < 8) kingZone = BLACK; // черные ячейки от 0 индекса до 7 являются королевскими зонами
  89.     else if (k > 55) kingZone = WHITE; // также, как и ячейки с индексом от 56 до 63
  90.  
  91.     return kingZone;
  92. }
  93.  
  94. int getFigure(int k) {
  95.     int figure = NONE;
  96.  
  97.     if (k < 24) figure = BLACK; // черные ячейки с k < 24 имеют черные фигуры
  98.     else if (k > 39) figure = WHITE; // если k > 39, то фигуры белые
  99.  
  100.     return figure;
  101. }
  102.  
  103. void createWays(Cell *cell) {
  104.     cell->ways = malloc(4 * sizeof(Cell **));
  105.  
  106.     for (int n = 0; n < 4; n++) {
  107.         cell->ways[n] = malloc(8 * sizeof(Cell *));
  108.         for (int l = 0; l < 8; l++) {
  109.             cell->ways[n][l] = NULL;
  110.         }
  111.     }
  112. }
  113.  
  114. Cell **createCells() {
  115.     Cell **cells = malloc(8 * sizeof(Cell *)); // выделение памяти
  116.  
  117.     int offset = fieldSize / 8; // показывает, на сколько будут сдвигатся новые ячейки
  118.     int xOffset = 0; // отступ по оси x
  119.     int yOffset = 0; // отступ по оси y
  120.     COLORREF black = 0x00ba8871; // цвет, используемый как черный
  121.     COLORREF white = 0x00e3fcff; // цвет, используемый как белый
  122.     COLORREF lastColor = white; // последний цвет
  123.     int k = 0; // номер создаваемой ячейки
  124.     int pl1LastIndex = 0; // индекс последней ячейки первого игрока
  125.     int pl2LastIndex = 0; // индекс последней ячейки второго игрока
  126.  
  127.     for (int i = 0; i < 8; i++) {
  128.         cells[i] = malloc(8 * sizeof(Cell)); // выделение памяти
  129.  
  130.         COLORREF color;
  131.  
  132.         for (int j = 0; j < 8; j++) {
  133.             int figure = NONE; // ячейка пуста
  134.             int kingZone = NONE; // не является зоной, встав на которую можно превратится в дамку
  135.  
  136.             if (j % 2 == 0) { // если j четное число
  137.                 color = lastColor; // то в color записывается последний цвет
  138.  
  139.                 if (lastColor != white) {
  140.                     kingZone = getKingZone(k); // установка королевской зоны
  141.                     figure = getFigure(k); // установка фигуры
  142.                 }
  143.             } else if (lastColor == white) { // если j нечетное число и последний цвет белый
  144.                 color = black; // то цвет будет черным
  145.  
  146.                 kingZone = getKingZone(k);
  147.                 figure = getFigure(k);
  148.             } else if (lastColor == black) { // если же последний цвет черный
  149.                 color = white; // то текущий будет белым
  150.             }
  151.  
  152.             if (color == white) kingZone = NONE; // если цвет ячейки белый, то королевская зона у такой ячейки будет отсутствовать
  153.  
  154.             Cell *cell = newCell(xOffset + 1, yOffset + 1, color, figure, kingZone); // создание ячейки
  155.  
  156.             if(color == black) createWays(cell); // инициализация массива путей, по которым фигура, сможет передвигаться
  157.  
  158.             cells[i][j] = *cell; // добавление ячейки в массив ячеек
  159.  
  160.             if (figure != NONE) {
  161.                 if (k < 24) {
  162.                     player2->cells[pl2LastIndex++] = &cells[i][j]; // добавление ячейки в массив ячеек второго игрока
  163.                 } else if (k > 39) {
  164.                     player1->cells[pl1LastIndex++] = &cells[i][j]; // добавление ячейки в массив ячеек первого игрока
  165.                 }
  166.             }
  167.  
  168.             xOffset += offset; // увеличение отступа по x на величину offset
  169.             k++; // увеличение индекса ячейки
  170.         }
  171.  
  172.         yOffset += offset; // увеличение отступа по y на величину offset
  173.         xOffset = 0; // сброс отступа по x
  174.         lastColor = color; // установка последнего цвета
  175.     }
  176.  
  177.     return cells; // возврат массива ячеек
  178. }
  179.  
  180. void drawBorder(HDC dc) {
  181.     SelectObject(dc, GetStockObject(DC_PEN));
  182.     SetDCPenColor(dc, RGB(212, 162, 116));
  183.     Rectangle(dc, 0, 0, 602, 602);
  184. }
  185.  
  186. void drawCell(HDC dc, Cell *cell) {
  187.     if (cell == NULL) return; // если ячейка
  188.  
  189.     SelectObject(dc, GetStockObject(DC_BRUSH)); // выбирается кисть
  190.     SetDCBrushColor(dc, cell->background); // установка цвета кисти
  191.     SelectObject(dc, GetStockObject(DC_PEN)); // выбирается перо
  192.     SetDCPenColor(dc, cell->background); // установка цвета пера
  193.     Rectangle(dc, cell->x, cell->y, cell->x + 75, cell->y + 75); // отрисовка прямоугольной области по заданным координатам
  194. }
  195.  
  196. void drawCells(HDC memDC, Cell **cells) {
  197.     for (int i = 0; i < 8; i++) {
  198.         for (int j = 0; j < 8; j++) {
  199.             Cell cell = cells[i][j]; // получение ячейки из массива
  200.             drawCell(memDC, &cell); // вызов функции отрисовки ячейки
  201.         }
  202.     }
  203. }
  204.  
  205. void drawLetters() {
  206.     int offset = fieldSize / 8;
  207.     int xOfsset = 0.8 * offset;
  208.     int charCode = 65;
  209.     char *letter = malloc(2);
  210.     letter[1] = '\0';
  211.  
  212.     for(int i = 0; i < 8; i++) {
  213.         letter[0] = (char) charCode;
  214.         TextOut(dc, xOfsset, 5, letter, strlen(letter));
  215.         xOfsset += offset;
  216.         charCode++;
  217.     }
  218. }
  219.  
  220. void drawNumbers() {
  221.     int offset = fieldSize / 8;
  222.     int yOffset = 0.75 * offset;
  223.     int charCode = 49;
  224.     char *letter = malloc(2);
  225.     letter[1] = '\0';
  226.  
  227.     for(int i = 0; i < 8; i++) {
  228.         letter[0] = (char) charCode;
  229.         TextOut(dc, 7, yOffset, letter, strlen(letter));
  230.         yOffset += offset;
  231.         charCode++;
  232.     }
  233. }
  234.  
  235. HIMAGELIST getImg(char *path) {
  236.     InitCommonControls();
  237.     HIMAGELIST hImagelist = ImageList_Create(60, 60, ILC_COLOR32 | ILC_MASK, 1, 0);
  238.     HBITMAP image = LoadImage(NULL, path, IMAGE_BITMAP, 60, 60, LR_LOADFROMFILE);
  239.     ImageList_AddMasked(hImagelist, image, RGB(0, 0, 0));
  240.     return hImagelist;
  241. }
  242.  
  243. void placeFigure(HDC dc, Cell *cell) {
  244.     if (cell == NULL || cell->figure == NONE) return; // если указатель на ячейку = NULL или у ячейки отстутствует фигура, функция прекращает выполнение
  245.  
  246.     HIMAGELIST list = NULL; // здесь будет хранится изображение фигуры
  247.  
  248.     if (cell->figure == BLACK) {
  249.         if (cell->figureType == KING) list = getImg("images/black_queen.bmp"); // если черная фигура является дамкой, то загружается черная фигура дамки
  250.         else list = getImg("images/black.bmp"); // иначе просто черная фигура
  251.     } else if (cell->figure == WHITE) {
  252.         if (cell->figureType == KING) list = getImg("images/white_queen.bmp");// если белая фигура является дамкой, то загружается белая фигура дамки
  253.         else list = getImg("images/white.bmp"); // иначе просто белая фигура
  254.     }
  255.  
  256.     ImageList_Draw(list, 0, dc, cell->x + 8, cell->y + 7, ILD_NORMAL); // отрисовка изображения
  257.     ImageList_Destroy(list); // освобождение памяти
  258. }
  259.  
  260. void placeFigures(HDC dc, Cell **cells) {
  261.     for (int i = 0; i < 8; i++) {
  262.         for (int j = 0; j < 8; j++) {
  263.             Cell cell = cells[i][j]; // получение ячейки из массива
  264.             placeFigure(dc, &cell); // вызов функции размещения фигуры
  265.         }
  266.     }
  267. }
  268.  
  269. Cell *findCell(int x, int y) {
  270.     int i = floor((y - offsetY) / 75); // Индекс ячейки по координате Y
  271.     int j = floor((x - offsetX) / 75); // Индекс ячейки по координате X
  272.  
  273.     if (i > -1 && i < 8 && j > -1 && j < 8) // Если индексы находятся в необходимом промежутке
  274.         return &cells[i][j]; // То происходит возврат ссылки на ячейку
  275.  
  276.     return NULL; // Иначе возвращается NULL
  277. }
  278.  
  279. void getWay(int wayType, Cell *cell) {
  280.     if (cell == NULL) return;
  281.  
  282.     int i = floor((cell->y) / 75);
  283.     int j = floor((cell->x) / 75);
  284.     int k = 0;
  285.  
  286.     if (wayType == LEFT_TOP) {
  287.         i--;
  288.         j--;
  289.         while (i > -1 && j > -1) { // leftTop
  290.             cell->ways[0][k] = &cells[i][j];
  291.             i--;
  292.             j--;
  293.             k++;
  294.         }
  295.     }
  296.  
  297.     if (wayType == RIGHT_TOP) {
  298.         i--;
  299.         j++;
  300.         while (i > -1 && j < 8) {
  301.             cell->ways[1][k] = &cells[i][j];
  302.             i--;
  303.             j++;
  304.             k++;
  305.         }
  306.     }
  307.  
  308.     if (wayType == LEFT_BOTTOM) {
  309.         i++;
  310.         j--;
  311.         while (i < 8 && j > -1) { // leftTop
  312.             cell->ways[2][k] = &cells[i][j];
  313.             i++;
  314.             j--;
  315.             k++;
  316.         }
  317.     }
  318.  
  319.     if (wayType == RIGHT_BOTTOM) {
  320.         i++;
  321.         j++;
  322.         while (i < 8 && j < 8) { // leftTop
  323.             cell->ways[3][k] = &cells[i][j];
  324.             i++;
  325.             j++;
  326.             k++;
  327.         }
  328.     }
  329. }
  330.  
  331. int countWay(Cell **way) {
  332.     int count = 0;
  333.  
  334.     for (int i = 0; i < 8; i++) {
  335.         if (way[i] != NULL) count++;
  336.     }
  337.  
  338.     return count;
  339. }
  340.  
  341. void clearWay(Cell **way) {
  342.     for (int i = 0; i < 8; i++) {
  343.         way[i] = NULL;
  344.     }
  345. }
  346.  
  347. void clearRange(Cell **way, int from, int count) {
  348.     int cleared = 0;
  349.     for (int i = from; i < 8 && cleared < count; i++) {
  350.         if (way[i] != NULL) {
  351.             way[i] = NULL;
  352.             cleared++;
  353.         }
  354.     }
  355. }
  356.  
  357. void removeHighlight(Cell **way, int from, int count) {
  358.     for (int i = from; i < 8 && i < from + count; i++) {
  359.         if (way[i] != NULL) way[i]->highlightPath = 0;
  360.     }
  361. }
  362.  
  363. void restoreHighlight() {
  364.     for (int i = 0; i < 8; i++) {
  365.         for (int j = 0; j < 8; j++) {
  366.             cells[i][j].highlightPath = 1;
  367.         }
  368.     }
  369. }
  370.  
  371. int getAllValidWays(Cell *cell, int humanTurn) {
  372.     if (cell == NULL) return 0; // Если указатель на ячейку NULL, то возвращаем 0
  373.  
  374.     int eat[4] = {0, 0, 0, 0}; // Данный массив показывает, по каким направлением возможно взятие фигуры противника
  375.     int mustEat = 0; // Должна ли фигура бить другую фигуру
  376.  
  377.     for (int i = 0; i < 4; i++) {
  378.         Cell **way = cell->ways[i]; // Получение текущего пути
  379.         int wayCount = countWay(way); // Количество ячеек в данном пути
  380.  
  381.         if (cell->figure != NONE && wayCount > 0) {
  382.             if (cell->figureType == NORMAL) { // Если фигура является обычной
  383.                 if (way[0]->figure == NONE) { // То происходит проверка на соседнюю пустую ячейку
  384.                     if ((humanTurn && i > 1) || (!humanTurn && i < 2)) clearWay(way); // Если проверяются задние пути для текущего игрока, то они очищаются
  385.                     else clearRange(way, 1, wayCount - 1); // Иначе очищается все, кроме найденной соседней ячейки
  386.                 } else if (wayCount > 1 && way[0]->figure != cell->figure && way[0]->figure != NONE &&
  387.                            way[1]->figure == NONE) { // Если имеется возможность побить вражескую фигуру
  388.                     removeHighlight(way, 0, 1); // То у такой фигуры удаляется подсветка, т. к. на занимаемую такой фигурой ячейку нельзя наступить
  389.  
  390.                     clearRange(way, 2, wayCount - 2); // Очищается путь
  391.                     eat[i] = 1; // На данном пути нужно есть
  392.                     mustEat = 1; // Данная ячейка должна есть
  393.                 } else {
  394.                     clearWay(way); // Если оба условия не сработали, то путь очищается
  395.                 }
  396.             } else if (cell->figureType == KING) { // Если фигура является дамкой
  397.                 int stop = 0; // Отвечает за выход из цикла
  398.                 int j = 0;
  399.                 int rangeCleared = 0; // Показывает, был ли очищен путь
  400.  
  401.                 while (!stop && j < 8) {
  402.                     if (way[j] != NULL) { // Если путь существует
  403.                         if (way[j]->figure == cell->figure) { // Если встречена своя фигура
  404.                             clearRange(way, j, wayCount - j); // То путь очищается до этой фигуры
  405.                             stop = 1; // И просиходит выход из цикла
  406.                         } else if (j + 1 < 8 && way[j + 1] != NULL && way[j]->figure != NONE && way[j + 1]->figure == NONE) { // Если есть возможность побить другие фигуры
  407.                             removeHighlight(way, j, 1); // То на данных фигурах удаляется подсветка
  408.  
  409.                             if (!rangeCleared) { // Если путь не очищен
  410.                                 clearRange(way, 0, j); // То он очищается
  411.                                 rangeCleared = 1;
  412.                             }
  413.  
  414.                             eat[i] = 1; // На данном пути нужно есть
  415.                             mustEat = 1; // Данная ячейка должна есть
  416.                         } else if (way[j]->figure != NONE) { // Если встречена любая другая фигура
  417.                             clearRange(way, j, wayCount - j); // То часть пути очищается
  418.                             stop = 1; // И происходит выход из цикла
  419.                         }
  420.                     }
  421.  
  422.                     j++;
  423.                 }
  424.             }
  425.         }
  426.  
  427.         if (mustEat) { // Если ячейка должна есть
  428.             for (int j = 0; j <= i; j++) {
  429.                 if (!eat[j]) clearWay(cell->ways[j]); // То очищаются все пути, где можно было не есть
  430.             }
  431.         }
  432.     }
  433.  
  434.     return mustEat; // Возврат значения
  435. }
  436.  
  437. void clearWays(Cell *cell) {
  438.     for (int i = 0; i < 4; i++) {
  439.         if (cell != NULL) clearWay(cell->ways[i]);
  440.     }
  441. }
  442.  
  443. int getAllWays(Cell *cell, int humanTurn) {
  444.     clearWays(cell);
  445.  
  446.     getWay(LEFT_TOP, cell);
  447.     getWay(RIGHT_TOP, cell);
  448.     getWay(LEFT_BOTTOM, cell);
  449.     getWay(RIGHT_BOTTOM, cell);
  450.  
  451.     return getAllValidWays(cell, humanTurn);
  452. }
  453.  
  454. void highlightCell(HDC dc, Cell *cell) {
  455.     if (cell != NULL && cell->highlightPath) { // Если указатель на ячейку не NULL и ее следует подсветить
  456.         SelectObject(dc, GetStockObject(DC_PEN)); // То выбирается перо
  457.         SetDCPenColor(dc, RGB(59, 221, 143)); // И устанавливается цвет пера
  458.         SelectObject(dc, GetStockObject(DC_BRUSH)); // Затем выбирается кисть
  459.         SetDCBrushColor(dc, RGB(59, 221, 143)); // И устанавливается увет для пера
  460.  
  461.         Rectangle(dc, cell->x, cell->y, cell->x + 75, cell->y + 75); // Далее происходит отрисовка прямоугольника по области ячейки
  462.         placeFigure(dc, cell); // И размещается фигура
  463.     }
  464. }
  465.  
  466. void hideHighlight(Cell *cell) {
  467.     drawCell(memDC, cell);
  468.     placeFigure(memDC, cell);
  469.  
  470.     for (int i = 0; i < 4; i++) {
  471.         Cell **way = cell->ways[i];
  472.  
  473.         for (int j = 0; j < 8; j++) {
  474.             drawCell(memDC, way[j]);
  475.             placeFigure(memDC, way[j]);
  476.         }
  477.     }
  478. }
  479.  
  480. void showWays(HDC dc, Cell *cell) {
  481.     for (int i = 0; i < 4; i++) {
  482.         Cell **way = cell->ways[i];
  483.  
  484.         for (int j = 0; j < 8; j++) {
  485.             highlightCell(dc, way[j]);
  486.         }
  487.     }
  488. }
  489.  
  490. int wayContains(Cell **way, Cell *cell) {
  491.     for (int i = 0; i < 8; i++) {
  492.         if (way[i] == cell) return 1;
  493.     }
  494.  
  495.     return 0;
  496. }
  497.  
  498. Cell **getPath(Cell *cell) {
  499.     if (lastChosenCell == NULL) return NULL;
  500.  
  501.     for (int i = 0; i < 4; i++) {
  502.         Cell **way = lastChosenCell->ways[i];
  503.  
  504.         for (int j = 0; j < 8; j++) {
  505.             if (wayContains(way, cell) && cell->highlightPath) return way;
  506.         }
  507.     }
  508. }
  509.  
  510. int wayIndexOf(Cell **way, Cell *cell) {
  511.     for (int i = 0; i < 8; i++) {
  512.         if (way[i] == cell) return i;
  513.     }
  514.  
  515.     return -1;
  516. }
  517.  
  518. int indexOf(Cell **cells, Cell *cell) {
  519.     for (int i = 0; i < 12; i++) {
  520.         if (cells[i] == cell) return i;
  521.     }
  522.  
  523.     return -1;
  524. }
  525.  
  526. int eat(Cell *cell, Cell **way, int king) {
  527.     int ate = 0;
  528.     int destIndex = wayIndexOf(way, cell);
  529.  
  530.     for (int i = 0; i < 8; i++) {
  531.         if (way[i] != NULL && way[i]->figure != NONE && ((king && destIndex > i) || !king)) {
  532.             way[i]->figure = NONE;
  533.             ate = 1;
  534.         }
  535.     }
  536.  
  537.     return ate;
  538. }
  539.  
  540. int canEat(Cell *cell) {
  541.     return getAllWays(cell, humanTurn);
  542. }
  543.  
  544. int getTurnsCount(Cell *cell) {
  545.     int turns = 0;
  546.  
  547.     for (int i = 0; i < 4; i++) {
  548.         if (cell != NULL) turns += countWay(cell->ways[i]);
  549.     }
  550.  
  551.     return turns;
  552. }
  553.  
  554. int haveTurns(Player *player) {
  555.     int humanTurn = player == player1 ? 1 : 0;
  556.  
  557.     for (int i = 0; i < 12; i++) {
  558.         getAllWays(player->cells[i], humanTurn);
  559.         int count = getTurnsCount(player->cells[i]);
  560.         if (player->cells[i]->figure != NONE && player->cells[i]->figure == player->side && count > 0) {
  561.             return 1;
  562.         }
  563.     }
  564.  
  565.     return 0;
  566. }
  567.  
  568. void swapProps(Cell *cell1, Cell *cell2) {
  569.     int figure = cell1->figure;
  570.     int figureType = cell1->figureType;
  571.     cell1->figure = cell2->figure;
  572.     cell1->figureType = cell2->figureType;
  573.     cell2->figure = figure;
  574.     cell2->figureType = figureType;
  575. }
  576.  
  577. int msleep(long msec) {
  578.     struct timespec ts;
  579.     int res;
  580.  
  581.     if (msec < 0) {
  582.         errno = EINVAL;
  583.         return -1;
  584.     }
  585.  
  586.     ts.tv_sec = msec / 1000;
  587.     ts.tv_nsec = (msec % 1000) * 1000000;
  588.  
  589.     do {
  590.         res = nanosleep(&ts, NULL);
  591.     } while (res && errno == EINTR);
  592.  
  593.     return res;
  594. }
  595.  
  596. int isGameOver() {
  597.     int noTurns1 = !haveTurns(player1);
  598.     int noTurns2 = !haveTurns(player2);
  599.  
  600.     if (noTurns1 || noTurns2) {
  601.         BitBlt(dc, 25, 25, 602, 602, memDC, 0, 0, SRCCOPY);
  602.  
  603.         if ((noTurns1 && player1->side == WHITE) || (noTurns2 && player2->side == WHITE)) {
  604.             MessageBox(hwnd, "Победили чёрные", "Игра завершена", MB_OK | MB_ICONINFORMATION);
  605.         } else if ((noTurns1 && player1->side == BLACK) || (noTurns2 && player2->side == BLACK)) {
  606.             MessageBox(hwnd, "Победили белые", "Игра завершена", MB_OK | MB_ICONINFORMATION);
  607.         }
  608.  
  609.         writeStats(humanTurn);
  610.  
  611.         ReleaseDC(hwnd, memDC);
  612.         newGame(dc, gameMode);
  613.         return 1;
  614.     }
  615.  
  616.     return 0;
  617. }
  618.  
  619. void changeTurn(int ate, Cell *cell) {
  620.     if(isGameOver()) return;
  621.  
  622.     if (playerCanChangeSide) {
  623.         playerCanChangeSide = 0;
  624.         EnableMenuItem(hFile, 2, MF_GRAYED);
  625.     }
  626.  
  627.     if (!ate || !canEat(cell)) { // Если в результате хода не была съедена фигура или данная ячейка не может больше есть
  628.         humanTurn = !humanTurn; // То происходит смена хода
  629.         currentPlayer->mustMove = NULL;
  630.         currentPlayer = humanTurn ? player1 : player2;
  631.     } else {
  632.         currentPlayer->mustMove = cell; // Иначе полю mustMove будет присвоен указатель на данную ячейку
  633.     }
  634.  
  635.     if (gameMode == AI && !humanTurn) moveFigure();
  636. }
  637.  
  638. void defineFiguresSide() {
  639.     for (int i = 0; i < 12; i++) {
  640.         player1->cells[i]->figure = player1->side;
  641.         player2->cells[i]->figure = player2->side;
  642.  
  643.         if (i < 8) {
  644.             if (cells[0][i].kingZone != NONE) cells[0][i].kingZone = player2->side;
  645.             if (cells[7][i].kingZone != NONE) cells[7][i].kingZone = player1->side;
  646.         }
  647.     }
  648. }
  649.  
  650. void changeSide() {
  651.     int isWhite = player1->side == WHITE;
  652.     humanTurn = !humanTurn;
  653.  
  654.     if (isWhite) {
  655.         player1->side = BLACK;
  656.         player2->side = WHITE;
  657.         currentPlayer = player2;
  658.     } else {
  659.         player1->side = WHITE;
  660.         player2->side = BLACK;
  661.         currentPlayer = player1;
  662.     }
  663.  
  664.     defineFiguresSide();
  665.  
  666.     drawCells(memDC, cells);
  667.     placeFigures(memDC, cells);
  668.  
  669.     if (gameMode == AI && !humanTurn) {
  670.         moveFigure();
  671.         playerCanChangeSide = 0;
  672.         EnableMenuItem(hFile, 2, MF_GRAYED);
  673.     }
  674.  
  675.     BitBlt(dc, 25, 25, 602, 602, memDC, 0, 0, SRCCOPY);
  676. }
  677.  
  678. void freeMem() {
  679.     if (gameStarted) {
  680.         for (int i = 0; i < 8; i++) {
  681.             for (int j = 0; j < 8; j++) {
  682.                 free(cells[i][j].ways);
  683.             }
  684.             free(cells[i]);
  685.         }
  686.  
  687.         free(cells);
  688.         free(player1);
  689.         free(player2);
  690.         ReleaseDC(hwnd, memDC);
  691.         DeleteObject(memBM);
  692.  
  693.         player1 = NULL;
  694.         player2 = NULL;
  695.         cells = NULL;
  696.         lastChosenCell = NULL;
  697.         currentPlayer = NULL;
  698.         memDC = NULL;
  699.         memBM = NULL;
  700.     }
  701. }
  702.  
  703. void newGame(HDC dc, int mode) {
  704.     int side1 = player1 != NULL ? player1->side : WHITE;
  705.     int side2 = player2 != NULL ? player2->side : BLACK;
  706.     freeMem();
  707.     memDC = CreateCompatibleDC(dc);
  708.     memBM = CreateCompatibleBitmap(dc, rct.right - rct.left, rct.bottom - rct.top);
  709.     SelectObject(memDC, memBM);
  710.  
  711.     player1 = newPlayer(side1);
  712.     player2 = newPlayer(side2);
  713.     currentPlayer = side1 == WHITE ? player1 : player2;
  714.     humanTurn = side1 == WHITE;
  715.  
  716.     cells = createCells();
  717.     defineFiguresSide();
  718.  
  719.     drawBorder(memDC);
  720.     drawCells(memDC, cells);
  721.     placeFigures(memDC, cells);
  722.     drawLetters();
  723.     drawNumbers();
  724.  
  725.     gameStarted = 1;
  726.     gameMode = mode;
  727.  
  728.     if (gameMode == AI && !humanTurn) {
  729.         moveFigure();
  730.         playerCanChangeSide = 0;
  731.     } else if (!playerCanChangeSide) {
  732.         playerCanChangeSide = 1;
  733.         EnableMenuItem(hFile, 2, MF_ENABLED);
  734.     }
  735.  
  736.     BitBlt(dc, 25, 25, 602, 602, memDC, 0, 0, SRCCOPY);
  737. }
  738.  
  739. // Player.h
  740.  
  741. #ifndef C_PLAYER_H
  742. #define C_PLAYER_H
  743.  
  744. #include "Cell.h"
  745.  
  746. typedef struct Player {
  747.     int side;
  748.     int mustEat;
  749.     Cell **cells;
  750.     Cell *mustMove;
  751. } Player;
  752.  
  753. Player* newPlayer(int side);
  754.  
  755. #endif
  756.  
  757. // Player.c
  758.  
  759. #include "Player.h"
  760.  
  761. Player* newPlayer(int side) {
  762.     Player *player = calloc(1, sizeof(Player));
  763.  
  764.     player->side = side;
  765.     player->mustEat = 0;
  766.     player->mustMove = NULL;
  767.     player->cells = calloc(12, sizeof(Cell*));
  768.  
  769.     return player;
  770. }
  771.  
  772. // Cell.h
  773.  
  774. #ifndef C_CELL_H
  775. #define C_CELL_H
  776.  
  777. #include <windows.h>
  778.  
  779. enum Figures {
  780.     NONE, BLACK, WHITE, NORMAL, KING
  781. };
  782.  
  783. enum wayTypes {
  784.     LEFT_TOP = 100, RIGHT_TOP, LEFT_BOTTOM, RIGHT_BOTTOM
  785. };
  786.  
  787. typedef struct Cell {
  788.     int x;
  789.     int y;
  790.     COLORREF background;
  791.     int figure;
  792.     int figureType;
  793.     int kingZone;
  794.     int highlightPath;
  795.     struct Cell ***ways;
  796. } Cell;
  797.  
  798. Cell* newCell(int x, int y, COLORREF background, int figure, int kingZone);
  799.  
  800. #endif
  801.  
  802. // Cell.c
  803.  
  804. #include "Cell.h"
  805.  
  806. Cell* newCell(int x, int y, COLORREF background, int figure, int kingZone) {
  807.     Cell* cell = calloc(1, sizeof(Cell));
  808.  
  809.     cell->x = x;
  810.     cell->y = y;
  811.     cell->background = background;
  812.     cell->figure = figure;
  813.     cell->figureType = NORMAL;
  814.     cell->kingZone = kingZone;
  815.     cell->highlightPath = 1;
  816.  
  817.     return cell;
  818. }
  819.  
  820. // HumanGame.h
  821.  
  822. #ifndef CHECKERS_HUMANGAME_H
  823. #define CHECKERS_HUMANGAME_H
  824.  
  825. #include "Player.h"
  826. #include "Cell.h"
  827. #include "Game.h"
  828.  
  829. int canPlayerEat(Player *player);
  830. void onMouseDown(int x, int y);
  831.  
  832. #endif
  833.  
  834. // HumanGame.c
  835.  
  836. #include "HumanGame.h"
  837.  
  838. int canPlayerEat(Player *player) {
  839.     for (int i = 0; i < 12; i++) {
  840.         Cell *cell = player->cells[i];
  841.         if (cell->figure == player->side && canEat(cell)) return 1;
  842.     }
  843.  
  844.     return 0;
  845. }
  846.  
  847. void onMouseDown(int x, int y) {
  848.     Cell *cell = findCell(x, y);
  849.  
  850.     if (cell != NULL) {
  851.         if (cell->figure != NONE) {
  852.             if (cell == lastChosenCell) {
  853.                 hideHighlight(cell);
  854.                 lastChosenCell = NULL;
  855.             } else if ((gameMode == HUMAN && ((humanTurn && cell->figure == player1->side) || (!humanTurn && cell->figure == player2->side))) || (gameMode == AI && (humanTurn && cell->figure == player1->side))) {
  856.                 if (lastChosenCell != NULL)
  857.                     hideHighlight(lastChosenCell);
  858.  
  859.                 if ((currentPlayer->mustMove != NULL && currentPlayer->mustMove != cell) ||
  860.                     (canPlayerEat(currentPlayer) && !canEat(cell)))
  861.                     return;
  862.  
  863.                 highlightCell(memDC, cell);
  864.                 getAllWays(cell, humanTurn);
  865.                 showWays(memDC, cell);
  866.  
  867.                 lastChosenCell = cell;
  868.             }
  869.         } else {
  870.             Cell **way = getPath(cell);
  871.             if (lastChosenCell != NULL && way != NULL) {
  872.                 int ate = eat(cell, way, lastChosenCell->figureType == KING);
  873.  
  874.                 swapProps(cell, lastChosenCell);
  875.  
  876.                 int cellIndex = indexOf(currentPlayer->cells, lastChosenCell);
  877.                 if (cellIndex != -1) currentPlayer->cells[cellIndex] = cell;
  878.  
  879.                 if (cell->kingZone != NONE && cell->kingZone != cell->figure) cell->figureType = KING;
  880.  
  881.                 hideHighlight(lastChosenCell);
  882.                 drawCell(memDC, cell);
  883.                 placeFigure(memDC, cell);
  884.  
  885.                 changeTurn(ate, cell);
  886.  
  887.                 lastChosenCell = NULL;
  888.             }
  889.         }
  890.     }
  891.  
  892.     restoreHighlight();
  893.  
  894.     BitBlt(dc, 25, 25, 602, 602, memDC, 0, 0, SRCCOPY);
  895. }
  896.  
  897. // AiGame.h
  898.  
  899. #ifndef CHECKERS_AIGAME_H
  900. #define CHECKERS_AIGAME_H
  901.  
  902. #include "Player.h"
  903. #include "Cell.h"
  904. #include "Game.h"
  905.  
  906. Cell *peekRandomCell(Cell **cells, int length);
  907. void moveFigure();
  908.  
  909. #endif
  910.  
  911. // AiGame.c
  912.  
  913. #include "AiGame.h"
  914.  
  915. Cell *peekRandomCell(Cell **cells, int length) {
  916.     int index = rand() % length;
  917.     return cells[index];
  918. }
  919.  
  920. int countValidWays(Cell *cell) {
  921.     int validWaysCount = 0;
  922.  
  923.     for (int i = 0; i < 4; i++)
  924.         validWaysCount += countWay(cell->ways[i]);
  925.  
  926.     return validWaysCount;
  927. }
  928.  
  929. Cell **getValidWaysCells(int validWaysCount, Cell *cell) {
  930.     int k = 0;
  931.     Cell **validWays = malloc(validWaysCount * sizeof(Cell *));
  932.  
  933.     for (int i = 0; i < 4; i++) {
  934.         for (int j = 0; j < 8; j++) {
  935.             if (cell->ways[i][j] != NULL) {
  936.                 validWays[k] = cell->ways[i][j];
  937.                 k++;
  938.             }
  939.         }
  940.     }
  941.  
  942.     return validWays;
  943. }
  944.  
  945. void renderDestination(Cell *cell, Cell *destination) {
  946.     hideHighlight(cell);
  947.     drawCell(memDC, destination);
  948.     placeFigure(memDC, destination);
  949.     restoreHighlight(cell);
  950. }
  951.  
  952. void moveFigure() {
  953.     Cell *cell = peekRandomCell(player2->cells, 12); // Выбор случайной фигуры из доступных
  954.  
  955.     if(cell == NULL || cell->figure != player2->side) return moveFigure(); // Если указатель на ячейку NULL или фигура отличается, то выбирается другая фигура
  956.  
  957.     getAllWays(cell, 0); // Получение всех путей для выбранной фигуры
  958.     int validWaysCount = countValidWays(cell); // Получение общего количества путей, по которым можно ходить
  959.  
  960.     if (validWaysCount == 0 || (player2->mustMove != NULL && player2->mustMove != cell) || (canPlayerEat(player2) && !canEat(cell))) // Если путей нет или необходимо есть, то выбирается другая фигура
  961.         return moveFigure();
  962.  
  963.     lastChosenCell = cell;
  964.  
  965.     Cell **validWays = getValidWaysCells(validWaysCount, cell); // Одномерный массив указателей на структуру Cell, представляющий собой ячейки, на которые можно походить
  966.     Cell *destination = peekRandomCell(validWays, validWaysCount); // Ячейка, на которую будет перемещена фигура
  967.     Cell **way = getPath(destination); // Выбранный путь
  968.  
  969.     if (way == NULL) return moveFigure(); // Если такой путь пустой, то происходит выбор другой фигуры
  970.  
  971.     BitBlt(dc, 25, 25, 602, 602, memDC, 0, 0, SRCCOPY); // Отрисовка перед таймером
  972.     msleep(200); // Ожидание 200 мс
  973.  
  974.     int ate = eat(destination, way, cell->figureType == KING); // Показывает, была ли съедена фигура противника
  975.  
  976.     swapProps(destination, cell); // Обмен значениями между исходной и конечной ячейками
  977.  
  978.     int cellIndex = indexOf(player2->cells, cell); // Индекс ячейки в массиве ячеек игрока
  979.     if (cellIndex != -1) player2->cells[cellIndex] = destination; // Если ячейка в массиве игрока, то она заменяется на destination
  980.  
  981.     if (destination->kingZone != NONE && destination->kingZone != destination->figure) // Если наступили на королевскую зону противника
  982.         destination->figureType = KING;
  983.  
  984.     renderDestination(cell, destination); // Отрисовка фигуры
  985.     changeTurn(ate, destination); // Смена хода
  986. }
  987.  
  988. // Menu.h
  989.  
  990. #ifndef CHECKERS_MENU_H
  991. #define CHECKERS_MENU_H
  992.  
  993. #include <stdio.h>
  994. #include <errno.h>
  995. #include <unistd.h>
  996.  
  997. #include "Game.h"
  998.  
  999. FILE *openFile(char *path);
  1000. void showStats();
  1001. void about();
  1002. int *readStats(FILE *file);
  1003. void writeStats(int win);
  1004. void clearStats();
  1005. void closeGame();
  1006. void newGameWithAi();
  1007. void newGameWithHuman();
  1008. void confirmation(char *text, void (*callback)(void));
  1009.  
  1010. #endif
  1011.  
  1012. // Menu.c
  1013.  
  1014. #include "Menu.h"
  1015.  
  1016. FILE *openFile(char *path) {
  1017.     FILE *file;
  1018.     if (access(path, F_OK) == 0) {
  1019.         file = fopen(path, "r+");
  1020.     } else {
  1021.         file = fopen(path, "w+");
  1022.     }
  1023.  
  1024.     return file;
  1025. }
  1026.  
  1027. void showStats() {
  1028.     FILE *file = openFile("stats.data");
  1029.  
  1030.     int *stats = readStats(file);
  1031.     char *str = malloc(128);
  1032.  
  1033.     sprintf(str, "Победы: %d\nПоражения: %d", stats[0], stats[1]);
  1034.  
  1035.     MessageBox(NULL, str, "Статистика", MB_ICONINFORMATION | MB_OK);
  1036.  
  1037.     fclose(file);
  1038. }
  1039.  
  1040. void about() {
  1041.     MessageBox(NULL,
  1042.                "Данная программа предназначена для развлекательных целей. \n\nАвтор программы:\nКуфтырев Алексей, студент 2 курса ФКСиС.",
  1043.                "О программе", MB_ICONINFORMATION | MB_OK);
  1044. }
  1045.  
  1046. int *readStats(FILE *file) {
  1047.     rewind(file);
  1048.  
  1049.     int *info = malloc(2 * sizeof(int));
  1050.     info[0] = 0; // wins
  1051.     info[1] = 0; // loses
  1052.  
  1053.     char ch;
  1054.     int i = 0;
  1055.  
  1056.     while ((ch = getc(file)) != EOF) {
  1057.         info[i] = ch - '0';
  1058.         if (ch != '\n' && ch != '\r') i++;
  1059.     }
  1060.  
  1061.     return info;
  1062. }
  1063.  
  1064. void writeStats(int win) {
  1065.     FILE *file = openFile("stats.data");
  1066.  
  1067.     int *currStats = readStats(file);
  1068.     int wins = currStats[0];
  1069.     int loses = currStats[1];
  1070.  
  1071.     if (win)
  1072.         wins++;
  1073.     else
  1074.         loses++;
  1075.  
  1076.     fseek(file, 0, SEEK_SET);
  1077.     fputc(wins + '0', file);
  1078.     fputc('\n', file);
  1079.     fseek(file, 2, SEEK_SET);
  1080.     fputc(loses + '0', file);
  1081.  
  1082.     fclose(file);
  1083. }
  1084.  
  1085. void clearStats() {
  1086.     remove("stats.data");
  1087.     MessageBox(NULL, "Статистика сброшена", "Информация", MB_ICONINFORMATION | MB_OK);
  1088. }
  1089.  
  1090. void closeGame() {
  1091.     freeMem();
  1092.     PostQuitMessage(0);
  1093. }
  1094.  
  1095. void newGameWithAi() {
  1096.     newGame(dc, AI);
  1097. }
  1098.  
  1099. void newGameWithHuman() {
  1100.     newGame(dc, HUMAN);
  1101. }
  1102.  
  1103. void confirmation(char *text, void (*callback)(void)) {
  1104.     int msgBoxId = MessageBox(NULL, text, "Подтвердите действие", MB_ICONQUESTION | MB_YESNO);
  1105.  
  1106.     if (msgBoxId == IDYES) {
  1107.         callback();
  1108.     }
  1109. }
  1110.  
  1111. // main.c
  1112.  
  1113. #include <math.h>
  1114. #include <windows.h>
  1115. #include <commctrl.h>
  1116. #include <time.h>
  1117.  
  1118. #include "modules/Game.h"
  1119.  
  1120. RECT rct;
  1121.  
  1122. const int offsetX = 25;
  1123. const int offsetY = 25;
  1124. const int fieldSize = 600;
  1125.  
  1126. Player *player1 = NULL;
  1127. Player *player2 = NULL;
  1128. Player *currentPlayer = NULL;
  1129. int humanTurn = 1;
  1130. Cell **cells = NULL;
  1131. Cell *lastChosenCell = NULL;
  1132. int gameStarted = 0;
  1133. int playerCanChangeSide = 1;
  1134. int gameMode = HUMAN;
  1135.  
  1136. HWND hwnd = NULL;
  1137. HDC dc = NULL;
  1138. HDC memDC = NULL;
  1139. HBITMAP memBM = NULL;
  1140. HMENU hFile = NULL;
  1141. HMENU hInf = NULL;
  1142.  
  1143. enum MenuButtons {
  1144.     AGAINST_AI, AGAINST_HUMAN, CHANGE_SIDE, CLEAR_STATS, CLOSE_GAME, ABOUT, STATS
  1145. };
  1146.  
  1147. LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
  1148.  
  1149. LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
  1150.     if (message == WM_DESTROY) {
  1151.         freeMem();
  1152.         PostQuitMessage(0);
  1153.     } else if (message == WM_SIZE) {
  1154.         GetClientRect(hwnd, &rct);
  1155.     } else if (message == WM_LBUTTONDOWN) {
  1156.         int x = LOWORD(lparam);
  1157.         int y = HIWORD(lparam);
  1158.         onMouseDown(x, y);
  1159.     } else if (message == WM_CREATE) {
  1160.         HMENU hMenuBar = CreateMenu();
  1161.         hFile = CreateMenu();
  1162.         hInf = CreateMenu();
  1163.  
  1164.         AppendMenuA(hMenuBar, MF_POPUP, (UINT_PTR) hFile, "Меню");
  1165.         AppendMenuA(hMenuBar, MF_POPUP, (UINT_PTR) hInf, "Информация");
  1166.  
  1167.         AppendMenuA(hFile, MF_STRING, AGAINST_AI, "Новая игра с компьютером");
  1168.         AppendMenuA(hFile, MF_STRING, AGAINST_HUMAN, "Новая игра с человеком");
  1169.         AppendMenuA(hFile, MF_STRING, CHANGE_SIDE, "Сменить сторону");
  1170.         AppendMenuA(hFile, MF_SEPARATOR, NULL, NULL);
  1171.         AppendMenuA(hFile, MF_STRING, CLEAR_STATS, "Сбросить статистику");
  1172.         AppendMenuA(hFile, MF_SEPARATOR, NULL, NULL);
  1173.         AppendMenuA(hFile, MF_STRING, CLOSE_GAME, "Выход");
  1174.  
  1175.         AppendMenuA(hInf, MF_STRING, ABOUT, "О программе");
  1176.         AppendMenuA(hInf, MF_STRING, STATS, "Статистика");
  1177.  
  1178.         SetMenu(hwnd, hMenuBar);
  1179.     } else if (message == WM_COMMAND) {
  1180.         int wmId = LOWORD(wparam);
  1181.  
  1182.         switch (wmId) {
  1183.             case AGAINST_AI:
  1184.                 confirmation("Вы уверены, что хотите начать новую игру с компьютером?", newGameWithAi);
  1185.                 break;
  1186.             case AGAINST_HUMAN:
  1187.                 confirmation("Вы уверены, что хотите начать новую игру с человеком?", newGameWithHuman);
  1188.                 break;
  1189.             case CHANGE_SIDE:
  1190.                 confirmation("Вы уверены, что хотите сменить сторону?", changeSide);
  1191.                 break;
  1192.             case CLEAR_STATS:
  1193.                 confirmation("Вы уверены, что хотите сбросить статистику?", clearStats);
  1194.                 break;
  1195.             case CLOSE_GAME:
  1196.                 confirmation("Вы уверены, что хотите выйти?", closeGame);
  1197.             case STATS:
  1198.                 showStats();
  1199.                 break;
  1200.             case ABOUT:
  1201.                 about();
  1202.                 break;
  1203.         }
  1204.     } else if (message == WM_PAINT) {
  1205.         if (gameStarted) {
  1206.             HDC dc;
  1207.             PAINTSTRUCT ps;
  1208.             RECT rc;
  1209.  
  1210.             dc = BeginPaint(hwnd, &ps);
  1211.  
  1212.             GetClientRect(hwnd, &rc);
  1213.             HDC mdc = CreateCompatibleDC(dc);
  1214.             HBITMAP mbm = CreateCompatibleBitmap(dc, rct.right - rct.left, rct.bottom - rct.top);
  1215.             SelectObject(mdc, mbm);
  1216.  
  1217.             drawBorder(mdc);
  1218.             drawCells(mdc, cells);
  1219.             placeFigures(mdc, cells);
  1220.  
  1221.             if (lastChosenCell != NULL) {
  1222.                 getAllWays(lastChosenCell, humanTurn);
  1223.                 highlightCell(mdc, lastChosenCell);
  1224.                 showWays(mdc, lastChosenCell);
  1225.             }
  1226.  
  1227.             BitBlt(dc, 25, 25, 602, 602, mdc, 0, 0, SRCCOPY);
  1228.  
  1229.             ReleaseDC(hwnd, mdc);
  1230.             DeleteObject(mbm);
  1231.             EndPaint(hwnd, &ps);
  1232.  
  1233.             SelectObject(memDC, memBM);
  1234.         }
  1235.     } else
  1236.         return DefWindowProcA(hwnd, message, wparam, lparam);
  1237. }
  1238.  
  1239. void loadWindowIcon(HWND hwnd) {
  1240.     HICON icon = LoadImage(NULL, "images/icon.ico", IMAGE_ICON, 48, 48, LR_LOADFROMFILE);
  1241.     if (icon != NULL) SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) icon);
  1242. }
  1243.  
  1244. int main() {
  1245.     WNDCLASSA wcl;
  1246.     memset(&wcl, 0, sizeof(WNDCLASSA));
  1247.     wcl.lpszClassName = "my Window";
  1248.     wcl.lpfnWndProc = WndProc;
  1249.     wcl.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  1250.  
  1251.     RegisterClassA(&wcl);
  1252.  
  1253.     int screenWidth = GetSystemMetrics(SM_CXSCREEN);
  1254.     int screenHeight = GetSystemMetrics(SM_CYSCREEN);
  1255.     int formWidth = 665;
  1256.     int formHeight = 700;
  1257.  
  1258.     hwnd = CreateWindow("my Window", "Шашки", WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME ^ WS_MAXIMIZEBOX,
  1259.                         (screenWidth - formWidth) / 2, (screenHeight - formHeight) / 2, formWidth, formHeight, NULL,
  1260.                         NULL, NULL, NULL);
  1261.  
  1262.     dc = GetDC(hwnd);
  1263.     loadWindowIcon(hwnd);
  1264.     ShowWindow(hwnd, SW_SHOWNORMAL);
  1265.  
  1266.     srand(time(NULL));
  1267.     newGame(dc, HUMAN);
  1268.     InitCommonControls();
  1269.  
  1270.     MSG msg;
  1271.     while (GetMessage(&msg, NULL, 0, 0)) {
  1272.         TranslateMessage(&msg);
  1273.         DispatchMessage(&msg);
  1274.     }
  1275.     return 0;
  1276. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement