paranid5

SAPPER

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