Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* С++ версия */
- #include <algorithm>
- #include <cmath>
- #include <cstdlib>
- #include <ctime>
- #include <fstream>
- #include <iomanip>
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- bool victory = false;
- struct result
- {
- string name;
- unsigned short games{};
- unsigned short victories{};
- double percent{};
- unsigned short izzy{};/*успешно пройденный просто*/
- unsigned short hard{};/*успешно пройденный не просто*/
- unsigned short doom_guy{};/*успешно пройденный ХАРДКОР*/
- };
- unsigned short compare_games(const result& a, const result& b)
- {
- return a.games < b.games;
- }
- unsigned short compare_izzy(const result& a, const result& b)
- {
- return a.izzy < b.izzy;
- }
- unsigned short compare_hard(const result& a, const result& b)
- {
- return a.hard < b.hard;
- }
- unsigned short compare_doom(const result& a, const result& b)
- {
- return a.doom_guy < b.doom_guy;
- }
- unsigned short compare_percent(const result& a, const result& b)
- {
- return a.percent < b.percent;
- }
- void save(vector<result>&save)
- {
- ofstream fout("results.bin", ios::binary);
- for (result& q : save)
- {
- unsigned short sz = q.name.size();
- fout.write(reinterpret_cast<char*>(&sz), sizeof(sz));
- fout.write(q.name.data(), sz);
- fout.write(reinterpret_cast<char*>(&q.games), sizeof(q.games));
- fout.write(reinterpret_cast<char*>(&q.victories), sizeof(q.victories));
- fout.write(reinterpret_cast<char*>(&q.percent), sizeof(q.percent));
- fout.write(reinterpret_cast<char*>(&q.izzy), sizeof(q.izzy));
- fout.write(reinterpret_cast<char*>(&q.hard), sizeof(q.hard));
- fout.write(reinterpret_cast<char*>(&q.doom_guy), sizeof(q.doom_guy));
- }
- fout.close();
- }
- void printdesk(char** deskgr, const unsigned short x, const unsigned short y)
- {
- ios_base::sync_with_stdio(false);
- cout << " ";
- for (unsigned short i = 1; i < y + 1; i++)
- cout << " " << i % 10;
- cout << "\n";
- for (unsigned short i = 0; i < x; i++)
- {
- cout << " ";
- for (unsigned short q = 1; q < y + 1; q++)
- cout << " _";
- cout << "\n";
- cout<<(i + 1) % 10 << " ";
- for (unsigned short q = 0; q < y; q++)
- cout << "|" << deskgr[i][q];
- cout << "|\n";
- }
- cout << " ";
- for (unsigned short q = 1; q < y + 1; q++)
- cout << " _";
- cout << "\n";
- }
- char opencl(const unsigned short num)
- {
- switch (num)
- {
- case 0:
- return 48;
- break;
- case 1:
- return 49;
- break;
- case 2:
- return 50;
- break;
- case 3:
- return 51;
- break;
- case 4:
- return 52;
- break;
- case 5:
- return 53;
- break;
- case 6:
- return 54;
- break;
- case 7:
- return 55;
- break;
- default:
- return 56;
- break;
- }
- }
- short to_hu(string& XM)
- {
- ios_base::sync_with_stdio(false);
- unsigned short xm = 0;
- bool correct = true;
- 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)
- {
- switch (XM[0])
- {
- case 49:
- xm = 10;
- break;
- case 50:
- xm = 20;
- break;
- case 51:
- xm = 30;
- break;
- default:
- cout << "Ввод не корректен.\n";
- correct = false;
- break;
- }
- if (correct)
- {
- switch (XM[1])
- {
- case 48:
- break;
- case 49:
- xm++;
- break;
- case 50:
- xm += 2;
- break;
- case 51:
- xm += 3;
- break;
- case 52:
- xm += 4;
- break;
- case 53:
- xm += 5;
- break;
- case 54:
- xm += 6;
- break;
- case 55:
- xm += 7;
- break;
- case 56:
- xm += 8;
- break;
- case 57:
- xm += 9;
- break;
- default:
- cout<<"Ввод не корректен.\n";
- correct = false;
- break;
- }
- }
- if (correct && XM[2] != 0)
- {
- cout << "Ввод не корректен.\n";
- correct = false;
- }
- }
- else if (XM[1] == 0)
- {
- switch (XM[0])
- {
- case 48:
- break;
- case 49:
- xm++;
- break;
- case 50:
- xm += 2;
- break;
- case 51:
- xm += 3;
- break;
- case 52:
- xm += 4;
- break;
- case 53:
- xm += 5;
- break;
- case 54:
- xm += 6;
- break;
- case 55:
- xm += 7;
- break;
- case 56:
- xm += 8;
- break;
- case 57:
- xm += 9;
- break;
- default:
- cout << "Ввод не корректен.\n";
- correct = false;
- break;
- }
- }
- else
- {
- cout << "Ввод не корректен.\n";;
- correct = false;
- }
- return correct ? xm : -1;
- }
- void game(vector<result>&p, const unsigned short type)
- {
- ios_base::sync_with_stdio(false);
- unsigned short x = 0, y = 0;/*custom*/
- unsigned short mines = 0;
- char** deskgr = 0;
- unsigned short** bnum = 0;
- unsigned short count = 0;/*кол-во мин*/
- unsigned short* position = 0;
- if (type != 1)
- {
- deskgr = new char*[type];
- for (unsigned short i = 0; i < type; i++)
- deskgr[i] = new char[type];
- for (unsigned short i = 0; i < type; i++)
- for (unsigned short q = 0; q < type; q++)
- deskgr[i][q] = 32;
- /*то, что отображается*/
- bnum = new unsigned short* [type];
- for (unsigned short i = 0; i < type; i++)
- bnum[i] = new unsigned short[type];
- for (unsigned short i = 0; i < type; i++)
- for (unsigned short q = 0; q < type; q++)
- bnum[i][q] = 0;
- /*номера(рядом с минами)*/
- switch (type)
- {
- case 8:
- printdesk(deskgr, 8, 8);
- break;
- case 16:
- printdesk(deskgr, 16, 16);
- break;
- default:
- printdesk(deskgr, 32, 32);
- break;
- }
- srand(time(nullptr));
- count = 0;
- position = new unsigned short[type * 2];/*номера мин*/
- while (count != type * 2)
- {
- bool test = false;
- unsigned short place = rand() % ((type * type - 1) - 0 + 1) + 0; /*позиция мины*/
- for (unsigned short i = 0; i < count; i++)
- {
- if (place == position[i])
- {
- test = true;
- break;
- }
- }
- if (!test)
- {
- count++;
- position[count - 1] = place;
- }
- } /*создали мины*/
- unsigned short xc = 0, yc = 0;
- for (unsigned short q = 0; q < count; q++)
- {
- xc = position[q] / type; /*строка с миной*/
- yc = position[q] - (type * xc); /*столбец с миной*/
- /*определили положение мины*/
- if (xc > 0)
- bnum[xc - 1][yc]++;
- if (xc < type - 1)
- bnum[xc + 1][yc]++;
- if (yc > 0)
- bnum[xc][yc - 1]++;
- if (yc < type - 1)
- bnum[xc][yc + 1]++;
- if (xc > 0 && yc > 0)
- bnum[xc - 1][yc - 1]++;
- if (xc < type - 1 && yc > 0)
- bnum[xc + 1][yc - 1]++;
- if (xc > 0 && yc < type - 1)
- bnum[xc - 1][yc + 1]++;
- if (xc < type - 1 && yc < type - 1)
- bnum[xc + 1][yc + 1]++;
- } /*Заполнили номерами для мин*/
- }
- else
- {
- string X;
- string Y;
- cout << "Задайте размер доски.\n";
- do
- {
- cout << "Кол-во строк(не больше 50, минимум 3): ";
- cin >> X;
- cin.ignore(32767, '\n');
- cin.clear();
- x = stoi(X);
- if (x < 3 || x > 50)
- cout << "Ввод не корректен\n";
- }
- while (x < 3 || x > 50);
- do
- {
- cout << "Кол-во столбцов(не больше 50, минимум 3): ";
- cin >> Y;
- cin.ignore(32767, '\n');
- cin.clear();
- y = stoi(Y);
- if (y < 3 || y > 50)
- cout<<"Ввод не корректен\n";
- }
- while (y < 3 || y > 50);
- deskgr = new char* [x];
- for (unsigned short i = 0; i < x; i++)
- deskgr[i] = new char[y];
- for (unsigned short i = 0; i < x; i++)
- for (unsigned short q = 0; q < y; q++)
- deskgr[i][q] = 32;
- /*то, что отображается*/
- bnum = new unsigned short* [x];
- for (unsigned short i = 0; i < x; i++)
- bnum[i] = new unsigned short[y];
- for (unsigned short i = 0; i < x; i++)
- for (unsigned short q = 0; q < y; q++)
- bnum[i][q] = 0;
- /*номера(рядом с минами)*/
- printdesk(deskgr, x, y);
- do
- {
- mines = 0;
- string MINES;
- cout << "Задайте кол-во мин (минимум 5%% от площади доски и максимум 95%%): ";
- cin >> MINES;
- cin.ignore(32767, '\n');
- cin.clear();
- mines = stoi(MINES);
- if (mines < (y * x) / 100.0 * 5 || mines >(y * x) / 100.0 * 95)
- cout << "Ввод не корректен\n";
- }
- while (mines < (y * x) / 100.0 * 5 || mines >(y * x) / 100.0 * 95);
- srand(time(nullptr));
- count = 0;
- position = new unsigned short[mines];/*номера мин*/
- while (count != mines)
- {
- bool test = false;
- unsigned short place = rand() % ((x * y - 1) - 0 + 1) + 0; /*позиция мины*/
- for (unsigned short i = 0; i < count; i++)
- {
- if (place == position[i])
- {
- test = true;
- break;
- }
- }
- if (!test)
- {
- count++;
- position[count - 1] = place;
- }
- } /*создали мины*/
- unsigned short xc = 0, yc = 0;
- for (unsigned short q = 0; q < count; q++)
- {
- xc = position[q] / y;/*строка с миной*/
- yc = position[q] - y * xc;/*столбец с миной*/
- /*определили положение мины*/
- if (xc > 0)
- bnum[xc - 1][yc]++;
- if (xc < x - 1)
- bnum[xc + 1][yc]++;
- if (yc > 0)
- bnum[xc][yc - 1]++;
- if (yc < y - 1)
- bnum[xc][yc + 1]++;
- if (xc > 0 && yc > 0)
- bnum[xc - 1][yc - 1]++;
- if (xc < x - 1 && yc > 0)
- bnum[xc + 1][yc - 1]++;
- if (xc > 0 && yc < y - 1)
- bnum[xc - 1][yc + 1]++;
- if (xc < x - 1 && yc < y - 1)
- bnum[xc + 1][yc + 1]++;
- }/*Заполнили номерами для мин*/
- }
- unsigned short xh = 0, yh = 0, mch = 0, mv = 0;
- bool lose = false;
- unsigned short space = type != 1 ? type * type - type * 2 : x * y - mines;/*не мины*/;
- string MV, YESf, YESd, YESm, XM, YM, XD, YD, XH, YH;
- time_t start = time(nullptr);
- do
- {
- do
- {
- cout << "1. Поставить метку\n2. Убрать метку\n3. Сделать ход\n";
- cout << "Выберите ЦИФРУ: ";
- cin >> MV;
- cin.ignore(32767, '\n');
- cin.clear();
- if (MV[0] != 49 && MV[0] != 50 && MV[0] != 51 || MV[1] != 0)
- cout << "Ввод не коректен\n";
- }
- while (MV[0] != 49 && MV[0] != 50 && MV[0] != 51 || MV[1] != 0);
- switch (MV[0])
- {
- case 49:
- mv = 1;
- break;
- case 50:
- mv = 2;
- break;
- default:
- mv = 3;
- break;
- }
- switch (mv)
- {
- case 1:
- do
- {
- cout << "Если у вас есть предположение о месте мин, то можете поставить + на это место. Если хотите это сделать, то введите YES, иначе что-то другое: ";
- cin >> YESf;
- cin.ignore(32767, '\n');
- cin.clear();
- if (YESf == "YES")
- {
- unsigned short xm = 0, ym = 0;/*координаты мин*/
- short xt = 0, yt = 0;/*тест*/
- cout << "Введите координаты мины.\n";
- do
- {
- xm = 0;
- cout << "Введите номер строки: ";
- cin >> XM;
- cin.ignore(32767, '\n');
- cin.clear();
- xt = to_hu(XM);
- }
- while (xt == -1);
- xm = xt;
- do
- {
- ym = 0;
- cout << "Введите номер столбца: ";
- cin >> YM;
- cin.ignore(32767, '\n');
- cin.clear();
- yt = to_hu(YM);
- }
- while (yt == -1);
- ym = yt;
- if (type != 1)
- {
- if ((xm > type || xm < 1) && (ym > type || ym < 1))
- {
- cout << "Вы вышли за рамки доски\n";
- break;
- }
- }
- else if ((xm > x || xm < 1) && (ym > y || ym < 1))
- {
- cout << "Вы вышли за рамки доски\n";
- break;
- }
- if (deskgr[xm - 1][ym - 1] != 32)
- {
- cout << "Сомневаюсь, что вы хотите поставить сюда метку...\n";
- break;
- }
- deskgr[xm - 1][ym - 1] = 43;
- switch (type)
- {
- case 8:
- printdesk(deskgr, 8, 8);
- break;
- case 16:
- printdesk(deskgr, 16, 16);
- break;
- case 32:
- printdesk(deskgr, 32, 32);
- break;
- default:
- printdesk(deskgr, x, y);
- break;
- }
- }
- }
- while (YESf == "YES");
- break;
- case 2:
- do
- {
- cout << "Вы можете убрать метку на мину. Если хотите это сделать, то введите YES, иначе что-то другое: ";
- cin >> YESd;
- cin.ignore(32767, '\n');
- cin.clear();
- if (YESd == "YES")
- {
- unsigned short xm = 0, ym = 0;/*координаты мин*/
- short xt = 0, yt = 0;/*тест*/
- cout << "Введите координаты мины.\n";
- do
- {
- xm = 0;
- cout << "Введите номер строки: ";
- cin >> XD;
- cin.ignore(32767, '\n');
- cin.clear();
- xt = to_hu(XD);
- }
- while (xt == -1);
- xm = xt;
- do
- {
- ym = 0;
- cout << "Введите номер столбца: ";
- cin >> YD;
- cin.ignore(32767, '\n');
- cin.clear();
- yt = to_hu(YD);
- }
- while (yt == -1);
- ym = yt;
- if (type != 1)
- {
- if ((xm > type || xm < 1) && (ym > type || ym < 1))
- {
- cout << "Вы вышли за рамки доски\n";
- break;
- }
- }
- else if ((xm > x || xm < 1) && (ym > y || ym < 1))
- {
- cout << "Вы вышли за рамки доски\n";
- break;
- }
- if (deskgr[xm - 1][ym - 1] != 43)
- {
- cout << "Здесь нет метки...\n";
- break;
- }
- deskgr[xm - 1][ym - 1] = 32;
- switch (type)
- {
- case 8:
- printdesk(deskgr, 8, 8);
- break;
- case 16:
- printdesk(deskgr, 16, 16);
- break;
- case 32:
- printdesk(deskgr, 32, 32);
- break;
- default:
- printdesk(deskgr, x, y);
- break;
- }
- }
- }
- while (YESd == "YES");
- break;
- default:
- cout << "Вы уверены, что хотите совершить ход? Если да, то введите YES, иначе что-то другое: ";
- cin >> YESm;
- cin.ignore(32767, '\n');
- cin.clear();
- if (YESm != "YES")
- break;
- short xt = 0, yt = 0;/*тест*/
- bool beyond = false;
- do
- {
- cout << "Введите координаты мины\n";
- do
- {
- xh = 0;
- cout << "Введите номер строки: ";
- cin >> XH;
- cin.ignore(32767, '\n');
- cin.clear();
- xt = to_hu(XH);
- }
- while (xt == -1);
- xh = xt;
- do
- {
- yh = 0;
- cout << "Введите номер столбца: ";
- cin >> YH;
- cin.ignore(32767, '\n');
- cin.clear();
- yt = to_hu(YH);
- }
- while (yt == -1);
- yh = yt;
- beyond = false;
- if (type != 1)
- {
- if ((xh > type || xh < 1) && (yh > type || yh < 1))
- {
- cout << "Вы вышли за рамки доски\n";
- beyond = true;
- }
- }
- else if ((xh > x || xh < 1) && (yh > y || yh < 1))
- {
- cout << "Вы вышли за рамки доски\n";
- beyond = true;
- }
- }
- while (beyond);
- for (unsigned short c = 0; c < count; c++)
- {
- if (type != 1)
- {
- if ((xh - 1) * type + yh - 1 == position[c]) /*просрали*/
- {
- for (unsigned short o = 0; o < count; o++)
- deskgr[position[o] / type][position[o] - (position[o] / type) * type] = 120;
- switch (type)
- {
- case 8:
- printdesk(deskgr, 8, 8);
- break;
- case 16:
- printdesk(deskgr, 16, 16);
- break;
- default:
- printdesk(deskgr, 32, 32);
- break;
- }
- cout << "Вы взорвались :(\n";
- lose = true;
- break;
- }
- }
- else if ((xh - 1) * y + yh - 1 == position[c]) /*просрали*/
- {
- for (unsigned short o = 0; o < count; o++)
- deskgr[position[o] / y][position[o] - (position[o] / y) * y] = 120;
- printdesk(deskgr, x, y);
- cout << "Вы взорвались :(\n";
- lose = true;
- break;
- }
- }
- if (!lose && deskgr[xh - 1][yh - 1] != 32)
- cout << "Эта клетка уже открыта\n";
- else if (!lose && deskgr[xh - 1][yh - 1] == 32) /*не просрали*/
- {
- unsigned short i = 0;
- unsigned short amount = 0;
- if (bnum[xh - 1][yh - 1] == 0) /*открытие клеток*/
- {
- vector<unsigned short>eternal_x(1, xh - 1);/*строки 0*/
- vector<unsigned short>eternal_y(1, yh - 1);/*столбцы 0*/
- for (i = 0; i < eternal_x.size(); i++)
- {
- deskgr[eternal_x[i]][eternal_y[i]] = 48;
- amount++;
- if (eternal_x[i] > 0)
- {
- if (bnum[eternal_x[i] - 1][eternal_y[i]] == 0)
- {
- bool potato = false;
- for (unsigned short c = 0; c < eternal_x.size(); c++)
- {
- if (eternal_x[c] == eternal_x[i] - 1 && eternal_y[c] == eternal_y[i])
- {
- potato = true;
- break;
- }
- }
- if (!potato)
- {
- eternal_x.push_back(eternal_x[i] - 1);
- eternal_y.push_back(eternal_y[i]);
- }
- }
- else if (deskgr[eternal_x[i] - 1][eternal_y[i]] == 32)
- {
- deskgr[eternal_x[i] - 1][eternal_y[i]] = opencl(bnum[eternal_x[i] - 1][eternal_y[i]]);
- amount++;
- }
- }
- if (type != 1)
- {
- if (eternal_x[i] < type - 1)
- {
- if (bnum[eternal_x[i] + 1][eternal_y[i]] == 0)
- {
- bool potato = false;
- for (unsigned short c = 0; c < eternal_x.size(); c++)
- {
- if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i])
- {
- potato = true;
- break;
- }
- }
- if (!potato)
- {
- eternal_x.push_back(eternal_x[i] + 1);
- eternal_y.push_back(eternal_y[i]);
- }
- }
- else if (deskgr[eternal_x[i] + 1][eternal_y[i]] == 32)
- {
- deskgr[eternal_x[i] + 1][eternal_y[i]] = opencl(bnum[eternal_x[i] + 1][eternal_y[i]]);
- amount++;
- }
- }
- }
- else
- {
- if (eternal_x[i] < x - 1)
- {
- if (bnum[eternal_x[i] + 1][eternal_y[i]] == 0)
- {
- bool potato = false;
- for (unsigned short c = 0; c < eternal_x.size(); c++)
- {
- if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i])
- {
- potato = true;
- break;
- }
- }
- if (!potato)
- {
- eternal_x.push_back(eternal_x[i] + 1);
- eternal_y.push_back(eternal_y[i]);
- }
- }
- else if (deskgr[eternal_x[i] + 1][eternal_y[i]] == 32)
- {
- deskgr[eternal_x[i] + 1][eternal_y[i]] = opencl(bnum[eternal_x[i] + 1][eternal_y[i]]);
- amount++;
- }
- }
- }
- if (eternal_y[i] > 0)
- {
- if (bnum[eternal_x[i]][eternal_y[i] - 1] == 0)
- {
- bool potato = false;
- for (unsigned short c = 0; c < eternal_x.size(); c++)
- {
- if (eternal_x[c] == eternal_x[i] && eternal_y[c] == eternal_y[i] - 1)
- {
- potato = true;
- break;
- }
- }
- if (!potato)
- {
- eternal_x.push_back(eternal_x[i]);
- eternal_y.push_back(eternal_y[i] - 1);
- }
- }
- else if (deskgr[eternal_x[i]][eternal_y[i] - 1] == 32)
- {
- deskgr[eternal_x[i]][eternal_y[i] - 1] = opencl(bnum[eternal_x[i]][eternal_y[i] - 1]);
- amount++;
- }
- }
- if (type != 1)
- {
- if (eternal_y[i] < type - 1)
- {
- if (bnum[eternal_x[i]][eternal_y[i] + 1] == 0)
- {
- bool potato = false;
- for (unsigned short c = 0; c < eternal_x.size(); c++)
- {
- if (eternal_x[c] == eternal_x[i] && eternal_y[c] == eternal_y[i] + 1)
- {
- potato = true;
- break;
- }
- }
- if (!potato)
- {
- eternal_x.push_back(eternal_x[i]);
- eternal_y.push_back(eternal_y[i] + 1);
- }
- }
- else if (deskgr[eternal_x[i]][eternal_y[i] + 1] == 32)
- {
- deskgr[eternal_x[i]][eternal_y[i] + 1] = opencl(bnum[eternal_x[i]][eternal_y[i] + 1]);
- amount++;
- }
- }
- }
- else
- {
- if (eternal_y[i] < y - 1)
- {
- if (bnum[eternal_x[i]][eternal_y[i] + 1] == 0)
- {
- bool potato = false;
- for (unsigned short c = 0; c < eternal_x.size(); c++)
- {
- if (eternal_x[c] == eternal_x[i] && eternal_y[c] == eternal_y[i] + 1)
- {
- potato = true;
- break;
- }
- }
- if (!potato)
- {
- eternal_x.push_back(eternal_x[i]);
- eternal_y.push_back(eternal_y[i] + 1);
- }
- }
- else if (deskgr[eternal_x[i]][eternal_y[i] + 1] == 32)
- {
- deskgr[eternal_x[i]][eternal_y[i] + 1] = opencl(bnum[eternal_x[i]][eternal_y[i] + 1]);
- amount++;
- }
- }
- }
- if (eternal_x[i] > 0 && eternal_y[i] > 0)
- {
- if (bnum[eternal_x[i] - 1][eternal_y[i] - 1] == 0)
- {
- bool potato = false;
- for (unsigned short c = 0; c < eternal_x.size(); c++)
- {
- if (eternal_x[c] == eternal_x[i] - 1 && eternal_y[c] == eternal_y[i] - 1)
- {
- potato = true;
- break;
- }
- }
- if (!potato)
- {
- eternal_x.push_back(eternal_x[i] - 1);
- eternal_y.push_back(eternal_y[i] - 1);
- }
- }
- else if (deskgr[eternal_x[i] - 1][eternal_y[i] - 1] == 32)
- {
- deskgr[eternal_x[i] - 1][eternal_y[i] - 1] = opencl(bnum[eternal_x[i] - 1][eternal_y[i] - 1]);
- amount++;
- }
- }
- if (type != 1)
- {
- if (eternal_x[i] < type - 1 && eternal_y[i] > 0)
- {
- if (bnum[eternal_x[i] + 1][eternal_y[i] - 1] == 0)
- {
- bool potato = false;
- for (unsigned short c = 0; c < eternal_x.size(); c++)
- {
- if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i] - 1)
- {
- potato = true;
- break;
- }
- }
- if (!potato)
- {
- eternal_x.push_back(eternal_x[i] + 1);
- eternal_y.push_back(eternal_y[i] - 1);
- }
- }
- else if (deskgr[eternal_x[i] + 1][eternal_y[i] - 1] == 32)
- {
- deskgr[eternal_x[i] + 1][eternal_y[i] - 1] = opencl(bnum[eternal_x[i] + 1][eternal_y[i] - 1]);
- amount++;
- }
- }
- }
- else
- {
- if (eternal_x[i] < x - 1 && eternal_y[i] > 0)
- {
- if (bnum[eternal_x[i] + 1][eternal_y[i] - 1] == 0)
- {
- bool potato = false;
- for (unsigned short c = 0; c < eternal_x.size(); c++)
- {
- if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i] - 1)
- {
- potato = true;
- break;
- }
- }
- if (!potato)
- {
- eternal_x.push_back(eternal_x[i] + 1);
- eternal_y.push_back(eternal_y[i] - 1);
- }
- }
- else if (deskgr[eternal_x[i] + 1][eternal_y[i] - 1] == 32)
- {
- deskgr[eternal_x[i] + 1][eternal_y[i] - 1] = opencl(bnum[eternal_x[i] + 1][eternal_y[i] - 1]);
- amount++;
- }
- }
- }
- if (type != 1)
- {
- if (eternal_x[i] > 0 && eternal_y[i] < type - 1)
- {
- if (bnum[eternal_x[i] - 1][eternal_y[i] + 1] == 0)
- {
- bool potato = false;
- for (unsigned short c = 0; c < eternal_x.size(); c++)
- {
- if (eternal_x[c] == eternal_x[i] - 1 && eternal_y[c] == eternal_y[i] + 1)
- {
- potato = true;
- break;
- }
- }
- if (!potato)
- {
- eternal_x.push_back(eternal_x[i] - 1);
- eternal_y.push_back(eternal_y[i] + 1);
- }
- }
- else if (deskgr[eternal_x[i] - 1][eternal_y[i] + 1] == 32)
- {
- deskgr[eternal_x[i] - 1][eternal_y[i] + 1] = opencl(bnum[eternal_x[i] - 1][eternal_y[i] + 1]);
- amount++;
- }
- }
- }
- else
- {
- if (eternal_x[i] > 0 && eternal_y[i] < y - 1)
- {
- if (bnum[eternal_x[i] - 1][eternal_y[i] + 1] == 0)
- {
- bool potato = false;
- for (unsigned short c = 0; c < eternal_x.size(); c++)
- {
- if (eternal_x[c] == eternal_x[i] - 1 && eternal_y[c] == eternal_y[i] + 1)
- {
- potato = true;
- break;
- }
- }
- if (!potato)
- {
- eternal_x.push_back(eternal_x[i] - 1);
- eternal_y.push_back(eternal_y[i] + 1);
- }
- }
- else if (deskgr[eternal_x[i] - 1][eternal_y[i] + 1] == 32)
- {
- deskgr[eternal_x[i] - 1][eternal_y[i] + 1] = opencl(bnum[eternal_x[i] - 1][eternal_y[i] + 1]);
- amount++;
- }
- }
- }
- if (type != 1)
- {
- if (eternal_x[i] < type - 1 && eternal_y[i] < type - 1)
- {
- if (bnum[eternal_x[i] + 1][eternal_y[i] + 1] == 0)
- {
- bool potato = false;
- for (unsigned short c = 0; c < eternal_x.size(); c++)
- {
- if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i] + 1)
- {
- potato = true;
- break;
- }
- }
- if (!potato)
- {
- eternal_x.push_back(eternal_x[i] + 1);
- eternal_y.push_back(eternal_y[i] + 1);
- }
- }
- else if (deskgr[eternal_x[i] + 1][eternal_y[i] + 1] == 32)
- {
- deskgr[eternal_x[i] + 1][eternal_y[i] + 1] = opencl(bnum[eternal_x[i] + 1][eternal_y[i] + 1]);
- amount++;
- }
- }
- }
- else
- {
- if (eternal_x[i] < x - 1 && eternal_y[i] < y - 1)
- {
- if (bnum[eternal_x[i] + 1][eternal_y[i] + 1] == 0)
- {
- bool potato = false;
- for (unsigned short c = 0; c < eternal_x.size(); c++)
- {
- if (eternal_x[c] == eternal_x[i] + 1 && eternal_y[c] == eternal_y[i] + 1)
- {
- potato = true;
- break;
- }
- }
- if (!potato)
- {
- eternal_x.push_back(eternal_x[i] + 1);
- eternal_y.push_back(eternal_y[i] + 1);
- }
- }
- else if (deskgr[eternal_x[i] + 1][eternal_y[i] + 1] == 32)
- {
- deskgr[eternal_x[i] + 1][eternal_y[i] + 1] = opencl(bnum[eternal_x[i] + 1][eternal_y[i] + 1]);
- amount++;
- }
- }
- }
- }
- }
- else
- {
- deskgr[xh - 1][yh - 1] = opencl(bnum[xh - 1][yh - 1]);
- amount++;
- }
- switch (type)
- {
- case 8:
- printdesk(deskgr, 8, 8);
- break;
- case 16:
- printdesk(deskgr, 16, 16);
- break;
- case 32:
- printdesk(deskgr, 32, 32);
- break;
- default:
- printdesk(deskgr, x, y);
- break;
- }
- space -= amount;
- }
- break;
- }
- }
- while (!lose && space != 0);
- if (!lose)
- {
- cout << "ВЫ ВЫЖИЛИ!\n";
- victory = true;
- }
- time_t finish = time(nullptr);
- cout << "Ваше время: " << setprecision(0) << difftime(finish, start) << " секунд\n";
- delete position;
- for (unsigned short i = 0; i < type; i++)
- delete deskgr[i];
- delete deskgr;
- for (unsigned short i = 0; i < type; i++)
- delete bnum[i];
- delete bnum;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- setlocale(LC_ALL, "Russian");
- vector<result>list;
- ifstream fin("results.bin", ios::binary);
- if (!fin.good())
- {
- ofstream create("results.bin", ios::binary);
- create.close();
- }
- else
- {
- while (!fin.eof())
- {
- result guy;
- string namez;
- unsigned short name_sz = 0, games = 0, vic = 0, iz = 0, hrd = 0, slayer = 0;
- double pr = 0.0;
- char x = 0;
- fin.read(reinterpret_cast<char*>(&name_sz), sizeof(name_sz));
- if (name_sz != 0)
- {
- namez.resize(name_sz + 1);
- fin.read(&namez[0], name_sz);
- fin.read(reinterpret_cast<char*>(&games), sizeof(games));
- fin.read(reinterpret_cast<char*>(&vic), sizeof(vic));
- fin.read(reinterpret_cast<char*>(&pr), sizeof(pr));
- fin.read(reinterpret_cast<char*>(&iz), sizeof(iz));
- fin.read(reinterpret_cast<char*>(&hrd), sizeof(hrd));
- fin.read(reinterpret_cast<char*>(&slayer), sizeof(slayer));
- guy.name = namez;
- guy.games = games;
- guy.victories = vic;
- guy.percent = pr;
- guy.izzy = iz;
- guy.hard = hrd;
- guy.doom_guy = slayer; /*ОСТОРОЖНО, СПОЙЛЕР К DOOM ETERNAL :)*/
- list.push_back(guy);
- }
- else
- break;
- }
- fin.close();
- }
- unsigned short choice = 0, gm_ch = 0, res_ch = 0;
- string CHOICE;
- string GAME_CH;
- string RES_CH;
- string away;
- string resaw;
- bool g8sch = false;
- bool g16sch = false;
- bool g32sch = false;
- do
- {
- g8sch = false;
- g16sch = false;
- g32sch = false;
- do
- {
- cout << "ххххх_САПЁР_ххххх\n";
- cout << "1.Играть\n2.Рекорды\n3.Выход\n";
- cout << "Введите ЦИФРУ, чтобы выполнить действие: ";
- cin >> CHOICE;
- cin.ignore(32767, '\n');
- cin.clear();
- if (CHOICE[0] != 49 && CHOICE[0] != 50 && CHOICE[0] != 51 || CHOICE[1] != 0)
- cout << "Ввод не корректен\n";
- }
- while (CHOICE[0] != 49 && CHOICE[0] != 50 && CHOICE[0] != 51 || CHOICE[1] != 0);
- switch (CHOICE[0])
- {
- case 49:
- choice = 1;
- break;
- case 50:
- choice = 2;
- break;
- default:
- choice = 3;
- break;
- }
- result player;
- string name;
- switch (choice)
- {
- case 1:
- cout << "Введите ваше имя (максимум 15 символов): ";
- cin >> skipws >> name;
- cin.ignore(32767, '\n');
- cin.clear();
- player.name = name;
- do
- {
- cout << "Выберите уровень сложности: 1.Просто(доска 8x8, 16 мин); 2.Не так просто(доска 16x16, 32 мины); 3.ХАРДКОР(доска 32x32, 64 мины); 4.Своя игра: ";
- cin >> GAME_CH;
- cin.ignore(32767, '\n');
- cin.clear();
- if (GAME_CH[0] != 49 && GAME_CH[0] != 50 && GAME_CH[0] != 51 && GAME_CH[0] != 52 || GAME_CH[1] != 0)
- cout << "Ввод не корректен\n";
- }
- while (GAME_CH[0] != 49 && GAME_CH[0] != 50 && GAME_CH[0] != 51 && GAME_CH[0] != 52 || GAME_CH[1] != 0);
- switch (GAME_CH[0])
- {
- case 49:
- gm_ch = 1;
- break;
- case 50:
- gm_ch = 2;
- break;
- case 51:
- gm_ch = 3;
- break;
- default:
- gm_ch = 4;
- break;
- }
- switch (gm_ch)
- {
- case 1:
- for (unsigned short e = 0; e < list.size(); e++)
- {
- if (list[e].name == player.name)
- {
- g8sch = true;
- game(list, 8);
- if (victory)
- {
- list[e].victories++;
- list[e].izzy++;
- victory = false;
- }
- list[e].games++;
- list[e].percent = (list[e].victories / (list[e].games / 100.0));
- break;
- }
- }
- if (!g8sch)
- {
- player.victories = 0;
- player.izzy = 0;
- player.hard = 0;
- player.doom_guy = 0;
- game(list, 8);
- if (victory)
- {
- player.victories = 1;
- player.izzy = 1;
- victory = false;
- }
- player.games = 1;
- player.percent = (player.victories / (player.games / 100.0));
- list.push_back(player);
- }
- save(list);
- break;
- case 2:
- for (unsigned short e = 0; e < list.size(); e++)
- {
- if (list[e].name == player.name)
- {
- g16sch = true;
- game(list, 16);
- if (victory)
- {
- list[e].victories++;
- list[e].hard++;
- victory = false;
- }
- list[e].games++;
- list[e].percent = (list[e].victories / (list[e].games / 100.0));
- break;
- }
- }
- if (!g16sch)
- {
- player.victories = 0;
- player.izzy = 0;
- player.hard = 0;
- player.doom_guy = 0;
- game(list, 16);
- if (victory)
- {
- player.victories = 1;
- player.hard = 1;
- victory = false;
- }
- player.games = 1;
- player.percent = (player.victories / (player.games / 100.0));
- list.push_back(player);
- }
- save(list);
- break;
- case 3:
- for (unsigned short e = 0; e < list.size(); e++)
- {
- if (list[e].name == player.name)
- {
- g32sch = true;
- game(list, 32);
- if (victory)
- {
- list[e].victories++;
- list[e].doom_guy++;
- victory = false;
- }
- list[e].games++;
- list[e].percent = (list[e].victories / (list[e].games / 100.0));
- break;
- }
- }
- if (!g32sch)
- {
- player.victories = 0;
- player.izzy = 0;
- player.hard = 0;
- player.doom_guy = 0;
- game(list, 32);
- if (victory)
- {
- player.victories++;
- player.doom_guy++;
- victory = false;
- }
- player.games = 1;
- player.percent = (player.victories / (player.games / 100.0));
- list.push_back(player);
- }
- save(list);
- break;
- default:
- for (unsigned short e = 0; e < list.size(); e++)
- {
- if (list[e].name == player.name)
- {
- g8sch = true;
- game(list, 1);
- if (victory)
- {
- list[e].victories++;
- victory = false;
- }
- list[e].games++;
- list[e].percent = (list[e].victories / (list[e].games / 100.0));
- break;
- }
- }
- if (!g8sch)
- {
- player.victories = 0;
- player.izzy = 0;
- player.hard = 0;
- player.doom_guy = 0;
- game(list, 1);
- if (victory)
- {
- player.victories = 1;
- victory = false;
- }
- player.games = 1;
- player.percent = (player.victories / (player.games / 100.0));
- list.push_back(player);
- }
- save(list);
- break;
- }
- break;
- case 2:
- do
- {
- cout << "Результаты\n";
- do
- {
- cout << "1.Сыграно игр\n2.Побед на сложности 'легко'\n3.Побед на сложности 'не так легко'\n4.Побед на сложности 'ХАРДКОР'\n5.Процент побед.\n6.Выход\n";
- cout << "Выберите ЦИФРУ действия: ";
- cin >> RES_CH;
- cin.ignore(32767, '\n');
- cin.clear();
- 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)
- cout << "Ввод не корректен\n";
- }
- 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);
- switch (RES_CH[0])
- {
- case 49:
- res_ch = 1;
- break;
- case 50:
- res_ch = 2;
- break;
- case 51:
- res_ch = 3;
- break;
- case 52:
- res_ch = 4;
- break;
- case 53:
- res_ch = 5;
- break;
- default:
- res_ch = 6;
- break;
- }
- switch (res_ch)
- {
- case 1:
- if (list.empty())
- cout << "Ещё никто не играл...\n";
- else
- {
- sort(list.begin(), list.end(), compare_games);
- reverse(list.begin(), list.end());
- for (auto& i : list)
- cout << i.name << " : " << i.games << "\n";
- }
- break;
- case 2:
- if (list.empty())
- cout << "Ещё никто не играл...\n";
- else
- {
- sort(list.begin(), list.end(), compare_izzy);
- reverse(list.begin(), list.end());
- for (auto& i : list)
- cout << i.name << " : " << i.izzy << "\n";
- }
- break;
- case 3:
- if (list.empty())
- cout << "Ещё никто не играл...\n";
- else
- {
- sort(list.begin(), list.end(), compare_hard);
- reverse(list.begin(), list.end());
- for (auto& i : list)
- cout << i.name << " : " << i.hard << "\n";
- }
- break;
- case 4:
- if (list.empty())
- cout << "Ещё никто не играл...\n";
- else
- {
- sort(list.begin(), list.end(), compare_doom);
- reverse(list.begin(), list.end());
- for (auto& i : list)
- cout << i.name << " : " << i.hard << "\n";
- }
- break;
- case 5:
- if (list.empty())
- cout << "Ещё никто не играл...\n";
- else
- {
- sort(list.begin(), list.end(), compare_percent);
- reverse(list.begin(), list.end());
- for (auto& i : list)
- {
- int perc = static_cast<int>(round(i.percent));
- cout << i.name << " : " << perc << "%\n";
- }
- }
- break;
- default:
- cout << "Вы точно хотите выйти? Введите YES, если да или что-то другое, если нет.\n";
- cin >> resaw;
- cin.ignore(32767, '\n');
- cin.clear();
- if (resaw != "YES")
- res_ch = 0;
- break;
- }
- }
- while (res_ch != 6);
- break;
- default:
- cout << "Вы точно хотите выйти? Введите YES, если да или что-то другое, если нет.\n";
- cin >> away;
- cin.ignore(32767, '\n');
- cin.clear();
- if (away != "YES")
- choice = 0;
- break;
- }
- }
- while (choice != 3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment