text based RPG map (need help ASAP ) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

text based RPG map (need help ASAP )

I am trying to keep changing the position of the hero but what this program is doing it just changing the position of the hero by (0,0) where as when a user enters south it should go to a new position and the program does that, but when i am entering now it is increment for (0,0) where as I want my program to be incrementing from the south position coordinates. thank you #include <iostream> #include <string> using namespace std; void printBoard(); //void intro(); const int ROW = 5; const int COL = 6; int board[ROW][COL]; char grid[6][5]; int main() { int herox = 0; int heroy = 0; string directionX = ""; string directionY = ""; int heroX = herox; // herox is the initaial position int heroY = heroy; // heroy is the inital postion and heroX is the postion that is being moved char hero = 'h'; string direction; grid[0][0] = hero; printBoard(); grid[0][0] = 0; while (1) { // get pos of the hero cout << "Enter a direction" << endl; cin >> direction; //printBoard(); if (direction == "s") { grid[heroX + 1][heroY] = hero; printBoard(); grid[heroX +1][heroY] = 0; } if (direction == "n") { grid[heroX][heroY + 1]= hero; printBoard(); grid[heroX][heroY+1] = 0; } if (direction == "e") { grid[heroX + 1][heroY] = hero; printBoard(); grid[heroX + 1][heroY] = 0; } } system("pause"); return 0; } void printBoard() { char x, y; for (x = 0; x < 6; x++) { for (y = 0; y < 5; y++) { cout << (grid[x][y] == 'h'); } cout << endl; } }

14th Mar 2019, 10:43 PM
Tania Sajjad
Tania Sajjad - avatar
1 Answer
+ 3
Hi, the problem seems to be that you don't increase the coordinates. You just change the value of the matrix, but not the x and y coordinates. I hope this hint helps.
26th Apr 2019, 4:31 PM
Siegfried Petersen
Siegfried Petersen - avatar