0

MAP (NEED HELP ASAP) please

I’m trying to keep track of the position of a character in a 2d array map. I want a visual representation of the position of a character , I think I’m close to figuring it out, but whenever I enter a movement command, my initial position should return to 1 but it doesn’t. Can anyone help me out with this? Thats what i have so far: #include <iostream> using namespace std; void printBoard(); const int ROW = 5; const int COL = 6; int board[ROW][COL]; int grid[6][5] ; int main() { char hero = 'h'; char direction; //int grid[6][5] = { {0} }; printBoard(); //grid[0][0] = hero; while (1) { // get pos of the hero cout << "Enter a direction" << endl; cin >> direction; //printBoard(); if (direction == 's') { grid[0][1] = hero; printBoard(); } if (direction == 'n') { grid[3][1] = hero; printBoard(); } if (direction == 'e') { grid[1][1] = hero; printBoard(); } } system("pause"); return 0; } void printBoard() { int x, y; for (x = 0; x < 6; x++) { for (y = 0; y < 5; y++) { cout << (grid[x][y] == 0); } cout << endl; } }

14th Mar 2019, 12:49 AM
Tania Sajjad
Tania Sajjad - avatar
6 Respuestas
+ 2
I'm not sure if what I think "returning to initial position" means is what you actually mean, but try doing: if (direction == 's') { grid[0][1] = hero; printBoard(); grid[0][1] = 0; } if (direction == 'n') { grid[3][1] = hero; printBoard(); grid[3][1] = 0; } if (direction == 'e') { grid[1][1] = hero; printBoard(); grid[1][1] = 0; }
14th Mar 2019, 1:05 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
You want to return to initial position after moving, so after printBoard(), you should be wiping the field and reassigning hero to 0,0.
14th Mar 2019, 12:55 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
So as of now, the code doesn't seem to do anything after printBoard(). Do you need help on that or, are you still working on it?
14th Mar 2019, 12:57 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
THANK You soo much that made it a lot easier and a lot better.
14th Mar 2019, 1:12 AM
Tania Sajjad
Tania Sajjad - avatar
0
yes
14th Mar 2019, 12:56 AM
Tania Sajjad
Tania Sajjad - avatar
0
i need help on that too because i m completely lost honestly and thank you soo much for helping
14th Mar 2019, 1:00 AM
Tania Sajjad
Tania Sajjad - avatar