So i'm making an ASCII rogue game, and it's in C++ coded in Visual Studio 2010. There are boundaries, and there is an @ sign (the player). You can move in all directions (up,left,down,right). You cannot pass the boundaries though, because they're boundaries :I
The problem is, the player moves normally, only one space, when moving up or left; but when he moves down or right, he goes all the way to the bottom of the screen, or to to the right of the screen, without passing the boundaries thankfully. I only want him to move one space right and down like he does when moving up or left. I don't know how to fix this, so can some C++ coders help me?
#include <iostream>
#include <Windows.h>
#include <ctime>
using namespace std;
char Map[10][20] = {"###################",
"# #",
"# #",
"# #",
"# #",
"# #",
"# @ #",
"# #",
"# #",
"###################"};
bool running = true;
int gametick = 100;
int main() {
while(running) {
system("cls");
for(int i = 0; i < 10; i ++) {
cout << Map[i] << endl;
}
for(int y = 0; y < 10; y ++) {
for(int x = 0; x < 20; x++) {
switch(Map[y][x]) {
case '@':
if(GetAsyncKeyState(VK_UP)) {
if(Map[y-1][x] != '#' && Map[y-1][x] != '%') {
Map[y][x] = ' ';
Map[y-1][x] = '@';
}
}
else if(GetAsyncKeyState(VK_LEFT)) {
if(Map[y][x-1] != '#' && Map[y][x-1] != '%') {
Map[y][x] = ' ';
Map[y][x-1] = '@';
}
}
else if(GetAsyncKeyState(VK_DOWN)) {
if(Map[y+1][x] != '#' && Map[y+1][x] != '%') {
Map[y][x] = ' ';
Map[y+1][x] = '@';
}
}
else if(GetAsyncKeyState(VK_RIGHT)) {
if(Map[y][x+1] != '#' && Map[y][x+1] != '%') {
Map[y][x] = ' ';
Map[y][x+1] = '@';
}
}
}
}
}
Sleep(gametick);
}
}