### trying to make a player go around a map and give you certain phrases when you land on specific spots

The problem that im having is that when the player [P] goes over any of the map tiles it doesnt register properly.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213`` ``````#include #include #include using namespace std; //Globals const int rows = 8; const int columns = 8; char gameBoard[rows][columns]; bool dismount = false; bool gameover = false; void drawBoard(int, int); void changePosition(int&, int&, int); int main() { srand(time(NULL)); //DONT CHANGE THESE char spacesToMove = 0; char spacesToUse = spacesToMove; int positionX = 0; int positionY = 0; int choice; cout << "make your choice" << endl; cout << "press 1 to start" << endl; cout << "Press 2 to load" << endl; cin >> choice; if (choice == 1) { cout << "Hello and welcome to the game" << endl; cout << "_____________________________" << endl; drawBoard(positionX, positionY); cout << "_____________________________" << endl; while (gameover == false) { cout << "If you would like to make a move press 1" << endl; cout << "press 2 if you would like to dismount" << endl; cin >> choice; if (choice == 1) { spacesToMove = rand() % 6; dismount = false; if (spacesToMove > 0) { changePosition(positionX, positionY, spacesToMove); cout << "_____________________________" << endl; drawBoard(positionX, positionY); cout << "_____________________________" << endl; } } if (choice == 2) { cout << "You dismount."; dismount = true; if (gameBoard[positionX][positionY] == gameBoard[0][7] || gameBoard[7][7]) { cout << "Cathedral"; } else if (gameBoard[positionX][positionY] == gameBoard[3][7] || gameBoard[7][0]) { cout << "Graveyard"; } else if (gameBoard[positionX][positionY] == gameBoard[0][4] || gameBoard[7][4]) { cout << "Well Of Reflection"; } else if (gameBoard[positionX][positionY] == gameBoard[3][0]) { cout << "Dungeon Exit"; } else { int random1; random1 = rand() % 4; if (random1 == 1) { cout << " its 1" << endl; } else if (random1 == 2) { cout << " its 2" << endl; } else if (random1 == 3) { cout << " its 3" << endl; } else if (random1 == 0) { cout << " its 0" << endl; } } } } return 0; } if (choice == 2) { cout << "LOADING....." << endl; } return 0; } void changePosition(int& positionX, int& positionY, int spacesToMove) { while (spacesToMove > 0) { //position is in the first row and moving right if (spacesToMove > 0 && positionX == 0 && positionY != 7) { if (positionY + spacesToMove >= columns) { spacesToMove = spacesToMove - (columns - (positionY + 1)); positionY = 7; } else { positionY = positionY + spacesToMove; spacesToMove = 0; } } //position is last column and moving down if (spacesToMove > 0 && positionY == 7 && positionX != 7) { if (positionX + spacesToMove >= rows) { spacesToMove = spacesToMove - (rows - (positionX + 1)); positionX = 7; } else { positionX = positionX + spacesToMove; spacesToMove = 0; } } //position is on last row and moving left if (spacesToMove > 0 && positionX == 7 && positionY != 0) { if ((columns - (positionY + 1)) + spacesToMove >= columns) { spacesToMove = spacesToMove - (positionY); positionY = 0; } else { positionY = positionY - spacesToMove; spacesToMove = 0; } } //position is on first column and moving up if (spacesToMove > 0 && positionY == 0 && positionX != 0) { if ((rows - (positionX + 1)) + spacesToMove >= rows) { spacesToMove = spacesToMove - (positionX); positionX = 0; } else { positionX = positionX - spacesToMove; spacesToMove = 0; } } } //end of while } void drawBoard(int positionX, int positionY) { //Use two loops to draw the game board. If the passed in player position matches //a position, place a P on it. for (int x = 0; x < rows; x++) { for (int y = 0; y < columns; y++) { //The board representation will be drawn with * only if is the outer paths //of the 2D Array if (y == 0 || y == 7 || x == 0 || x == 7) { if (positionX == x && positionY == y) { gameBoard[x][y] = 'P'; } else { gameBoard[x][y] = '*'; } if (gameBoard[x][y] != 'P') { gameBoard[0][0] = 'S'; gameBoard[0][4] = 'W'; gameBoard[0][7] = 'C'; gameBoard[3][7] = 'G'; gameBoard[7][7] = 'C'; gameBoard[7][4] = 'W'; gameBoard[7][0] = 'G'; gameBoard[3][0] = 'E'; } cout << setw(2) << gameBoard[x][y]; } else { cout << setw(2) << " "; } } cout << endl; } }``````
Last edited on
> if (gameBoard[positionX][positionY] == gameBoard[0][7] || gameBoard[7][7])
This isn't how you compare one position with a set of possible positions.

> if (y == 0 || y == 7 || x == 0 || x == 7)
Compare with this statement which is expressed correctly.

> gameBoard[0][0] = 'S';
You should be doing this once.
Not for every single position on the board where the player isn't.
All this should be in an initialiseBoard function you call once.
Topic archived. No new replies allowed.