I need some help on first 2D array game. To make this game I just took a simple approach making a drawing function that draws the array, and a function that sets my array to default values. Then check for arrow keys pressed then set player new position, clear screen and redraw the array. My program works pretty much fine expect for 2 problems. Heres a bit of my code.
int keys;
do
{
if(keys=_getch()==72) // Up key
{
firstmap(map); // set all values of the array back to default
currenty = currenty - 1;
map[currenty][currentx] = "*"; // sets player new position
system("CLS"); // clear screen
drawmap(map); // redraws new array with new player position
}
if(keys=_getch()==75) // Left Key
{
firstmap(map);
currentx = currentx - 1;
map[currenty][currentx] = "*";
system("CLS");
drawmap(map);
}
if(keys=_getch()==77) // Right key
{
firstmap(map);
currentx = currentx + 1;
map[currenty][currentx] = "*";
system("CLS");
drawmap(map);
}
if(keys=_getch()==80) // down key
{
firstmap(map);
currenty = currenty + 1;
map[currenty][currentx] = "*";
system("CLS");
drawmap(map);
}
}while(map[3][4]!="*");
When my program enters the loop only the last if statement will work. For example in my code above my program will run flawlessly for the down key but not for the rest of the keys. If I switch the last if statement to the up key it will work fine for the up key nothing else(same for the rest of the keys). As well my second question is how come I have to press the button twice in order for it to work.