#include <iostream>
#include <vector>
#include <conio.h> // для _getch() на Windows
using namespace std;
// Символы лабиринта
const char WALL = '#';
const char PATH = ' ';
const char PLAYER = '@';
const char EXIT = 'E';
// Карта лабиринта (1 = стена, 0 = путь)
vector<string> maze = {
"####################",
"# # # # #",
"# # # ## # ### # # #",
"# # # # # # # #",
"# ##### ##### # # # #",
"# # # # # #",
"####### # # # # ### #",
"# # # # # # # #",
"# ### # # ####### # #",
"# # # # # #",
"# # ######### # ### #",
"# # # E",
"####################"
};
int playerX = 1, playerY = 1; // стартовая позиция игрока
void draw() {
system("cls"); // очистка экрана (Windows)
// На Linux/Mac замените на: system("clear");
cout << "=== ЛАБИРИНТ ===\n";
cout << "Управление: W A S D | Цель: найти выход [E]\n\n";
for (int y = 0; y < (int)maze.size(); y++) {
for (int x = 0; x < (int)maze[y].size(); x++) {
if (x == playerX && y == playerY)
cout << PLAYER;
else
cout << maze[y][x];
}
cout << "\n";
}
}
bool canMove(int x, int y) {
if (y < 0 || y >= (int)maze.size()) return false;
if (x < 0 || x >= (int)maze[y].size()) return false;
return maze[y][x] != WALL;
}
int main() {
while (true) {
draw();
// Проверка победы
if (maze[playerY][playerX] == EXIT) {
cout << "\n *** ПОЗДРАВЛЯЕМ! Вы нашли выход! ***\n";
break;
}
char key = _getch(); // читаем нажатие без Enter
// На Linux/Mac используйте: char key = getchar();
int nx = playerX, ny = playerY;
if (key == 'w' || key == 'W') ny--;
else if (key == 's' || key == 'S') ny++;
else if (key == 'a' || key == 'A') nx--;
else if (key == 'd' || key == 'D') nx++;
else if (key == 'q' || key == 'Q') break; // выход из игры
if (canMove(nx, ny)) {
playerX = nx;
playerY = ny;
}
}
return 0;
}