* I have to make a maze with 21 rows and 77 columns, allow some for the user's input and for messages.
* It also has to have A multidimensional array containing the board.
* A function to print the board.
* Find the user's starting location (i.e. the location of the 'i')
* Loop forever, doing the following:
Print the board (using your handy board printing function)
If the character is:
'w': move the 'i' up, if possible
'a': move the 'i' left, if possible
's': move the 'i' down, if possible
'd': move the 'i' right, if possible
* If the square that 'i' is trying to move to does not contain a space:
If the character is an '=', then the user won! Say so, and exit the program (using return 0;).
If the character is a '*', then you probably want to do nothing.
If you were being adventerous, and you included characters for lava and other such dangers, you should handle them accordingly.
So far, I have something like this but I'm not really sure how to make the i move, I did it in a small scale first.
#include <iostream>
using namespace std;
int main()
{
int maze[4][9];
const int rows = 4;
const int columns = 9;
int choice= 9;
char board[rows][columns + 1] = {
"** === **",
"* *",
"* *",
"*** i ***",
};
for (int i = 0; i< 21; i++)
{
for (int j = 0; j < 77; j++)
{
cout << board[i][j];
}
cout << endl;
}
int Prow = 44;
int Pcol = 38;
if (choice == 'w')
{
if(board[Prow][Pcol] == ' ')
{
Prow= Prow + 1;
board[Prow][Pcol] = 'i';
}
cout << "Enter a character " << choice;
}
if (choice == 's')
{
if(board[Prow][Pcol] == ' ')
{
Prow= Prow -1;
board[Prow][Pcol] = 'i';
}
}
system("pause");
return 0;
}
DS9596
0
Junior Poster in Training
Recommended Answers
Jump to PostPut the nested loop to print out the board in a separate function.
When using the smaller board be sure you don't go out of bounds by using indexes relevant for the final board.
The only values the board will hold are *, space char, equal sign and an i.
…
All 3 Replies
DS9596
0
Junior Poster in Training
Lerner
582
Nearly a Posting Maven
DS9596
0
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.