Created
April 4, 2025 18:18
-
-
Save prodevo/e3588953ff2892ba383e0d0a6ac38064 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <iostream> | |
#include <ctime> | |
#include <conio.h> | |
#include "ConsoleApplication5.h" | |
using namespace std; | |
int main() | |
{ | |
int window_settings(); | |
{ | |
srand(time(0)); | |
system("mode con cols=210 lines=70"); | |
system("title Maze"); | |
} | |
// hide standard console cursor | |
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); | |
int cursor_delete(); | |
{ | |
CONSOLE_CURSOR_INFO cci; | |
cci.bVisible = false; | |
cci.dwSize = 100; | |
SetConsoleCursorInfo(h, &cci); | |
} | |
const int width = 75; | |
const int height = 20; | |
int maze[height][width]; | |
enum maze_objects { HALL, WALL, GOLD, VRAG }; | |
enum direction { DOWN = 80, UP = 72, LEFT = 75, RIGHT = 77 }; | |
enum colors { BLUE = 9, RED = 12, YELLOW = 14, DARKGREEN = 2 }; | |
int location_generation(); | |
{ | |
for (int y = 0; y < height; y++) | |
{ | |
for (int x = 0; x < width; x++) | |
{ | |
int generating_walls(); | |
{ | |
int random = rand() % 4; | |
maze[y][x] = random; | |
if (x == 0 || y == 0 || x == width - 1 || y == height - 1) | |
maze[y][x] = WALL; | |
} | |
// enter and exit | |
int generating_exits(); | |
{ | |
if (x == 0 && y == 2 || x == 1 && y == 2 | |
|| x == width - 1 && y == height - 3) | |
maze[y][x] = HALL; | |
} | |
///////////////////////////////////////////////////////// | |
int painting_location(); | |
{ | |
if (maze[y][x] == WALL) | |
{ | |
SetConsoleTextAttribute(h, DARKGREEN); | |
cout << (char)178; | |
} | |
else if (maze[y][x] == GOLD) | |
{ | |
SetConsoleTextAttribute(h, YELLOW); | |
cout << (char)250; | |
} | |
else if (maze[y][x] == VRAG) | |
{ | |
int r = rand() % 100; // 0...99 | |
if (r == 0) | |
{ | |
SetConsoleTextAttribute(h, RED); | |
cout << (char)1; | |
} | |
else | |
{ | |
maze[y][x] = HALL; | |
cout << " "; | |
} | |
} | |
else | |
{ | |
cout << " "; | |
} | |
} | |
} | |
cout << "\n"; | |
} | |
} | |
COORD pers = { 0, 2 }; | |
int player_position(); | |
{ | |
SetConsoleCursorPosition(h, pers); | |
SetConsoleTextAttribute(h, BLUE); | |
cout << (char)1; | |
} | |
while (true) | |
{ | |
int direct = _getch(); | |
if (direct == 224) | |
direct = _getch(); | |
int cursor_set(); | |
{ | |
SetConsoleCursorPosition(h, pers); | |
cout << " "; | |
} | |
int moving_by_x(); | |
{ | |
if (direct == RIGHT && maze[pers.Y][pers.X + 1] != WALL) | |
{ | |
pers.X++; | |
} | |
else if (pers.X > 0 && direct == LEFT && maze[pers.Y][pers.X - 1] != WALL) | |
{ | |
pers.X--; | |
} | |
} | |
int moving_by_y(); | |
{ | |
if (pers.Y > 0 && direct == UP && maze[pers.Y - 1][pers.X] != WALL) | |
{ | |
pers.Y--; | |
} | |
else if (pers.Y > 0 && direct == DOWN && maze[pers.Y + 1][pers.X] != WALL) | |
{ | |
pers.Y++; | |
} | |
} | |
SetConsoleCursorPosition(h, pers); | |
SetConsoleTextAttribute(h, BLUE); | |
cout << (char)1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment