Multidimensional arrays

I need help in developing this array which will show my map and shows the current position im in with a 0 or something and i can move around by typing N S E W and make it where I cannot stop on the X spots since there solid. So far i got it to make the map and display it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const int rows = 10;
	const int columns = 10;
	char board [rows][columns] =
	{
		{'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'},
		{' ', ' ', 'X', ' ', ' ', ' ', ' ', 'X', 'X', 'X'},
		{'X', ' ', 'X', ' ', 'X', 'X', ' ', ' ', 'X', 'X'},
		{'X', ' ', 'X', ' ', 'X', 'X', 'X', ' ', 'X', 'X'},
		{'X', ' ', 'X', ' ', ' ', 'X', 'X', ' ', 'X', 'X'},
		{'X', ' ', 'X', 'X', ' ', 'X', ' ', ' ', 'X', 'X'},
		{'X', ' ', 'X', 'X', ' ', 'X', ' ', 'X', 'X', 'X'},
		{'X', ' ', ' ', 'X', ' ', 'X', ' ', 'X', 'X', 'X'},
		{'X', 'X', ' ', ' ', ' ', 'X', ' ', ' ', ' ', ' '},
		{'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'}
	};
		for (int i = 0; i < rows; i++)
		{
			for (int j = 0; j < columns; j++)
			{
				cout << board[i][j];
			}
			cout << endl;
		}
First you need to make in input loop to read input from the user. Depending on the direction they input, add/subtract one from the current row/column and check to see that it is in-bounds and not an X. If so, move them there.
Been trying to do that all day, i always hit a wall.
1
2
3
4
5
6
7
8
9
                 for (int i = 0; i < rows; i++)
		{
			for (int j = 0; j < columns; j++)
			{
                                //u gutta make variables for x and y or sumfing
                                if(board[y][x-1] != 'X') //if left is pressed
                                         // do something unbelievable
			}
		}
Last edited on
I have tried that. I have a structure named character which has xCoord and yCoord so its character.xCoord etc. I have tried making it then redisplaying the map on my movement etc, i cannot get it to work.
Topic archived. No new replies allowed.