Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ONLY NEED HELP WITH STEPS 4 and 5. THE REST ARE ONLY HERE FOR INFO. Step 2: Check out maze_data.hpp The file maze_data.hpp contains some

ONLY NEED HELP WITH STEPS 4 and 5. THE REST ARE ONLY HERE FOR INFO.

image text in transcribed

Step 2: Check out maze_data.hpp

The file maze_data.hpp contains some data specifying a maze. There are two constant values MAZE_HEIGHT and MAZE_WIDTH that specify, respectively, the height and width of the maze, in characters. Then, MAZE_DATA is a 2D array of characters representing the maze itself. There are 4 different characters used:

  • '#' this represents a wall in the maze

  • ' ' (space) this represents an open space in the maze

  • '@' this represents the start of the maze

  • '^' this represents the end of the maze

In this lab, youre going to write a classes to represent this maze and an algorithm to explore it randomly, displaying the location of your random explorer in the maze after each step it takes.

Step 3: Implement classes to represent locations in your maze

You should write one abstract class called MazeLocation to represent a generic location in the maze. It should have the following public methods:

  • bool is_occupiable() this will indicate whether this location can be occupied by your maze explorer

  • char get_display_character() this will return the character that should be displayed to represent this location in the maze

After writing the MazeLocation class, you should write two classes that derive from it: Wall and OpenSpace.

The Wall class should represent a wall in the maze. A wall is never occupiable, and its display character is always '#'.

The OpenSpace class should represent an open space in your maze. An open space is always occupiable, but its display character might change depending on whether your explorer is in the space or whether it contains the start or end of the maze. To help with this, you should implement these additional methods for this class:

  • void set_has_explorer(bool) and bool has_explorer() use these functions to set and return a boolean class member that lets you know whether your explorer is in this space

  • void set_is_start(bool) and bool is_start() use these functions to set and return a boolean class member that lets you know whether this space is the start of the maze

  • void set_is_end(bool) and bool is_end() use these functions to set and return a boolean class member that lets you know whether this space is the end of the maze

Implement each of these classes in a separate set of .hpp and .cpp files. When youre done, add and commit your files to your git repo, and push them to your repo on GitHub.

Step 4: Write a Maze class to represent your maze

Now, you should write a Maze class to tie together your location classes above to represent a whole maze (note that because the maze in this lab only has one level, the Maze class here will actually correspond to the MazeLevel class in your final project). Here are some things you should implement in your Maze class:

  • Your class should have a 2D vector of MazeLocation pointers to allow you to use polymorphism to represent your maze as a grid of Wall and OpenSpace objects: std::vector<:vector> > locations;

  • Your class should have a constructor that takes the following arguments: a 2D array of characters representing the maze (like MAZE_DATA from maze_data.hpp), an integer representing the mazes height, and an integer representing the mazes width. In this constructor, you should allocate your grid of locations and then loop through the maze data and allocate new Wall and OpenSpace objects to fill the grid, e.g.: this->locations[i][j] = new Wall() or this->locations[i][j] = new OpenSpace();

  • You should write a destructor that frees the space you allocate in the constructor.

  • You should write a method to return the MazeLocation at a specified row and column of the grid: MazeLocation* get_location(int, int);

  • You should write a method to display the maze in the console: void display_maze(); This method should use the get_display_character() method to get the character to display for each of the individual locations.

Implement this class in a separate set of .hpp and .cpp files. When youre done, add and commit your new files to your git repo, and push them to your repo on GitHub.

Step 5: Write an application that creates and displays a maze

Now, write a small application that creates an object of your Maze class using the data in maze_data.hpp. Then, use the display_maze() method to display your maze. When youre done, add and commit your application code to your git repo, and push it to your repo on GitHub.

1 #ifndef MAZE DATA HPP 2 #define MAZE DATA HPP #define MAZEHEIGHT 16 #define MAZE WIDTH 16 - 5 const char* MAZE-DATA[MAZE-HEIGHT] { = 10 12 13 14 15 16 17 18 19 20 21 23 25 26 #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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions