* 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;
    }

Put 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.

Fill the board with *'s. Remove *'s as desired to create a path by replacing a guiven * with a space char.

Replace a space char with an equal sign and a different space char with an i.

Within a loop repeat the following as long as the user wants to play on, and the i isn't moved to the cell with equal sign:

Obtain input as to how to move i and analyze using an if/else statement or, if you know how to use a switch statement, that would be even better.

To move the i up check the value of cell one row up from where the i is.
To move the i to the left check the value of the cell one column to the left of where the i is.
etc.

if the "new cell" is a * or off the board it is an illegal move, don't do anything, other than maybe notify user they can't move there

if the "new cell" is a space, then assign i to the "new cell" and place a space char in the "old cell".
if the "new cell is an equal sign stop the loop

display the board to show the new position of the i

Once the loop is completed, determine if the user won or gave up and display an appropriate message.

thanks, so I got it to work but I have to make a monster, do you have any suggestions on it? How do I make a monster in which the whole thing moves?
Monsters: Perhaps they could take one step towards the user (or even just in any random direction) once every 1-3 turns.

#include <iostream>
using namespace std;


int main()
{
    int maze[4][9];
    const int rows = 20;
    const int columns = 70;
    int Prow;
    int Pcol; 
    char board[rows][columns + 1] = {
        "**                              =====                              **",
        "********************************<   *********************************",
        "*********************************   *********************************",
        "*******************************     *********************************",
        "*******************************     *********************************",
        "**********************************       ****************************",
        "****************************************  ***************************",
        "****************************************     ************************",
        "********************************************  ***********************",
        "*****************************************     ***********************",
        "***************************************    **************************",
        "***********************************     *****************************",
        "**********************************   ********************************",
        "**********************************   ********************************",
        "*********************************    ********************************",
        "************************************    *****************************",
        "*************************************    ****************************",
        "************************************     ****************************",
        "***********************************   *******************************",
        "***                                 i                             ***",

    };
    while (1)
    {
        int Prow = 20;
        int Pcol = 35;

        for (int i = 0; i < 20; i++)
        {

            for (int j = 0; j < 70; j++)
            {

                cout << board[i][j];
                if (board[i][j] == 'i')
                {
                    Prow = i;
                    Pcol = j;
                }
            }
            cout << endl;
        }


        char move;

        cout << "Make your move: w = up, a = left, s = down, d = right ";
        cin >> move;

        if (move == 'w')
        {
            if (board[Prow - 1][Pcol] == ' ')
            {
                board[Prow][Pcol] = ' ';
                board[Prow - 1][Pcol] = 'i';

            }

            else if (board[Prow - 1][Pcol] == '*')
            {
                board[Prow][Pcol] = ' ';
                board[Prow - 1][Pcol] = 'i';
                cout << "You lost!/n";
            }

            else if (board[Prow - 1][Pcol] == '=')
            {
                board[Prow][Pcol] = ' ';
                board[Prow - 1][Pcol] = 'i';
                cout << "You just Won! ";
            }
        }


        if (move == 'a')
        {
            if (board[Prow][Pcol - 1] == ' ')
            {
                board[Prow][Pcol] = ' ';
                board[Prow][Pcol - 1] = 'i';

            }
        }

        if (move == 's')
        {
            if (board[Prow + 1][Pcol] == ' ')
            {
                board[Prow][Pcol] = ' ';
                board[Prow + 1][Pcol] = 'i';

            }
        }

        if (move == 'd')
        {
            if (board[Prow][Pcol + 1] == ' ')
            {
                board[Prow][Pcol] = ' ';
                board[Prow][Pcol + 1] = 'i';

            }
        }
    }

    system("pause");
    return 0;
}

Edited 2 Years Ago by DS9596

This article has been dead for over six months. Start a new discussion instead.