Question: This is in C++. Please help me code the definitions (maze.cpp) in question 1. maze.hpp file: testMaze.cpp file: / / tests maze function implementation #include

This is in C++. Please help me code the definitions (maze.cpp) in question 1.

maze.hpp file:

testMaze.cpp file:

This is in C++. Please help me code the definitions (maze.cpp) inquestion 1.maze.hpp file:testMaze.cpp file: / / tests maze function implementation #include "maze.hpp" #include using std: :cout; using std: :cin; using std: : endl;int main( ) { / / srand( time (nullptr) ) ; // random seed srand ( 1) ; / / fixed seed 11/ / first part: checking Room functions 1 1 Room myRoom; // create a room myRoom. x = 2; myRoom.y = 'b'; /

/ / tests maze function implementation #include "maze. hpp" #include using std: :cout; using std: :cin; using std: : endl; int main( ) { / / srand( time (nullptr) ) ; / / random seed srand ( 1) ; / / fixed seed 11 / / first part: checking Room functions 1 1 Room myRoom; / / create a room myRoom. x = 2; myRoom.y = 'b'; / / print Room cout #include #ifndef MAZE HPP #define MAZE_HPP const int mazeSize = 4; // maze is mazeSize * mazeSize const int numWalls = 8; // number of internal walls 1/ / / data structures definitions 1/ struct Room { int x; / / 1 through mazeSize char y; // 'a' through mazeSize const Room startRoom = { 1, 'a' ); const Room cheeseRoom = { mazeSize, 'a" + mazeSize-1 }; / / internal wall or next move struct RoomPair{ Room one; Room two; 11 / / initialization functions void clearWalls (RoomPair [ ]); / / places every RoomPair to connect two non-existing rooms / / where x-coordinate is -1 / / and y-coordinate is (a star) to signify / / that the wall is not built vetnot built yet const RoomPair pickWall ( ); // generates a random wall bool matchRoom (const Rooms, const Rooms ) ; / / returns true if the two rooms are the same bool matchPair (const RoomPairs, const RoomPairs) ; / / returns true if two pairs of // adjacent rooms are the same, / / returns false otherwise, / / uses matchRoom( ) / / note that rl|r2 matches r2|rl int checkMaze (const RoomPair [ ], const RoomPair 6); // returns the index of 11 element of the array of RoomPair (walls) that 11 separates RoomPair, returns -1 if none do / / uses matchPair ( ) void build (RoomPair [ ]) ; / / places internal walls in random locations of the maze 11 // display functions 1/ void printRoom (const Rooms ); / / prints the location of the room void printPair (const RoomPairs ); // prints the locations of the adjacent rooms void printMaze (const RoomPair [ ]); / / prints the locations of all the internal walls of the maze // uses printPair 1 1 / / game functions const Room nextMove (const Rooms currentRoom); // asks the user for the room to move // adjacent to currentRoom // note that checkMaze ( ) and matchRoom( ) are also used in the game #endif / / MAZE HPPSou 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. x lVIaze navigation. You are to help a mouse to nd cheese in a maze. The maze is a square mazeSize*mazeSlze grid of rooms Each room has two coordinates The horizontal coordinate is an integer ii [7 number ranging from J to mazeSiZe. The Vertical coordinate is a letter ranging from 'a' to 'a ' tmazeSiZEsl. The mouse is placed in room a1 (topsleft room). The cheese is placed. in room ' atmazesizEsljma zeSize (bonoinsright room). Tile maze has walls that separate some pairs of adjacent rooms. Your program should randomly place numwalls in the maze. Two walls must separate a pair of different rooms. That is. if there is a wall rl l r2. where r1 and r2 are adjacent room coordinates. then there should not be another wall rl l r2 or er r1. sec, l s, No other checks. such as a check whether the maze is navigable. need to be performed. Oil user request. the program prints the 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)ow (lleft. (r)ight. or (q)uit The program should accept a single character. 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 retains 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. l'rlaze 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: - Room stores the number and letter coordinates of a room: - RoomPair stores two adjacent rooms. That is. one room may be up. down. left or right from the other. The maze is represented by an array of RoomPair. This array is first initialized and then used in the game. The functions are separated into three groups: - Initialization functions that place the walls in the maze. The major nictions among the initialization functions are pic knallt) and bui1d() Function pickwallo selects a random pair ofadiacent rooms to be separated by a wall. The pseudocode for the function is as follows: select a random location For the first room pick a flag(variah1e) to indicate it the adjacent room is selected, initialize it to \"not selected" uhile adjacent room is not selected select a random direction (an integer variable indicating direction would work) it direction is up and it is not outside the maze the adjacent room coorindates is set to the same column as first room and row a 1 mark adjacent room as selected else if the direction is left and it is not outside the maze the adjacent room coordinates is set to same row as First room and column ,1 mark adjacent room as selected return se1ected pair or rooms Function build() accepts an array of RoomPair by reference and initializes wall locations. It uses the other two initialization functions: pickWall() and checkMaze() The pseudocode for build() is as follows: declare a variable that stores the number of already built walls, initially zero, this variable is to be used as an index in the array of walls loop until all required walls are built invoke pickWall() to get a new arbitrary placed wall invoke checkMaze() to verify whether this wall is already built if this wall not not built then build the this wall by copying this wall into the array increment the number of built walls Hint 1: To randomly assign a character coordinate (from 'a' to mazesize) for the location in pickWall (), randomly select a number from 1 to mazeSize and then use a switch to select the appropriate letter. Alternatively, you can add an integer to a character as done in this example. Hint 2: The logic of clearWalls (), checkMaze() and build() is very similar to the logic of lottery number selection functions in one of the previous labs. . Functions that display maze configuration. After the walls are built, the user is prompted if he would like to see the wall locations (hint: use this option for debugging). The printout functions are: printRoom( ) prints the location of a single room printPair () prints the location of a pair of rooms that are separated by the wall, uses printRoom( ) printMaze () lists all the walls, uses printPair () The output of this function might look like this: a2 b2, c3 c2, d2| c2, c4| c3, a4|a3, d3|d4 d3|c3, alla2 Game functions. The game functions are: nextMove ( ) accepts the current location, asks the user for the move: up, down, left and right and returns the room where the user wants to move the mouse. This function does not check whether this move is possible. This check is done in main ( ) or another function. o note that previously described checkMaze ( ) is also used in the game1. Test, Create a protect titled Laszest Add the header file maze. hgg described above to your protect. Add this file testMaze. cp_p_ to your project as well. Implement the functions prototyped in maze. hpp file and invoked in testMaze . (pp. 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 rst. Then. uncominent the second portion of code and implement those functions Once your project works correctly With a_ll code of testMaze . (pp unconnnented. submit your protect. 2. Game. Create a project Titled Labiame. Use maze.hpp. maze . [pp from the test assignment above: add game . :pp that contains main() . invokes the game functions declared in maze.hpp and implements the maze navigation game. The program should work as follows Fiist. 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]: while the mouse is not in the Cheese room and user wants to Continue the game print turrent mouse location ask the user for the next mouse move if the move takes the mouse outside the maze er the current mouse location and the next is separated by a wall then repent ue11 do not move the mouse else move mouse to new location report ending of the game

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!