So I got a little maze game over here, kept very simple. But how is it possible, that I can call a function or do something else when the Player "O" reached a specific point inside the maze ? Let's say he gets to the lower right corner, immediately after him arriving there the screen shall be cleared for example.
#include<iostream>
#include<windows.h>
#include<conio.h>
using namespace std;
char map[20][40] = {
"#######################################",
start -->"#O X XXXXX XX #",
"# X XX XXXX XXX#",
"# XXXXXXXXXXXXX XXXXXXXX XX #",
"# XX XXX XXXXX #",
"# XXXX XXX XXXX X XX X #",
"# X XXXX X X X XX X #",
"# XX X X X X X XX X X #",
"# XX X X X X XX X X #",
"# XX X X XX XXXXXXX X #",
"# X XXXXX XXXXXX #",
"#X X X X X X XXXXX X #",
"#X X XXX X X X XXXXX X X #",
"#X X X X XXXX X X #",
"# X XX X XXXX X XX X X #",
"# XXXXXX X X X XX #",
"# X X XXXX X XXXX#",
"# XXXXXXXX X X X z#", //<--where the O arrives
"#######################################"
};
int x = 1, y = 1;
bool game_running = true;
int main()
{
while(game_running == true)
{
HANDLE hStdout;
COORD destCoord;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
//position cursor at start of window
destCoord.X = 0;
destCoord.Y = 0;
SetConsoleCursorPosition(hStdout, destCoord);
Sleep(100);
for(int display = 0; display < 20; display++)
{
cout<<map[display]<<endl;
}
if(GetAsyncKeyState(VK_DOWN))
{
int y2 = y + 1;
if(map[y2][x] == ' ')
{
map[y][x] = ' ';
y++;
map[y2][x] = 'O';
}
}
if(GetAsyncKeyState(VK_UP))
{
int y2 = y - 1;
if(map[y2][x] == ' ')
{
map[y][x] = ' ';
y--;
map[y2][x] = 'O';
}
}
if(GetAsyncKeyState(VK_RIGHT))
{
int x2 = x + 1;
if(map[y][x2] == ' ')
{
map[y][x] = ' ';
x++;
map[y][x] = 'O';
}
}
if(GetAsyncKeyState(VK_LEFT))
{
int x2 = x - 1;
if(map[y][x2] == ' ')
{
map[y][x] = ' ';
x--;
map[y][x] = 'O';
}
}
if(GetAsyncKeyState(VK_ESCAPE))
{
game_running = false;
}
}
system("pause>nul");
cout<<"GAME OVER"<<endl;
return 0;
}