Maze with Structures

Introduction

Study Floating and Docking Windows of MSVS described here. As you work on the below project, demonstrate to the instructor the usage of this feature.

You are to program a maze navigation game. The assignment is broken into two parts. The below game and header file description applies to both parts.

Maze navigation. You are to help a mouse to find cheese in a maze. The maze is a square mazeSize*mazeSize grid of rooms. Each room has two coordinates. The horizontal coordinate is an integer number ranging from 1 to mazeSize. The vertical coordinate is a letter ranging from 'a' to 'a'+mazeSize-1 (note that in C++ you could add an integer to a character as done in this example.)

The mouse is placed in room a1 (top-left room). The cheese is placed in room a+mazeSize-1,mazeSize (bottom-right room). Room r1 is adjacent to room r2, if r1 is to the left, right, up or down from room r2. Diagonal rooms are not considered adjacent. A wall prevents the mouse from moving to an adjacent room.

Your program should randomly place numWalls in the maze. A wall must separate a pair of adjacent rooms. Note that if there is a wall r1|r2, where r1 and r2 are adjacent room coordinates, then there should not be another wall r1|r2 or r2|r1. No other checks, such as a check whether the maze is navigable, need to be performed. On user request, the program should print wall locations.

The game proceeds as follows. The program prints the current mouse room and asks the user for the mouse's next move: (u)p, (d)own, (l)eft, (r)ight, or (q)uit. The program should accept a single character signifying the move. If the move takes the mouse outside the maze or there is a wall between the current mouse room and the next, then the program prints wall and keeps the mouse in the same room. Otherwise, it moves the mouse to the new location and the game continues. The check whether the mouse already visited the room is not needed. The game proceeds until the mouse reaches the cheese room or the user quits the game.

Maze data structures and function description. The data structures and functions needed to implement the game are declared in this header file. The header file defines two structures:

The functions are separated into three groups:

Assignments

  1. Test. Create a project titled Lab8_Test. Add the header file maze.hpp described above to your project. Add this file testMaze.cpp to your project as well. Implement the functions prototyped in maze.hpp file and invoked in testMaze.cpp. Place these function definitions in maze.cpp

    Note that, as shown, portions of the file are commented out. This is to encourage incremental program development. You need to implement the functions that are not commented out first. Then, uncomment the second portion of code and implement those functions. Once your project works correctly with all code of testMaze.cpp uncommented, submit your project.

  2. Game. Create a project titled Lab8_Game. Use maze.hpp, maze.cpp from the test assignment above; add game.cpp that contains main() , invokes the game functions declared in maze.hpp and implements the maze navigation game. The program should work as follows. First, the walls of the maze are built. Second, the user is asked if he wants to see them. The game starts after that. Below is the pseudocode of the game (to be implemented in main() or a dedicated function):
        populate the maze by invoking build() on it
        declare the room to keep the current mouse location, place the mouse
             in the top-left corner
        prompt the user if she wants to see the maze wall positions printed
        loop while the current mouse location is not the finish room and the user
             wants to continue the game (the selected room is not the -1*)
             inside the loop
                  print the current (mouse) room
                  on the basis of the current room, invoke nextMove() get the
                             next room from the user,
                  form a roomPair out of current room and next room to indicate the next move
                  invoke checkMaze() to see if this move is possible
                  if yes
                       move the mouse by updating the current room
                  if not
                      report a wall
        report ending of the game
        
    Here is an example game dialogue (user input is shown in bold):
    Show walls? [y/n]: y
    d2|d3, c3|d3, b4|a4, a2|a1, c3|c2, c1|c2, b1|c1, b4|b3
    
    Current room: a1
    Next move [u/d/l/r/q]: u
    wall
    
    Current Room: a1
    Next move [u/d/l/r/q]: r
    wall
    
    Current room: a1
    Next move [u/d/l/r/q]: d
    
    Current room: a2
    Next move [u/d/l/r/q]: l
    ...
    

Milestone: implement room and wall functions (first and second part of the testMaze.cpp file).

Make sure your programs adhere to proper programming style. Submit your projects to the subversion repository. Do not forget to verify your submission on the web.