Okay, this is a the code for refreshing a map(2D array) and printing it to the console, and taking input from the keyboard on where you want your character(X) to move. Something I have been trying to figure out is getting the code to detect if you have hit a wall, (A | or - in the array). And then, if you have, reverting your character back to where you were before you tried to walk onto the wall. My problem is, when I hit a wall it will start looping the MapRefresh() function infinitely. that's all I can really say, considering since it runs there wouldn't be any error output. It just doesn't run the way I'd like it too.
//Main Game Loop
while(true)
{
cin >> Move;
Hit:
MapRefresh();
if(Hit==true)
{
Hit=false;
goto Hit;
}
//Main loop end
}
I know, I know, there are some things here most programmers would not agree with, (IE Goto's), but I am not planning to keep these, and will replace then at some point. Also, I don't think this is really necessary, but here are all of the declarations at the beggining.
And your goto label has the same name as your variable
When you hit a wall, you are asking for display the map again.
In your display you make the move again. Display only should display the map.
You hit the wall, again.
When you hit a wall, you are asking for display the map again.
Separate the logic a little:
Check if the move is valid, correct if necessary, display the map and ask for input (no need for the inner loop)
I had thought by adding the if statement with the Hit variable and then it setting itself back to false wouldn't cause it to loop. The PosX and Y variables are supposed to keep a sort of history of your last move, and then when you hit a wall, it sets the CoordY and X to the PosX and Y to reset the move, therefore putting you in the place you were before the wall and then breaking the past the goto if, since it set Hit back to false, and allow the program to receive input again. Embarrassed to say, I think I am having trouble reading my own code. So I don't think I really understand what to move where, and what to remove.... I really need to learn to write this stuff better.
why not put the code for moving the character into a function, and do the checking in there, rather than having to revert to the old position if you're on a wall