#include "pch.h" #include #include #include #include #include using namespace std; string m[40][100]; int x = 47; int y = 20; int hx = 51; int hy = 20; void delhv() { if (m[hy][hx - 1] == "0") { m[hy][hx] = "."; hx -= 1; return; } if (m[hy][hx + 1] == "0"){ m[hy][hx] = "."; hx += 1; return; } if (m[hy - 1][hx] == "0") { m[hy][hx] = "."; hy -= 1; } if (m[hy + 1][hx] == "0"){ m[hy][hx] = "."; hy += 1; return; } } void pr() { for (int i = 0; i < 40; i++) //переключение по строкам { for (int j = 0; j < 100; j++)// переключение по столбцам cout << m[i][j]; cout << endl; } } void kon() { system("cls"); for (int i = 0; i < 40; i++) //переключение по строкам { for (int j = 0; j < 100; j++)// переключение по столбцам m[i][j] = "."; } int l = 0; string k = "The end!"; for (int c = 0; c < 8; c++) { m[20][46+c] = k[l]; cout << k[l]; l += 1; // system("cls"); // pr(); } pr(); Sleep(3000); exit(0); } void lef() { if ((m[y + 1][x] == "0") or (y + 1 > 40)) kon(); else { delhv(); system("cls"); y += 1; m[y][x] = "0"; pr(); } } void up() { if ((m[y - 1][x] == "0") or (y - 1 < 0)) kon(); else { delhv(); system("cls"); y -= 1; m[y][x] = "0"; pr(); } } void down() { if ((m[y][x - 1] == "0") or (x - 1 < 0)) kon(); else { delhv(); system("cls"); x -= 1; m[y][x] = "0"; pr(); } } void rig() { system("cls"); if ((m[y][x + 1] == "0") or (x + 1 > 100)) kon(); else { delhv(); x += 1; m[y][x] = "0"; pr(); } } int main(int argc, char* argv[]) { setlocale(0, "rus"); char symbol = _getch(); for (int i = 0; i < 40; i++) //переключение по строкам { for (int j = 0; j < 100; j++)// переключение по столбцам m[i][j] = "."; } m[20][50] = "0"; m[20][51] = "0"; m[20][49] = "0"; m[20][48] = "0"; m[20][47] = "0"; pr(); while ((symbol = _getch())) { switch (symbol) { case 72: up(); break; case 75: down(); break; case 77: rig(); break; case 80: lef(); break; default: break; } } return 0; }