closed account (DzTDjE8b)
Wrong forum
Last edited on
Right off the bat, your displayGameState() function doesn't do what you think it does. At least not if you think it does what it's named.

Also, your changeGameState() function doesn't look like it's going to do very well, because if the player presses 's', which I assume is the down key in your game, instead of moving the token down one, it will move it two past the end of the array vertically. Similarly, the a will set the character's token to the last element in the array horizontally. In addition, I don't know why you have a system("Pause"); in every one of those statements, but you should probably avoid any system() calls until you know why it's dangerous, and not just generally, but specifics.
closed account (DzTDjE8b)
So I got my logic messed up for the movement locations of (wasd), crud..

I thought displayGameState does what it said? I know we have initGame which initiates the game but only concern at the moment is just getting the button press to be reflected in the array so I can add rules afterwards.

Yeah, I didn't know system("Pause") is a bad idea. I was pausing it to see if the array changed after the positions of [x][y] were changed and if it displayed it.
"Please kind of guide me into making my board reflect the players position from one function to another."

I think this article may be what you're looking for?

You might also want to check that the user is not trying to input a position which does not exist. For example, if posX == 0 and I press 'a', posX will be -1.
The logic of moving through the game board is correct in your displayGameState() function, but this line:
board[row][col] = ' ';
doesn't display anything. It just sets the contents of every element to be empty.

In the changeGameState() function, all you need to do for let's say 'w':
if(!(posX > 0)){
        cout << "You can't go that way!" << endl;
board[posX][posY] = ' ';
posX -= 1;
board[posX][posY] = 'X';

That will check to see if you're on the upper edge of the array, and if not, then it'll move the character token up one.

Keep in mind that this code I've put up hasn't been checked for array directional accuracy. That's on you. If the variables are backwards, then you're going to have them moving in odd directions when they press keys.
Topic archived. No new replies allowed.