Created
May 15, 2025 13:23
-
-
Save fantom44ik/d827961f86ebf6e0cd472a04be9da8b7 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 <iostream> | |
#include "labyrinth.h" | |
using namespace std; | |
int main() { | |
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); | |
srand(time(0)); | |
rand(); | |
system("title Bomberman"); | |
hideCursor(h); | |
int map[HEIGHT][WIDTH] = {}; | |
generateMap(map); | |
drawMap(h, map); | |
COORD hero = { 0, 2 }; | |
drawHero(h, hero); | |
int coins_collected = 0; | |
updateCoinsInfo(h, coins_collected); | |
while (true) { | |
int code = _getch(); | |
if (code == 224) code = _getch(); | |
COORD old_position = hero; | |
bool has_been_moved = false; | |
switch (code) { | |
case Key::LEFT: | |
if (hero.X > 0 && map[hero.Y][hero.X - 1] != GameObject::WALL) { | |
has_been_moved = true; | |
hero.X--; | |
} | |
break; | |
case Key::RIGHT: | |
if (map[hero.Y][hero.X + 1] != GameObject::WALL) { | |
has_been_moved = true; | |
hero.X++; | |
} | |
break; | |
case Key::UP: | |
if (map[hero.Y - 1][hero.X] != GameObject::WALL) { | |
has_been_moved = true; | |
hero.Y--; | |
} | |
break; | |
case Key::DOWN: | |
if (map[hero.Y + 1][hero.X] != GameObject::WALL) { | |
has_been_moved = true; | |
hero.Y++; | |
} | |
break; | |
} | |
if (has_been_moved) { | |
SetConsoleCursorPosition(h, old_position); | |
SetConsoleTextAttribute(h, BLACK); | |
cout << " "; | |
drawHero(h, hero); | |
} | |
if (map[hero.Y][hero.X] == COIN) { | |
coins_collected++; | |
map[hero.Y][hero.X] = HALL; | |
updateCoinsInfo(h, coins_collected); | |
} | |
if (map[hero.Y][hero.X] == ENEMY) { | |
cout << "ENEMY"; | |
} | |
} | |
Sleep(INFINITE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment