Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1: Rooms Download the attached room.h header file. A room will be the basic object for our maze game. A room can have 4

Part 1: Rooms

Download the attached room.h header file. A room will be the basic object for our maze game. A room can have 4 doors. Each door points in one direction, north, south, east, or west. If a door can be taken, then we will store a pointer to which room the door connects to. If the pointer is set to null, that means that the door is "locked." We could also imagine that the null doors are just walls.

We want the player to be able to tell what room they are in. Each room with have a unique description. When the player enters a room, the program will describe the room. This way the player will know if they went back to a room that have already been to.

Create room.cpp and implement the methods in room.h. You MAY NOT change the header file in ANY way.

____________________________________________________________________________

Part 2: The Maze

A maze is just a bunch of rooms! There are three things we need to know to make a maze. We need to know what room the player starts in. We need to know where the exit is. This will allow us to tell the player that they won. We also need to know what room the player is currently in.

Download the attached maze.h header file. Create a maze.cpp file and implement all the methods defined.You MAY NOT change the header file in ANY way.

____________________________________________________________________________

Part 3: Make a Maze

Create a alpha.cpp file. We will create a very simple maze. This maze has three rooms. The player walks north from the start room gets to a middle room. The middle room leads to the exit.

An easy way to connect all the rooms is to put them into a vector of pointers.

 //Trivial Maze vector my_rooms(3); my_rooms[0] = new room("This room is the entrance."); my_rooms[1] = new room("This room has a table. Maybe a dinning room?"); my_rooms[2] = new room("This room is the exit. Good Job."); //room 0 is south of room 1 my_rooms[0]->setNorth(my_rooms[1]); my_rooms[1]->setSouth(my_rooms[0]); //Room 2 is east of room 1 my_rooms[1]->setEast(my_rooms[2]); my_rooms[2]->setWest(my_rooms[1]); //Make a maze! //Set the start and exit rooms. maze my_maze(my_rooms[0],my_rooms[2]); 

Create an interface for the player (the main with which the user will interact). Print a description of the room. Next, ask the player what direction to move. Either move into the next room, or stay in the same place if the path is blocked.

Here is an example walk through the above maze.

This room is the entrance. Enter direction to move north west east south restart west Direction invalid, try again. This room is the entrance. Enter direction to move north west east south restart north You went north This room has a table. Maybe a dinning room? Enter direction to move north west east south restart reset You went back to the start! This room is the entrance. Enter direction to move north west east south restart north You went north This room has a table. Maybe a dinning room? Enter direction to move north west east south restart west Direction invalid, try again. This room has a table. Maybe a dinning room? Enter direction to move north west east south restart east You went east You found the exit! 

____________________________________________________________________________

Part 4: Make a real maze

Make a real maze. Your maze must have AT LEAST 8 rooms and 2 paths. Paths may end in dead ends, but 1 path must lead to the exit.

As comments at the top of the main file, give instructions to walk both paths in the maze.

____________________________________________________________________________

Finishing Up

All the required files:

alpha.cpp

maze.cpp

maze.h

room.cpp

room.h

A maze with at least 15 rooms and 2 paths

Directions to walk through both paths as a comment

____________________________________________________________________________

maze.h

#ifndef _MAZE_

#define _MAZE_

#include "room.h"

class maze

{

private:

//Room the player starts in

room* start_room_;

//If the player finds this room they win

room* exit_room_;

//What room is the player currently in

room* current_;

public:

//Inputs: Pointer to start room and exit room

//Sets current to be start room

maze(room* st=NULL, room* ex=NULL);

//Return the room the player is in (current)

room* getCurrent() const;

//The next four all have the same idea

//See if there is a room in the direction

//If the direction is NULL, then it is impossible to go that way

//in this case return false

//If the direction is not null, then it is possible to go this way

//Update current to the new move (move the player)

//then return true so the main program knows it worked.

bool moveNorth();

bool moveSouth();

bool moveEast();

bool moveWest();

//If the current room is the exit,

//then the player won! return true

//otherwise return false

bool atExit() const;

//If you get stuck in the maze, you should be able to go

//back to the start

//This sets current to be the start_room

void reset();

};

#endif

____________________________________________________________________________

room.h

#ifndef _MAZE_ROOM_

#define _MAZE_ROOM_

#include

using namespace std;

class room

{

private:

//Description of the room to print out

//These should be unique so the player knows where they are

string description_;

//These either tell us what room we get to if we go through the door

//or they are null if the "door" can't be taken.

room* north_;

room* south_;

room* east_;

room* west_;

public:

//Constructor sets the description

//All four doors should be set to NULL to start

room(string descr="");

//Access

//Return the correct values

string getDescription() const;

room* getNorth() const;

room* getSouth() const;

room* getEast() const;

room* getWest() const;

//Mutators

//Update the values

void setDescription(string d);

void setNorth(room* n);

void setSouth(room* s);

void setEast(room* e);

void setWest(room* w);

};

#endif

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions

Question

What are the functions of top management?

Answered: 1 week ago

Question

Bring out the limitations of planning.

Answered: 1 week ago

Question

Why should a business be socially responsible?

Answered: 1 week ago

Question

Discuss the general principles of management given by Henri Fayol

Answered: 1 week ago