Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This in C++. Please help me write the definitions for the maze.cpp file for question number 1. The definitions need to be written from the

This in C++. Please help me write the definitions for the maze.cpp file for question number 1. The definitions need to be written from the prototypes in the header file below and with the help of the main() code below.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
- Game functions. The game functions are: 0 nextMove( 3 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( 3 or another function. 0 note that previously described checkMaze( ) is also used in the game Assignments 1. . Add the header file maze . hp_p_ 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 Study Floating and Docking Windows ofMSVS describcdhere. As g i you work on the below project, demonstrate to the instructor the / l 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. i 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 1as 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 ' +mazeSizel. The mouse is placed in room a1 (top-left room). The cheese is placed in room a+mazeSizel ,mazeSize (bottom-right room). The 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 ofdiffcrent rooms. That is, if there is a wall rl | 1-2, where rl and r2 are adjacent room coordinates, then there should not be another wall r1 | r2 or r2 | rl. No other checks. such as a check whether the maze is navigable, need to be performed. On 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)own, (l)eft, (r)ight. or (qjuit. 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. Maze data structures and function description. The data structures and functions needed to implement the game are declared in this header le. The header file defines two structures: 0 Room stores the number and letter coordinates ofa room: 0 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: 0 initialization functions that place the walls in the male. The major functions among the initialization functions are pickWall( ) and build( ) Function pickWall( ) selects a random pair ofadjaeent 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(variable} to indicate if the adjacent room is selected, initialize it to "not selected" while adjacent room is not selected select a random direction (an integer variable indicating direction would work) if 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 - 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 selected pair of 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 pickWallt) to get a new arbitrary placed wall invoke checkMazet) 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: T0 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. Altcmatively, you can add an integer to a character as done in ms example. Hint 2: The logic 0fclearWalls( ), 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: 0 printRoom( ) prints the location ot'a single room 0 printPair( ) prints the location ofa pair of rooms that are separated by the wall, USCSprintRoom(} / / 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 HPP

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions