paranid5

Sapper(C-version)

May 6th, 2020
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 58.36 KB | None | 0 0
  1. /*             С версия            */
  2. #define _CRT_DISABLE_PERFCRIT_LOCKS
  3. #define _CRT_SECURE_NO_WARNINGS
  4. #include <locale.h>
  5. #include <math.h>
  6. #include <stdarg.h>
  7. #include <stdbool.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <time.h>
  12. bool victory = false;
  13. struct result
  14. {
  15.     char* name;
  16.     unsigned short games;
  17.     unsigned short victories;
  18.     double percent;
  19.     unsigned short izzy;/*успешно пройденный просто*/
  20.     unsigned short hard;/*успешно пройденный не просто*/
  21.     unsigned short doom_guy;/*успешно пройденный ХАРДКОР*/
  22. };
  23. int scanf_rng(const char* const _Format, ...)
  24. {
  25.     int _Result;
  26.     va_list _ArgList;
  27.     __crt_va_start(_ArgList, _Format);
  28.     _Result = _vfscanf_l(stdin, _Format, NULL, _ArgList);
  29.     __crt_va_end(_ArgList);
  30.     scanf("%*[^\n]");
  31.     _fflush_nolock(stdin);
  32.     return _Result;
  33. }
  34. unsigned short compare_games(const void* a, const void* b)
  35. {
  36.     const struct result* k = (const struct result*)a;
  37.     const struct result* l = (const struct result*)b;
  38.     return ((k->games) - (l->games));
  39. }
  40. unsigned short compare_izzy(const void* a, const void* b)
  41. {
  42.     const struct result* k = (const struct result*)a;
  43.     const struct result* l = (const struct result*)b;
  44.     return ((k->izzy) - (l->izzy));
  45. }
  46. unsigned short compare_hard(const void* a, const void* b)
  47. {
  48.     const struct result* k = (const struct result*)a;
  49.     const struct result* l = (const struct result*)b;
  50.     return ((k->hard) - (l->hard));
  51. }
  52. unsigned short compare_doom(const void* a, const void* b)
  53. {
  54.     const struct result* k = (const struct result*)a;
  55.     const struct result* l = (const struct result*)b;
  56.     return ((k->doom_guy) - (l->doom_guy));
  57. }
  58. double compare_percent(const void* a, const void* b)
  59. {
  60.     const struct result* k = (const struct result*)a;
  61.     const struct result* l = (const struct result*)b;
  62.     return ((k->percent) - (l->percent));
  63. }
  64. void save(struct result* save, const unsigned short f)
  65. {
  66.     FILE* fout = fopen("results.bin", "wbe");
  67.     for (unsigned short q = 0; q < f; q++)
  68.     {
  69.         const unsigned short sz = strlen(save[q].name);
  70.         fwrite(&sz, sizeof(unsigned short), 1, fout);
  71.         fwrite(save[q].name, sizeof(char), sz, fout);
  72.         fwrite(&save[q].games, sizeof(unsigned short), 1, fout);
  73.         fwrite(&save[q].victories, sizeof(unsigned short), 1, fout);
  74.         fwrite(&save[q].percent, sizeof(double), 1, fout);
  75.         fwrite(&save[q].izzy, sizeof(unsigned short), 1, fout);
  76.         fwrite(&save[q].hard, sizeof(unsigned short), 1, fout);
  77.         fwrite(&save[q].doom_guy, sizeof(unsigned short), 1, fout);
  78.     }
  79.     fclose(fout);
  80. }
  81. void printdesk(char** deskgr, const unsigned short x, const unsigned short y)
  82. {
  83.     printf("  ");
  84.     for (unsigned short i = 1; i < y + 1; i++)
  85.         printf(" %d", i % 10);
  86.     printf("\n");
  87.     for (unsigned short i = 0; i < x; i++)
  88.     {
  89.         printf("  ");
  90.         for (unsigned short q = 1; q < y + 1; q++)
  91.             printf(" _");
  92.         printf("\n");
  93.         printf("%d ", (i + 1) % 10);
  94.         for (unsigned short q = 0; q < y; q++)
  95.             printf("|%c", deskgr[i][q]);
  96.         printf("|\n");
  97.     }
  98.     printf("  ");
  99.     for (unsigned short q = 1; q < y + 1; q++)
  100.         printf(" _");
  101.     printf("\n");
  102. }
  103. char opencl(const unsigned short num)
  104. {
  105.     switch (num)
  106.     {
  107.     case 0:
  108.         return 48;
  109.         break;
  110.     case 1:
  111.         return 49;
  112.         break;
  113.     case 2:
  114.         return 50;
  115.         break;
  116.     case 3:
  117.         return 51;
  118.         break;
  119.     case 4:
  120.         return 52;
  121.         break;
  122.     case 5:
  123.         return 53;
  124.         break;
  125.     case 6:
  126.         return 54;
  127.         break;
  128.     case 7:
  129.         return 55;
  130.         break;
  131.     default:
  132.         return 56;
  133.         break;
  134.     }
  135. }
  136. short to_hu(char* XM)
  137. {
  138.     unsigned short xm = 0;
  139.     bool correct = true;
  140.     if (XM[1] == 49 || XM[1] == 50 || XM[1] == 51 || XM[1] == 52 || XM[1] == 53 || XM[1] == 54 || XM[1] == 55 || XM[1] == 56 || XM[1] == 57 || XM[1] == 58)
  141.     {
  142.         switch (XM[0])
  143.         {
  144.         case 49:
  145.             xm = 10;
  146.             break;
  147.         case 50:
  148.             xm = 20;
  149.             break;
  150.         case 51:
  151.             xm = 30;
  152.             break;
  153.         default:
  154.             printf("Ввод не корректен.\n");
  155.             correct = false;
  156.             break;
  157.         }
  158.         if (correct)
  159.         {
  160.             switch (XM[1])
  161.             {
  162.             case 48:
  163.                 break;
  164.             case 49:
  165.                 xm++;
  166.                 break;
  167.             case 50:
  168.                 xm += 2;
  169.                 break;
  170.             case 51:
  171.                 xm += 3;
  172.                 break;
  173.             case 52:
  174.                 xm += 4;
  175.                 break;
  176.             case 53:
  177.                 xm += 5;
  178.                 break;
  179.             case 54:
  180.                 xm += 6;
  181.                 break;
  182.             case 55:
  183.                 xm += 7;
  184.                 break;
  185.             case 56:
  186.                 xm += 8;
  187.                 break;
  188.             case 57:
  189.                 xm += 9;
  190.                 break;
  191.             default:
  192.                 printf("Ввод не корректен.\n");
  193.                 correct = false;
  194.                 break;
  195.             }
  196.         }
  197.         if (correct && XM[2] != 0)
  198.         {
  199.             printf("Ввод не корректен.\n");
  200.             correct = false;
  201.         }
  202.     }
  203.     else if (XM[1] == 0)
  204.     {
  205.         switch (*XM)
  206.         {
  207.         case 48:
  208.             break;
  209.         case 49:
  210.             xm++;
  211.             break;
  212.         case 50:
  213.             xm += 2;
  214.             break;
  215.         case 51:
  216.             xm += 3;
  217.             break;
  218.         case 52:
  219.             xm += 4;
  220.             break;
  221.         case 53:
  222.             xm += 5;
  223.             break;
  224.         case 54:
  225.             xm += 6;
  226.             break;
  227.         case 55:
  228.             xm += 7;
  229.             break;
  230.         case 56:
  231.             xm += 8;
  232.             break;
  233.         case 57:
  234.             xm += 9;
  235.             break;
  236.         default:
  237.             printf("Ввод не корректен.\n");
  238.             correct = false;
  239.             break;
  240.         }
  241.     }
  242.     else
  243.     {
  244.         printf("Ввод не корректен.\n");
  245.         correct = false;
  246.     }
  247.     return correct ? xm : -1;
  248. }
  249. void game(struct result* p, struct result player, const unsigned short type)
  250. {
  251.     unsigned short x = 0, y = 0;/*custom*/
  252.     unsigned short mines = 0;
  253.     char** deskgr = 0;
  254.     unsigned short** bnum = 0;
  255.     unsigned short count = 0;/*кол-во мин*/
  256.     unsigned short* position = 0;
  257.     if (type != 1)
  258.     {
  259.         deskgr = (char**)malloc(type * sizeof(char*));
  260.         for (unsigned short i = 0; i < type; i++)
  261.             deskgr[i] = (char*)malloc(type * sizeof(char));
  262.         for (unsigned short i = 0; i < type; i++)
  263.             for (unsigned short q = 0; q < type; q++)
  264.                 deskgr[i][q] = 32;
  265.         /*то, что отображается*/
  266.         bnum = (unsigned short**)malloc(type * sizeof(unsigned short*));
  267.         for (unsigned short i = 0; i < type; i++)
  268.             bnum[i] = (unsigned short*)malloc(type * sizeof(unsigned short));
  269.         for (unsigned short i = 0; i < type; i++)
  270.             for (unsigned short q = 0; q < type; q++)
  271.                 bnum[i][q] = 0;
  272.         /*номера(рядом с минами)*/
  273.         switch (type)
  274.         {
  275.         case 8:
  276.             printdesk(deskgr, 8, 8);
  277.             break;
  278.         case 16:
  279.             printdesk(deskgr, 16, 16);
  280.             break;
  281.         default:
  282.             printdesk(deskgr, 32, 32);
  283.             break;
  284.         }
  285.         srand(time(NULL));
  286.         count = 0;
  287.         position = (unsigned short*)malloc(type * 2 * sizeof(unsigned short));/*номера мин*/
  288.         while (count != type * 2)
  289.         {
  290.             bool test = false;
  291.             unsigned short place = rand() % ((type * type - 1) - 0 + 1) + 0; /*позиция мины*/
  292.             for (unsigned short i = 0; i < count; i++)
  293.             {
  294.                 if (place == position[i])
  295.                 {
  296.                     test = true;
  297.                     break;
  298.                 }
  299.             }
  300.             if (!test)
  301.             {
  302.                 count++;
  303.                 position[count - 1] = place;
  304.             }
  305.         }/*создали мины*/
  306.         unsigned short xc = 0, yc = 0;
  307.         for (unsigned short q = 0; q < count; q++)
  308.         {
  309.             xc = position[q] / type;/*строка с миной*/
  310.             yc = position[q] - (type * xc);/*столбец с миной*/
  311.             /*определили положение мины*/
  312.             if (xc > 0)
  313.                 bnum[xc - 1][yc]++;
  314.             if (xc < type - 1)
  315.                 bnum[xc + 1][yc]++;
  316.             if (yc > 0)
  317.                 bnum[xc][yc - 1]++;
  318.             if (yc < type - 1)
  319.                 bnum[xc][yc + 1]++;
  320.             if (xc > 0 && yc > 0)
  321.                 bnum[xc - 1][yc - 1]++;
  322.             if (xc < type - 1 && yc > 0)
  323.                 bnum[xc + 1][yc - 1]++;
  324.             if (xc > 0 && yc < type - 1)
  325.                 bnum[xc - 1][yc + 1]++;
  326.             if (xc < type - 1 && yc < type - 1)
  327.                 bnum[xc + 1][yc + 1]++;
  328.         }/*Заполнили номерами для мин*/
  329.     }
  330.     else
  331.     {
  332.         char* X = (char*)malloc(0);
  333.         char* Y = (char*)malloc(0);
  334.         printf("Задайте размер доски.\n");
  335.         do
  336.         {
  337.             printf("Кол-во строк(не больше 50, минимум 3): ");
  338.             scanf_rng("%3s", X);
  339.             x = atoi(X);
  340.             if (x < 3 || x > 50)
  341.                 printf("Ввод не корректен\n");
  342.         }
  343.         while (x < 3 || x > 50);
  344.         do
  345.         {
  346.             printf("Кол-во столбцов(не больше 50, минимум 3): ");
  347.             scanf_rng("%3s", Y);
  348.             y = atoi(Y);
  349.             if (y < 3 || y > 50)
  350.                 printf("Ввод не корректен\n");
  351.         }
  352.         while (y < 3 || y > 50);
  353.         deskgr = (char**)malloc(x * sizeof(char*));
  354.         for (unsigned short i = 0; i < x; i++)
  355.             deskgr[i] = (char*)malloc(y * sizeof(char));
  356.         for (unsigned short i = 0; i < x; i++)
  357.             for (unsigned short q = 0; q < y; q++)
  358.                 deskgr[i][q] = 32;
  359.         /*то, что отображается*/
  360.         bnum = (unsigned short**)malloc(x * sizeof(unsigned short*));
  361.         for (unsigned short i = 0; i < x; i++)
  362.             bnum[i] = (unsigned short*)malloc(y * sizeof(unsigned short));
  363.         for (unsigned short i = 0; i < x; i++)
  364.             for (unsigned short q = 0; q < y; q++)
  365.                 bnum[i][q] = 0;
  366.         /*номера(рядом с минами)*/
  367.         printdesk(deskgr, x, y);
  368.         do
  369.         {
  370.             mines = 0;
  371.             char* MINES = (char*)malloc(0);
  372.             printf("Задайте кол-во мин (минимум 5%% от площади доски и максимум 95%%): ");
  373.             scanf_rng("%4s", MINES);
  374.             mines = atoi(MINES);
  375.             if (mines < (x * y) / 100.0 * 5 || mines >(x * y) / 100.0 * 95)
  376.                 printf("Ввод не корректен\n");
  377.         }
  378.         while (mines < (x * y) / 100.0 * 5 || mines >(x * y) / 100.0 * 95);
  379.         srand(time(NULL));
  380.         count = 0;
  381.         position = (unsigned short*)malloc(mines * sizeof(unsigned short));/*номера мин*/
  382.         while (count != mines)
  383.         {
  384.             bool test = false;
  385.             unsigned short place = rand() % ((x * y - 1) - 0 + 1) + 0; /*позиция мины*/
  386.             for (unsigned short i = 0; i < count; i++)
  387.             {
  388.                 if (place == position[i])
  389.                 {
  390.                     test = true;
  391.                     break;
  392.                 }
  393.             }
  394.             if (!test)
  395.             {
  396.                 count++;
  397.                 position[count - 1] = place;
  398.             }
  399.         } /*создали мины*/
  400.         unsigned short xc = 0, yc = 0;
  401.         for (unsigned short q = 0; q < count; q++)
  402.         {
  403.             xc = position[q] / y;/*строка с миной*/
  404.             yc = position[q] - y * xc;/*столбец с миной*/
  405.             /*определили положение мины*/
  406.             if (xc > 0)
  407.                 bnum[xc - 1][yc]++;
  408.             if (xc < x - 1)
  409.                 bnum[xc + 1][yc]++;
  410.             if (yc > 0)
  411.                 bnum[xc][yc - 1]++;
  412.             if (yc < y - 1)
  413.                 bnum[xc][yc + 1]++;
  414.             if (xc > 0 && yc > 0)
  415.                 bnum[xc - 1][yc - 1]++;
  416.             if (xc < x - 1 && yc > 0)
  417.                 bnum[xc + 1][yc - 1]++;
  418.             if (xc > 0 && yc < y - 1)
  419.                 bnum[xc - 1][yc + 1]++;
  420.             if (xc < x - 1 && yc < y - 1)
  421.                 bnum[xc + 1][yc + 1]++;
  422.         }/*Заполнили номерами для мин*/
  423.     }
  424.     unsigned short xh = 0, yh = 0, mch = 0, mv = 0;
  425.     bool lose = false;
  426.     unsigned short space = type != 1 ? type * type - type * 2 : x * y - mines;/*не мины*/;
  427.     char* MV = (char*)malloc(0);
  428.     char* YESf = (char*)malloc(0);
  429.     char* YESd = (char*)malloc(0);
  430.     char* YESm = (char*)malloc(0);
  431.     char* XM = (char*)malloc(0);
  432.     char* YM = (char*)malloc(0);
  433.     char* XD = (char*)malloc(0);
  434.     char* YD = (char*)malloc(0);
  435.     char* XH = (char*)malloc(0);
  436.     char* YH = (char*)malloc(0);
  437.     time_t start = time(NULL);
  438.     do
  439.     {
  440.         do
  441.         {
  442.             printf("1. Поставить метку\n2. Убрать метку\n3. Сделать ход\n");
  443.             printf("Выберите ЦИФРУ: ");
  444.             scanf_rng("%2s", MV);
  445.             if (*MV != 49 && *MV != 50 && *MV != 51 || MV[1] != 0)
  446.                 printf("Ввод не коректен\n");
  447.         }
  448.         while (*MV != 49 && *MV != 50 && *MV != 51 || MV[1] != 0);
  449.         switch (*MV)
  450.         {
  451.         case 49:
  452.             mv = 1;
  453.             break;
  454.         case 50:
  455.             mv = 2;
  456.             break;
  457.         default:
  458.             mv = 3;
  459.             break;
  460.         }
  461.         switch (mv)
  462.         {
  463.         case 1:
  464.             do
  465.             {
  466.                 printf("Если у вас есть предположение о месте мин, то можете поставить + на это место. Если хотите это сделать, то введите YES, иначе что-то другое: ");
  467.                 scanf_rng("%4s", YESf);
  468.                 if (strcmp(YESf, "YES") == 0)
  469.                 {
  470.                     unsigned short xm = 0, ym = 0;/*координаты мин*/
  471.                     short xt = 0, yt = 0;/*тест*/
  472.                     printf("Введите координаты мины.\n");
  473.                     do
  474.                     {
  475.                         xm = 0;
  476.                         printf("Введите номер строки: ");
  477.                         scanf_rng("%3s", XM);
  478.                         xt = to_hu(XM);
  479.                     }
  480.                     while (xt == -1);
  481.                     xm = xt;
  482.                     do
  483.                     {
  484.                         ym = 0;
  485.                         printf("Введите номер столбца: ");
  486.                         scanf_rng("%3s", YM);
  487.                         yt = to_hu(YM);
  488.                     }
  489.                     while (yt == -1);
  490.                     ym = yt;
  491.                     if (type != 1)
  492.                     {
  493.                         if ((xm > type || xm < 1) && (ym > type || ym < 1))
  494.                         {
  495.                             printf("Вы вышли за рамки доски\n");
  496.                             break;
  497.                         }
  498.                     }
  499.                     else if ((xm > x || xm < 1) && (ym > y || ym < 1))
  500.                     {
  501.                         printf("Вы вышли за рамки доски\n");
  502.                         break;
  503.                     }
  504.                     if (deskgr[xm - 1][ym - 1] != 32)
  505.                     {
  506.                         printf("Сомневаюсь, что вы хотите поставить сюда метку...\n");
  507.                         break;
  508.                     }
  509.                     deskgr[xm - 1][ym - 1] = 43;
  510.                     switch (type)
  511.                     {
  512.                     case 8:
  513.                         printdesk(deskgr, 8, 8);
  514.                         break;
  515.                     case 16:
  516.                         printdesk(deskgr, 16, 16);
  517.                         break;
  518.                     case 32:
  519.                         printdesk(deskgr, 32, 32);
  520.                         break;
  521.                     default:
  522.                         printdesk(deskgr, x, y);
  523.                         break;
  524.                     }
  525.                 }
  526.             }
  527.             while (strcmp(YESf, "YES") == 0);
  528.             break;
  529.         case 2:
  530.             do
  531.             {
  532.                 printf("Вы можете убрать метку на мину. Если хотите это сделать, то введите YES, иначе что-то другое: ");
  533.                 scanf_rng("%4s", YESd);
  534.                 if (strcmp(YESd, "YES") == 0)
  535.                 {
  536.                     unsigned short xm = 0, ym = 0;/*координаты мин*/
  537.                     short xt = 0, yt = 0;/*тест*/
  538.                     printf("Введите координаты мины.\n");
  539.                     do
  540.                     {
  541.                         xm = 0;
  542.                         printf("Введите номер строки: ");
  543.                         scanf_rng("%3s", XD);
  544.                         xt = to_hu(XD);
  545.                     }
  546.                     while (xt == -1);
  547.                     xm = xt;
  548.                     do
  549.                     {
  550.                         ym = 0;
  551.                         printf("Введите номер столбца: ");
  552.                         scanf_rng("%3s", YD);
  553.                         yt = to_hu(YD);
  554.                     }
  555.                     while (yt == -1);
  556.                     ym = yt;
  557.                     if (type != 1)
  558.                     {
  559.                         if ((xm > type || xm < 1) && (ym > type || ym < 1))
  560.                         {
  561.                             printf("Вы вышли за рамки доски\n");
  562.                             break;
  563.                         }
  564.                     }
  565.                     else if ((xm > x || xm < 1) && (ym > y || ym < 1))
  566.                     {
  567.                         printf("Вы вышли за рамки доски\n");
  568.                         break;
  569.                     }
  570.                     if (deskgr[xm - 1][ym - 1] != 43)
  571.                     {
  572.                         printf("Здесь нет метки...\n");
  573.                         break;
  574.                     }
  575.                     deskgr[xm - 1][ym - 1] = 32;
  576.                     switch (type)
  577.                     {
  578.                     case 8:
  579.                         printdesk(deskgr, 8, 8);
  580.                         break;
  581.                     case 16:
  582.                         printdesk(deskgr, 16, 16);
  583.                         break;
  584.                     case 32:
  585.                         printdesk(deskgr, 32, 32);
  586.                         break;
  587.                     default:
  588.                         printdesk(deskgr, x, y);
  589.                         break;
  590.                     }
  591.                 }
  592.             }
  593.             while (strcmp(YESd, "YES") == 0);
  594.             break;
  595.         default:
  596.             printf("Вы уверены, что хотите совершить ход? Если да, то введите YES, иначе что-то другое: ");
  597.             scanf_rng("%4s", YESm);
  598.             if (strcmp(YESm, "YES") != 0)
  599.                 break;
  600.             short xt = 0, yt = 0;/*тест*/
  601.             bool beyond = false;
  602.             do
  603.             {
  604.                 printf("Введите координаты мины\n");
  605.                 do
  606.                 {
  607.                     xh = 0;
  608.                     printf("Введите номер строки: ");
  609.                     scanf_rng("%3s", XH);
  610.                     xt = to_hu(XH);
  611.                 }
  612.                 while (xt == -1);
  613.                 xh = xt;
  614.                 do
  615.                 {
  616.                     yh = 0;
  617.                     printf("Введите номер столбца: ");
  618.                     scanf_rng("%3s", YH);
  619.                     yt = to_hu(YH);
  620.                 }
  621.                 while (yt == -1);
  622.                 yh = yt;
  623.                 beyond = false;
  624.                 if (type != 1)
  625.                 {
  626.                     if ((xh > type || xh < 1) && (yh > type || yh < 1))
  627.                     {
  628.                         printf("Вы вышли за рамки доски\n");
  629.                         beyond = true;
  630.                     }
  631.                 }
  632.                 else if ((xh > x || xh < 1) && (yh > y || yh < 1))
  633.                 {
  634.                     printf("Вы вышли за рамки доски\n");
  635.                     beyond = true;
  636.                 }
  637.             }
  638.             while (beyond);
  639.             for (unsigned short c = 0; c < count; c++)
  640.             {
  641.                 if (type != 1)
  642.                 {
  643.                     if ((xh - 1) * type + yh - 1 == position[c]) /*просрали*/
  644.                     {
  645.                         for (unsigned short o = 0; o < count; o++)
  646.                             deskgr[position[o] / type][position[o] - (position[o] / type) * type] = 120;
  647.                         switch (type)
  648.                         {
  649.                         case 8:
  650.                             printdesk(deskgr, 8, 8);
  651.                             break;
  652.                         case 16:
  653.                             printdesk(deskgr, 16, 16);
  654.                             break;
  655.                         default:
  656.                             printdesk(deskgr, 32, 32);
  657.                             break;
  658.                         }
  659.                         printf("Вы взорвались :(\n");
  660.                         lose = true;
  661.                         break;
  662.                     }
  663.                 }
  664.                 else if ((xh - 1) * y + yh - 1 == position[c]) /*просрали*/
  665.                 {
  666.                     for (unsigned short o = 0; o < count; o++)
  667.                         deskgr[position[o] / y][position[o] - (position[o] / y) * y] = 120;
  668.                     printdesk(deskgr, x, y);
  669.                     printf("Вы взорвались :(\n");
  670.                     lose = true;
  671.                     break;
  672.                 }
  673.             }
  674.             if (!lose && deskgr[xh - 1][yh - 1] != 32)
  675.                 printf("Эта клетка уже открыта\n");
  676.             else if (!lose && deskgr[xh - 1][yh - 1] == 32) /*не просрали*/
  677.             {
  678.                 unsigned short i = 0;
  679.                 unsigned short amount = 0;
  680.                 if (bnum[xh - 1][yh - 1] == 0) /*открытие клеток*/
  681.                 {
  682.                     unsigned short* eternal_x = (unsigned short*)malloc(1 * sizeof(unsigned short));/*строки 0*/
  683.                     *eternal_x = xh - 1;
  684.                     unsigned short* eternal_y = (unsigned short*)malloc(1 * sizeof(unsigned short));/*столбцы 0*/
  685.                     *eternal_y = yh - 1;
  686.                     unsigned short eternal_size = 1;
  687.                     for (i = 0; i < eternal_size; i++)
  688.                     {
  689.                         deskgr[eternal_x[i]][eternal_y[i]] = 48;
  690.                         amount++;
  691.                         if (eternal_x[i] > 0)
  692.                         {
  693.                             if (bnum[eternal_x[i] - 1][eternal_y[i]] == 0)
  694.                             {
  695.                                 bool potato = false;
  696.                                 for (unsigned short c = 0; c < eternal_size; c++)
  697.                                 {
  698.                                     if (eternal_x[c] == eternal_x[i] - 1 && eternal_y[c] == eternal_y[i])
  699.                                     {
  700.                                         potato = true;
  701.                                         break;
  702.                                     }
  703.                                 }
  704.                                 if (!potato)
  705.                                 {
  706.                                     eternal_size++;
  707.                                     eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
  708.                                     eternal_x[eternal_size - 1] = eternal_x[i] - 1;
  709.                                     eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
  710.                                     eternal_y[eternal_size - 1] = eternal_y[i];
  711.                                 }
  712.                             }
  713.                             else if (deskgr[eternal_x[i] - 1][eternal_y[i]] == 32)
  714.                             {
  715.                                 deskgr[eternal_x[i] - 1][eternal_y[i]] = opencl(bnum[eternal_x[i] - 1][eternal_y[i]]);
  716.                                 amount++;
  717.                             }
  718.                         }
  719.                         if (type != 1)
  720.                         {
  721.                             if (eternal_x[i] < type - 1)
  722.                             {
  723.                                 if (bnum[eternal_x[i] + 1][eternal_y[i]] == 0)
  724.                                 {
  725.                                     bool potato = false;
  726.                                     for (unsigned short c = 0; c < eternal_size; c++)
  727.                                     {
  728.                                         if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i])
  729.                                         {
  730.                                             potato = true;
  731.                                             break;
  732.                                         }
  733.                                     }
  734.                                     if (!potato)
  735.                                     {
  736.                                         eternal_size++;
  737.                                         eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
  738.                                         eternal_x[eternal_size - 1] = eternal_x[i] + 1;
  739.                                         eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
  740.                                         eternal_y[eternal_size - 1] = eternal_y[i];
  741.                                     }
  742.                                 }
  743.                                 else if (deskgr[eternal_x[i] + 1][eternal_y[i]] == 32)
  744.                                 {
  745.                                     deskgr[eternal_x[i] + 1][eternal_y[i]] = opencl(bnum[eternal_x[i] + 1][eternal_y[i]]);
  746.                                     amount++;
  747.                                 }
  748.                             }
  749.                         }
  750.                         else
  751.                         {
  752.                             if (eternal_x[i] < x - 1)
  753.                             {
  754.                                 if (bnum[eternal_x[i] + 1][eternal_y[i]] == 0)
  755.                                 {
  756.                                     bool potato = false;
  757.                                     for (unsigned short c = 0; c < eternal_size; c++)
  758.                                     {
  759.                                         if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i])
  760.                                         {
  761.                                             potato = true;
  762.                                             break;
  763.                                         }
  764.                                     }
  765.                                     if (!potato)
  766.                                     {
  767.                                         eternal_size++;
  768.                                         eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
  769.                                         eternal_x[eternal_size - 1] = eternal_x[i] + 1;
  770.                                         eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
  771.                                         eternal_y[eternal_size - 1] = eternal_y[i];
  772.                                     }
  773.                                 }
  774.                                 else if (deskgr[eternal_x[i] + 1][eternal_y[i]] == 32)
  775.                                 {
  776.                                     deskgr[eternal_x[i] + 1][eternal_y[i]] = opencl(bnum[eternal_x[i] + 1][eternal_y[i]]);
  777.                                     amount++;
  778.                                 }
  779.                             }
  780.                         }
  781.                         if (eternal_y[i] > 0)
  782.                         {
  783.                             if (bnum[eternal_x[i]][eternal_y[i] - 1] == 0)
  784.                             {
  785.                                 bool potato = false;
  786.                                 for (unsigned short c = 0; c < eternal_size; c++)
  787.                                 {
  788.                                     if (eternal_x[c] == eternal_x[i] && eternal_y[c] == eternal_y[i] - 1)
  789.                                     {
  790.                                         potato = true;
  791.                                         break;
  792.                                     }
  793.                                 }
  794.                                 if (!potato)
  795.                                 {
  796.                                     eternal_size++;
  797.                                     eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
  798.                                     eternal_x[eternal_size - 1] = eternal_x[i];
  799.                                     eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
  800.                                     eternal_y[eternal_size - 1] = eternal_y[i] - 1;
  801.                                 }
  802.                             }
  803.                             else if (deskgr[eternal_x[i]][eternal_y[i] - 1] == 32)
  804.                             {
  805.                                 deskgr[eternal_x[i]][eternal_y[i] - 1] = opencl(bnum[eternal_x[i]][eternal_y[i] - 1]);
  806.                                 amount++;
  807.                             }
  808.                         }
  809.                         if (type != 1)
  810.                         {
  811.                             if (eternal_y[i] < type - 1)
  812.                             {
  813.                                 if (bnum[eternal_x[i]][eternal_y[i] + 1] == 0)
  814.                                 {
  815.                                     bool potato = false;
  816.                                     for (unsigned short c = 0; c < eternal_size; c++)
  817.                                     {
  818.                                         if (eternal_x[c] == eternal_x[i] && eternal_y[c] == eternal_y[i] + 1)
  819.                                         {
  820.                                             potato = true;
  821.                                             break;
  822.                                         }
  823.                                     }
  824.                                     if (!potato)
  825.                                     {
  826.                                         eternal_size++;
  827.                                         eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
  828.                                         eternal_x[eternal_size - 1] = eternal_x[i];
  829.                                         eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
  830.                                         eternal_y[eternal_size - 1] = eternal_y[i] + 1;
  831.                                     }
  832.                                 }
  833.                                 else if (deskgr[eternal_x[i]][eternal_y[i] + 1] == 32)
  834.                                 {
  835.                                     deskgr[eternal_x[i]][eternal_y[i] + 1] = opencl(bnum[eternal_x[i]][eternal_y[i] + 1]);
  836.                                     amount++;
  837.                                 }
  838.                             }
  839.                         }
  840.                         else
  841.                         {
  842.                             if (eternal_y[i] < y - 1)
  843.                             {
  844.                                 if (bnum[eternal_x[i]][eternal_y[i] + 1] == 0)
  845.                                 {
  846.                                     bool potato = false;
  847.                                     for (unsigned short c = 0; c < eternal_size; c++)
  848.                                     {
  849.                                         if (eternal_x[c] == eternal_x[i] && eternal_y[c] == eternal_y[i] + 1)
  850.                                         {
  851.                                             potato = true;
  852.                                             break;
  853.                                         }
  854.                                     }
  855.                                     if (!potato)
  856.                                     {
  857.                                         eternal_size++;
  858.                                         eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
  859.                                         eternal_x[eternal_size - 1] = eternal_x[i];
  860.                                         eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
  861.                                         eternal_y[eternal_size - 1] = eternal_y[i] + 1;
  862.                                     }
  863.                                 }
  864.                                 else if (deskgr[eternal_x[i]][eternal_y[i] + 1] == 32)
  865.                                 {
  866.                                     deskgr[eternal_x[i]][eternal_y[i] + 1] = opencl(bnum[eternal_x[i]][eternal_y[i] + 1]);
  867.                                     amount++;
  868.                                 }
  869.                             }
  870.                         }
  871.                         if (eternal_x[i] > 0 && eternal_y[i] > 0)
  872.                         {
  873.                             if (bnum[eternal_x[i] - 1][eternal_y[i] - 1] == 0)
  874.                             {
  875.                                 bool potato = false;
  876.                                 for (unsigned short c = 0; c < eternal_size; c++)
  877.                                 {
  878.                                     if (eternal_x[c] == eternal_x[i] - 1 && eternal_y[c] == eternal_y[i] - 1)
  879.                                     {
  880.                                         potato = true;
  881.                                         break;
  882.                                     }
  883.                                 }
  884.                                 if (!potato)
  885.                                 {
  886.                                     eternal_size++;
  887.                                     eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
  888.                                     eternal_x[eternal_size - 1] = eternal_x[i] - 1;
  889.                                     eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
  890.                                     eternal_y[eternal_size - 1] = eternal_y[i] - 1;
  891.                                 }
  892.                             }
  893.                             else if (deskgr[eternal_x[i] - 1][eternal_y[i] - 1] == 32)
  894.                             {
  895.                                 deskgr[eternal_x[i] - 1][eternal_y[i] - 1] = opencl(bnum[eternal_x[i] - 1][eternal_y[i] - 1]);
  896.                                 amount++;
  897.                             }
  898.                         }
  899.                         if (type != 1)
  900.                         {
  901.                             if (eternal_x[i] < type - 1 && eternal_y[i] > 0)
  902.                             {
  903.                                 if (bnum[eternal_x[i] + 1][eternal_y[i] - 1] == 0)
  904.                                 {
  905.                                     bool potato = false;
  906.                                     for (unsigned short c = 0; c < eternal_size; c++)
  907.                                     {
  908.                                         if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i] - 1)
  909.                                         {
  910.                                             potato = true;
  911.                                             break;
  912.                                         }
  913.                                     }
  914.  
  915.                                     if (!potato)
  916.                                     {
  917.                                         eternal_size++;
  918.                                         eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
  919.                                         eternal_x[eternal_size - 1] = eternal_x[i] + 1;
  920.                                         eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
  921.                                         eternal_y[eternal_size - 1] = eternal_y[i] - 1;
  922.                                     }
  923.                                 }
  924.                                 else if (deskgr[eternal_x[i] + 1][eternal_y[i] - 1] == 32)
  925.                                 {
  926.                                     deskgr[eternal_x[i] + 1][eternal_y[i] - 1] = opencl(bnum[eternal_x[i] + 1][eternal_y[i] - 1]);
  927.                                     amount++;
  928.                                 }
  929.                             }
  930.                         }
  931.                         else
  932.                         {
  933.                             if (eternal_x[i] < x - 1 && eternal_y[i] > 0)
  934.                             {
  935.                                 if (bnum[eternal_x[i] + 1][eternal_y[i] - 1] == 0)
  936.                                 {
  937.                                     bool potato = false;
  938.                                     for (unsigned short c = 0; c < eternal_size; c++)
  939.                                     {
  940.                                         if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i] - 1)
  941.                                         {
  942.                                             potato = true;
  943.                                             break;
  944.                                         }
  945.                                     }
  946.                                     if (!potato)
  947.                                     {
  948.                                         eternal_size++;
  949.                                         eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
  950.                                         eternal_x[eternal_size - 1] = eternal_x[i] + 1;
  951.                                         eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
  952.                                         eternal_y[eternal_size - 1] = eternal_y[i] - 1;
  953.                                     }
  954.                                 }
  955.                                 else if (deskgr[eternal_x[i] + 1][eternal_y[i] - 1] == 32)
  956.                                 {
  957.                                     deskgr[eternal_x[i] + 1][eternal_y[i] - 1] = opencl(bnum[eternal_x[i] + 1][eternal_y[i] - 1]);
  958.                                     amount++;
  959.                                 }
  960.                             }
  961.                         }
  962.                         if (type != 1)
  963.                         {
  964.                             if (eternal_x[i] > 0 && eternal_y[i] < type - 1)
  965.                             {
  966.                                 if (bnum[eternal_x[i] - 1][eternal_y[i] + 1] == 0)
  967.                                 {
  968.                                     bool potato = false;
  969.                                     for (unsigned short c = 0; c < eternal_size; c++)
  970.                                     {
  971.                                         if (eternal_x[c] == eternal_x[i] - 1 && eternal_y[c] == eternal_y[i] + 1)
  972.                                         {
  973.                                             potato = true;
  974.                                             break;
  975.                                         }
  976.                                     }
  977.                                     if (!potato)
  978.                                     {
  979.                                         eternal_size++;
  980.                                         eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
  981.                                         eternal_x[eternal_size - 1] = eternal_x[i] - 1;
  982.                                         eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
  983.                                         eternal_y[eternal_size - 1] = eternal_y[i] + 1;
  984.                                     }
  985.                                 }
  986.                                 else if (deskgr[eternal_x[i] - 1][eternal_y[i] + 1] == 32)
  987.                                 {
  988.                                     deskgr[eternal_x[i] - 1][eternal_y[i] + 1] = opencl(bnum[eternal_x[i] - 1][eternal_y[i] + 1]);
  989.                                     amount++;
  990.                                 }
  991.                             }
  992.                         }
  993.                         else
  994.                         {
  995.                             if (eternal_x[i] > 0 && eternal_y[i] < y - 1)
  996.                             {
  997.                                 if (bnum[eternal_x[i] - 1][eternal_y[i] + 1] == 0)
  998.                                 {
  999.                                     bool potato = false;
  1000.                                     for (unsigned short c = 0; c < eternal_size; c++)
  1001.                                     {
  1002.                                         if (eternal_x[c] == eternal_x[i] - 1 && eternal_y[c] == eternal_y[i] + 1)
  1003.                                         {
  1004.                                             potato = true;
  1005.                                             break;
  1006.                                         }
  1007.                                     }
  1008.                                     if (!potato)
  1009.                                     {
  1010.                                         eternal_size++;
  1011.                                         eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
  1012.                                         eternal_x[eternal_size - 1] = eternal_x[i] - 1;
  1013.                                         eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
  1014.                                         eternal_y[eternal_size - 1] = eternal_y[i] + 1;
  1015.                                     }
  1016.                                 }
  1017.                                 else if (deskgr[eternal_x[i] - 1][eternal_y[i] + 1] == 32)
  1018.                                 {
  1019.                                     deskgr[eternal_x[i] - 1][eternal_y[i] + 1] = opencl(bnum[eternal_x[i] - 1][eternal_y[i] + 1]);
  1020.                                     amount++;
  1021.                                 }
  1022.                             }
  1023.                         }
  1024.                         if (type != 1)
  1025.                         {
  1026.                             if (eternal_x[i] < type - 1 && eternal_y[i] < type - 1)
  1027.                             {
  1028.                                 if (bnum[eternal_x[i] + 1][eternal_y[i] + 1] == 0)
  1029.                                 {
  1030.                                     bool potato = false;
  1031.                                     for (unsigned short c = 0; c < eternal_size; c++)
  1032.                                     {
  1033.                                         if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i] + 1)
  1034.                                         {
  1035.                                             potato = true;
  1036.                                             break;
  1037.                                         }
  1038.                                     }
  1039.                                     if (!potato)
  1040.                                     {
  1041.                                         eternal_size++;
  1042.                                         eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
  1043.                                         eternal_x[eternal_size - 1] = eternal_x[i] + 1;
  1044.                                         eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
  1045.                                         eternal_y[eternal_size - 1] = eternal_y[i] + 1;
  1046.                                     }
  1047.                                 }
  1048.                                 else if (deskgr[eternal_x[i] + 1][eternal_y[i] + 1] == 32)
  1049.                                 {
  1050.                                     deskgr[eternal_x[i] + 1][eternal_y[i] + 1] = opencl(bnum[eternal_x[i] + 1][eternal_y[i] + 1]);
  1051.                                     amount++;
  1052.                                 }
  1053.                             }
  1054.                         }
  1055.                         else
  1056.                         {
  1057.                             if (eternal_x[i] < x - 1 && eternal_y[i] < y - 1)
  1058.                             {
  1059.                                 if (bnum[eternal_x[i] + 1][eternal_y[i] + 1] == 0)
  1060.                                 {
  1061.                                     bool potato = false;
  1062.                                     for (unsigned short c = 0; c < eternal_size; c++)
  1063.                                     {
  1064.                                         if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i] + 1)
  1065.                                         {
  1066.                                             potato = true;
  1067.                                             break;
  1068.                                         }
  1069.                                     }
  1070.                                     if (!potato)
  1071.                                     {
  1072.                                         eternal_size++;
  1073.                                         eternal_x = (unsigned short*)realloc(eternal_x, eternal_size * sizeof(unsigned short));
  1074.                                         eternal_x[eternal_size - 1] = eternal_x[i] + 1;
  1075.                                         eternal_y = (unsigned short*)realloc(eternal_y, eternal_size * sizeof(unsigned short));
  1076.                                         eternal_y[eternal_size - 1] = eternal_y[i] + 1;
  1077.                                     }
  1078.                                 }
  1079.                                 else if (deskgr[eternal_x[i] + 1][eternal_y[i] + 1] == 32)
  1080.                                 {
  1081.                                     deskgr[eternal_x[i] + 1][eternal_y[i] + 1] = opencl(bnum[eternal_x[i] + 1][eternal_y[i] + 1]);
  1082.                                     amount++;
  1083.                                 }
  1084.                             }
  1085.                         }
  1086.                     }
  1087.                     free(eternal_x);
  1088.                     free(eternal_y);
  1089.                 }
  1090.                 else
  1091.                 {
  1092.                     deskgr[xh - 1][yh - 1] = opencl(bnum[xh - 1][yh - 1]);
  1093.                     amount++;
  1094.                 }
  1095.                 switch (type)
  1096.                 {
  1097.                 case 8:
  1098.                     printdesk(deskgr, 8, 8);
  1099.                     break;
  1100.                 case 16:
  1101.                     printdesk(deskgr, 16, 16);
  1102.                     break;
  1103.                 case 32:
  1104.                     printdesk(deskgr, 32, 32);
  1105.                     break;
  1106.                 default:
  1107.                     printdesk(deskgr, x, y);
  1108.                     break;
  1109.                 }
  1110.                 space -= amount;
  1111.             }
  1112.             break;
  1113.         }
  1114.     }
  1115.     while (!lose && space != 0);
  1116.     if (!lose)
  1117.     {
  1118.         printf("ВЫ ВЫЖИЛИ!\n");
  1119.         victory = true;
  1120.     }
  1121.     time_t finish = time(NULL);
  1122.     printf("Ваше время: %.0lf секунд\n", difftime(finish, start));
  1123.     free(position);
  1124.     for (unsigned short i = 0; i < type; i++)
  1125.         free(deskgr[i]);
  1126.     free(deskgr);
  1127.     for (unsigned short i = 0; i < type; i++)
  1128.         free(bnum[i]);
  1129.     free(bnum);
  1130. }
  1131. int main()
  1132. {
  1133.     setlocale(LC_ALL, "Russian");
  1134.     unsigned short list_size = 0;
  1135.     struct result* list = (struct result*)malloc(list_size * sizeof(struct result));
  1136.     FILE* fin = fopen("results.bin", "rbe");
  1137.     if (fin == NULL)
  1138.     {
  1139.         FILE* create = fopen("results.bin", "wbe");
  1140.         fclose(create);
  1141.     }
  1142.     else
  1143.     {
  1144.         while (!feof(fin))
  1145.         {
  1146.             struct result guy;
  1147.             unsigned short name_sz = 0, games = 0, vic = 0, iz = 0, hrd = 0, slayer = 0;
  1148.             double pr = 0.0;
  1149.             char x = 0;
  1150.             fread(&name_sz, sizeof(unsigned short), 1, fin);
  1151.             if (name_sz != 0)
  1152.             {
  1153.                 char* namez = (char*)malloc((name_sz + 1) * sizeof(char));
  1154.                 for (unsigned short i = 0; i < name_sz; i++)
  1155.                 {
  1156.                     fread(&x, sizeof(char), 1, fin);
  1157.                     namez[i] = x;
  1158.                 }
  1159.                 namez[name_sz] = '\0';
  1160.                 fread(&games, sizeof(unsigned short), 1, fin);
  1161.                 fread(&vic, sizeof(unsigned short), 1, fin);
  1162.                 fread(&pr, sizeof(double), 1, fin);
  1163.                 fread(&iz, sizeof(unsigned short), 1, fin);
  1164.                 fread(&hrd, sizeof(unsigned short), 1, fin);
  1165.                 fread(&slayer, sizeof(unsigned short), 1, fin);
  1166.                 guy.name = namez;
  1167.                 guy.games = games;
  1168.                 guy.victories = vic;
  1169.                 guy.percent = pr;
  1170.                 guy.izzy = iz;
  1171.                 guy.hard = hrd;
  1172.                 guy.doom_guy = slayer; /*ОСТОРОЖНО, СПОЙЛЕР К DOOM ETERNAL :)*/
  1173.                 list_size++;
  1174.                 list = (struct result*)realloc(list, list_size * sizeof(struct result));
  1175.                 list[list_size - 1] = guy;
  1176.             }
  1177.             else
  1178.                 break;
  1179.         }
  1180.         fclose(fin);
  1181.     }
  1182.     unsigned short choice = 0, gm_ch = 0, res_ch = 0;
  1183.     char* CHOICE = (char*)malloc(0);
  1184.     char* GAME_CH = (char*)malloc(0);
  1185.     char* RES_CH = (char*)malloc(0);
  1186.     char* away = (char*)malloc(0);
  1187.     char* resaw = (char*)malloc(0);
  1188.     bool g8sch = false;
  1189.     bool g16sch = false;
  1190.     bool g32sch = false;
  1191.     do
  1192.     {
  1193.         g8sch = false;
  1194.         g16sch = false;
  1195.         g32sch = false;
  1196.         do
  1197.         {
  1198.             printf("ххххх_САПЁР_ххххх\n");
  1199.             printf("1.Играть\n2.Рекорды\n3.Выход\n");
  1200.             printf("Введите ЦИФРУ, чтобы выполнить действие: ");
  1201.             scanf_rng("%2s", CHOICE);
  1202.             if (*CHOICE != 49 && *CHOICE != 50 && *CHOICE != 51 || CHOICE[1] != 0)
  1203.                 printf("Ввод не корректен\n");
  1204.         }
  1205.         while (*CHOICE != 49 && *CHOICE != 50 && *CHOICE != 51 || CHOICE[1] != 0);
  1206.         switch (*CHOICE)
  1207.         {
  1208.         case 49:
  1209.             choice = 1;
  1210.             break;
  1211.         case 50:
  1212.             choice = 2;
  1213.             break;
  1214.         default:
  1215.             choice = 3;
  1216.             break;
  1217.         }
  1218.         struct result player;
  1219.         switch (choice)
  1220.         {
  1221.         case 1:
  1222.             printf("Введите ваше имя (максимум 15 символов): ");
  1223.             char* name = (char*)malloc(15 * sizeof(char));
  1224.             scanf_rng("%15s", name);
  1225.             player.name = name;
  1226.             do
  1227.             {
  1228.                 printf("Выберите уровень сложности: 1.Просто(доска 8x8, 16 мин); 2.Не так просто(доска 16x16, 32 мины); 3.ХАРДКОР(доска 32x32, 64 мины); 4.Своя игра: ");
  1229.                 scanf_rng("%2s", GAME_CH);
  1230.                 if (*GAME_CH != 49 && *GAME_CH != 50 && *GAME_CH != 51 && *GAME_CH != 52 || GAME_CH[1] != 0)
  1231.                     printf("Ввод не корректен\n");
  1232.             }
  1233.             while (*GAME_CH != 49 && *GAME_CH != 50 && *GAME_CH != 51 && *GAME_CH != 52 || GAME_CH[1] != 0);
  1234.             switch (*GAME_CH)
  1235.             {
  1236.             case 49:
  1237.                 gm_ch = 1;
  1238.                 break;
  1239.             case 50:
  1240.                 gm_ch = 2;
  1241.                 break;
  1242.             case 51:
  1243.                 gm_ch = 3;
  1244.                 break;
  1245.             default:
  1246.                 gm_ch = 4;
  1247.                 break;
  1248.             }
  1249.             switch (gm_ch)
  1250.             {
  1251.             case 1:
  1252.                 for (unsigned short e = 0; e < list_size; e++)
  1253.                 {
  1254.                     if (strcmp(list[e].name, player.name) == 0)
  1255.                     {
  1256.                         g8sch = true;
  1257.                         game(list, list[e], 8);
  1258.                         if (victory)
  1259.                         {
  1260.                             list[e].victories++;
  1261.                             list[e].izzy++;
  1262.                             victory = false;
  1263.                         }
  1264.                         list[e].games++;
  1265.                         list[e].percent = (list[e].victories / (list[e].games / 100.0));
  1266.                         break;
  1267.                     }
  1268.                 }
  1269.                 if (!g8sch)
  1270.                 {
  1271.                     player.victories = 0;
  1272.                     player.izzy = 0;
  1273.                     player.hard = 0;
  1274.                     player.doom_guy = 0;
  1275.                     game(list, player, 8);
  1276.                     if (victory)
  1277.                     {
  1278.                         player.victories = 1;
  1279.                         player.izzy = 1;
  1280.                         victory = false;
  1281.                     }
  1282.                     player.games = 1;
  1283.                     player.percent = (player.victories / (player.games / 100.0));
  1284.                     list_size++;
  1285.                     list = (struct result*)realloc(list, list_size * sizeof(struct result));
  1286.                     list[list_size - 1] = player;
  1287.                 }
  1288.                 save(list, list_size);
  1289.                 break;
  1290.             case 2:
  1291.                 for (unsigned short e = 0; e < list_size; e++)
  1292.                 {
  1293.                     if (strcmp(list[e].name, player.name) == 0)
  1294.                     {
  1295.                         g16sch = true;
  1296.                         game(list, list[e], 16);
  1297.                         if (victory)
  1298.                         {
  1299.                             list[e].victories++;
  1300.                             list[e].hard++;
  1301.                             victory = false;
  1302.                         }
  1303.                         list[e].games++;
  1304.                         list[e].percent = (list[e].victories / (list[e].games / 100.0));
  1305.                         break;
  1306.                     }
  1307.                 }
  1308.                 if (!g16sch)
  1309.                 {
  1310.                     player.victories = 0;
  1311.                     player.izzy = 0;
  1312.                     player.hard = 0;
  1313.                     player.doom_guy = 0;
  1314.                     game(list, player, 16);
  1315.                     if (victory)
  1316.                     {
  1317.                         player.victories = 1;
  1318.                         player.hard = 1;
  1319.                         victory = false;
  1320.                     }
  1321.                     player.games = 1;
  1322.                     player.percent = (player.victories / (player.games / 100.0));
  1323.                     list_size++;
  1324.                     list = (struct result*)realloc(list, list_size * sizeof(struct result));
  1325.                     list[list_size - 1] = player;
  1326.                 }
  1327.                 save(list, list_size);
  1328.                 break;
  1329.             case 3:
  1330.                 for (unsigned short e = 0; e < list_size; e++)
  1331.                 {
  1332.                     if (strcmp(list[e].name, player.name) == 0)
  1333.                     {
  1334.                         g32sch = true;
  1335.                         game(list, list[e], 32);
  1336.                         if (victory)
  1337.                         {
  1338.                             list[e].victories++;
  1339.                             list[e].doom_guy++;
  1340.                             victory = false;
  1341.                         }
  1342.                         list[e].games++;
  1343.                         list[e].percent = (list[e].victories / (list[e].games / 100.0));
  1344.                         break;
  1345.                     }
  1346.                 }
  1347.                 if (!g32sch)
  1348.                 {
  1349.                     player.victories = 0;
  1350.                     player.izzy = 0;
  1351.                     player.hard = 0;
  1352.                     player.doom_guy = 0;
  1353.                     game(list, player, 32);
  1354.                     if (victory)
  1355.                     {
  1356.                         player.victories++;
  1357.                         player.doom_guy++;
  1358.                         victory = false;
  1359.                     }
  1360.                     player.games = 1;
  1361.                     player.percent = (player.victories / (player.games / 100.0));
  1362.                     list_size++;
  1363.                     list = (struct result*)realloc(list, list_size * sizeof(struct result));
  1364.                     list[list_size - 1] = player;
  1365.                 }
  1366.                 save(list, list_size);
  1367.                 break;
  1368.             default:
  1369.                 for (unsigned short e = 0; e < list_size; e++)
  1370.                 {
  1371.                     if (strcmp(list[e].name, player.name) == 0)
  1372.                     {
  1373.                         g8sch = true;
  1374.                         game(list, list[e], 1);
  1375.                         if (victory)
  1376.                         {
  1377.                             list[e].victories++;
  1378.                             victory = false;
  1379.                         }
  1380.                         list[e].games++;
  1381.                         list[e].percent = (list[e].victories / (list[e].games / 100.0));
  1382.                         break;
  1383.                     }
  1384.                 }
  1385.                 if (!g8sch)
  1386.                 {
  1387.                     player.victories = 0;
  1388.                     player.izzy = 0;
  1389.                     player.hard = 0;
  1390.                     player.doom_guy = 0;
  1391.                     game(list, player, 1);
  1392.                     if (victory)
  1393.                     {
  1394.                         player.victories = 1;
  1395.                         victory = false;
  1396.                     }
  1397.                     player.games = 1;
  1398.                     player.percent = (player.victories / (player.games / 100.0));
  1399.                     list_size++;
  1400.                     list = (struct result*)realloc(list, list_size * sizeof(struct result));
  1401.                     list[list_size - 1] = player;
  1402.                 }
  1403.                 save(list, list_size);
  1404.                 break;
  1405.             }
  1406.             break;
  1407.         case 2:
  1408.             do
  1409.             {
  1410.                 printf("Результаты\n");
  1411.                 do
  1412.                 {
  1413.                     printf(
  1414.                         "1.Сыграно игр\n2.Побед на сложности 'легко'\n3.Побед на сложности 'не так легко'\n4.Побед на сложности 'ХАРДКОР'\n5.Процент побед.\n6.Выход\n");
  1415.                     printf("Выберите ЦИФРУ действия: ");
  1416.                     scanf_rng("%2s", RES_CH);
  1417.                     if (*RES_CH != 49 && *RES_CH != 50 && *RES_CH != 51 && *RES_CH != 52 && *RES_CH != 53 && *RES_CH !=54 || RES_CH[1] != 0)
  1418.                         printf("Ввод не корректен\n");
  1419.                 }
  1420.                 while (*RES_CH != 49 && *RES_CH != 50 && *RES_CH != 51 && *RES_CH != 52 && *RES_CH != 53 && *RES_CH != 54 || RES_CH[1] != 0);
  1421.                 switch (*RES_CH)
  1422.                 {
  1423.                 case 49:
  1424.                     res_ch = 1;
  1425.                     break;
  1426.                 case 50:
  1427.                     res_ch = 2;
  1428.                     break;
  1429.                 case 51:
  1430.                     res_ch = 3;
  1431.                     break;
  1432.                 case 52:
  1433.                     res_ch = 4;
  1434.                     break;
  1435.                 case 53:
  1436.                     res_ch = 5;
  1437.                     break;
  1438.                 default:
  1439.                     res_ch = 6;
  1440.                     break;
  1441.                 }
  1442.                 switch (res_ch)
  1443.                 {
  1444.                 case 1:
  1445.                     if (list_size == 0)
  1446.                         printf("Ещё никто не играл...\n");
  1447.                     else
  1448.                     {
  1449.                         qsort(list, list_size, sizeof(*list), compare_games);
  1450.                         for (unsigned short i = list_size; i > 0; i--)
  1451.                             printf("%s : %hu\n", list[i - 1].name, list[i - 1].games);
  1452.                     }
  1453.                     break;
  1454.                 case 2:
  1455.                     if (list_size == 0)
  1456.                         printf("Ещё никто не играл...\n");
  1457.                     else
  1458.                     {
  1459.                         qsort(list, list_size, sizeof(*list), compare_izzy);
  1460.                         for (unsigned short i = list_size; i > 0; i--)
  1461.                             printf("%s : %hu\n", list[i - 1].name, list[i - 1].izzy);
  1462.                     }
  1463.                     break;
  1464.                 case 3:
  1465.                     if (list_size == 0)
  1466.                         printf("Ещё никто не играл...\n");
  1467.                     else
  1468.                     {
  1469.                         qsort(list, list_size, sizeof(*list), compare_hard);
  1470.                         for (unsigned short i = list_size; i > 0; i--)
  1471.                             printf("%s : %hu\n", list[i - 1].name, list[i - 1].hard);
  1472.                     }
  1473.                     break;
  1474.                 case 4:
  1475.                     if (list_size == 0)
  1476.                         printf("Ещё никто не играл...\n");
  1477.                     else
  1478.                     {
  1479.                         qsort(list, list_size, sizeof(*list), compare_doom);
  1480.                         for (unsigned short i = list_size; i > 0; i--)
  1481.                             printf("%s : %hu\n", list[i - 1].name, list[i - 1].doom_guy);
  1482.                     }
  1483.                     break;
  1484.                 case 5:
  1485.                     if (list_size == 0)
  1486.                         printf("Ещё никто не играл...\n");
  1487.                     else
  1488.                     {
  1489.                         qsort(list, list_size, sizeof(*list), compare_percent);
  1490.                         for (unsigned short i = list_size; i > 0; i--)
  1491.                         {
  1492.                             int perc = (int)round(list[i - 1].percent);
  1493.                             printf("%s : %d%%\n", list[i - 1].name, perc);
  1494.                         }
  1495.                     }
  1496.                     break;
  1497.                 default:
  1498.                     printf("Вы точно хотите выйти? Введите YES, если да или что-то другое, если нет.\n");
  1499.                     scanf_rng("%4s", resaw);
  1500.                     if (strcmp(resaw, "YES") != 0)
  1501.                         res_ch = 0;
  1502.                     break;
  1503.                 }
  1504.             }
  1505.             while (res_ch != 6);
  1506.             break;
  1507.         default:
  1508.             printf("Вы точно хотите выйти? Введите YES, если да или что-то другое, если нет.\n");
  1509.             scanf_rng("%4s", away);
  1510.             if (strcmp(away, "YES") != 0)
  1511.                 choice = 0;
  1512.             break;
  1513.         }
  1514.     }
  1515.     while (choice != 3);
  1516.     return 0;
  1517. }
Advertisement
Add Comment
Please, Sign In to add comment