Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How can I write just The Maze class in C++?? I am having trouble understanding how to implement the usage of fstream reading data and
How can I write just The Maze class in C++??
I am having trouble understanding how to implement the usage of fstream reading data and using that data for different member functions and pointers to different classes.
The project I am working on requires us to build a maze by reading in data from a .txt file.
Below you will find the class requirements:
The file format that the Maze reads in is specified here:
The Maze Class C Maze rooms: Room** O rows: int cols: int omazeFile: std::ifstream LoadMaze(): void CreatePassage(std::string type): Passage* Mazestd::string maze File) GetRoom(int row, int col): Room* GetNumberRows(): int GetNumberCols(): int -Maze() This class holds the information for the Maze. The Maze is a two-dimensional array of Rooms represented by a Room**. You will need to read the information for the Maze from an input file, assemble the information into Room objects, and add them to the array. In addition to the parameterized constructor and a destructor, this class should have the following methods: LoadMaze () This private helper function is used to read the file and create the two-dimensional array of Room objects. CreatePassage() This private helper function takes in a string of'-,'+, or an item need to open a door, and returns a pointer to an appropriate Passage object. GetRoom (int row, int col) o Takes in a position in terms of a row and col and returns a pointer to the Room object at that location in the Maze. GetNumberRows() GetNumberCols () o Simple getter methods that return the number of rows and columns in the maze. The Room Class C Room name: std::string items: std::vector<:string> O northPassage: Passage* O eastPassage: Passage* O southPassage: Passage* westPassage: Passage* Room) Room(std::string name, Passage*, Passage*, Passage*, Passage*) o GetName() : std::string o GetNorthPassage(): Passage* GetEastPassage(): Passage* o GetSouthPassage(): Passage* GetWestPassage(): Passage* Additem(std::string item): void AcquireNextItem(): std::string This class holds information for a Room in the maze. Each Room object is composed of four passages pointers (one for each direction), a name, and the list of items in that Room. In addition to the parameterized constructor, this class should have the following methods: GetName() o Returns the name of the Room. GetNorthPassage (), GetEastPassage () GetSouthPassage (), GetwestPassage () Each of these methods returns a pointer to the corresponding Passage. This allows for calls such as "someRoom->GetNorthPassage()-> Open()" AddItem (std::string item) Adds an item to the items vector of the Room object. AcquireNextItem() o When a player enters a room, they should receive all items in that room. AcquireNextltem returns one item at a time and removes it from the Room. The Passage Class C Passage isOpen: bool key: std::string o Passage) Passage(bool is Open) . Passage(bool is Open, std::string key) o Is Open(): bool RequiresKey(): bool GetRequiredKey(): std::string .Open() : void This class is responsible for storing information on a passage in the maze. A passage can either be a solid wall, an open passageway, or a door. The first parameterized constructor can be used to create a passage that is not a door. The second takes in an additional key parameter for a door. In addition to the parameterized constructors, this class should have the following methods: IsOpen() o Returns a boolean value to state whether the passage is currently open. Requireskey ) o Returns a boolean (true or false) if the passage requires a key to open. This function allows you to determine whether the passage is a door. GetRequiredkey () o Returns an std::string of the key needed to open the door. For instance a "red_key" is needed to open the door that is South of The Start Open() o Opens a closed door. You should check that the player has the required key before opening the door. A maze is specified by an input file with the following format: Row_count, Column_count Room_name, North_passageway, East_passageway, South_passageway, West_passageway,list_of_items_in_room The first line of the input file is the number of rows (Row_count) and the number of columns (Column_count) in the maze. The first line is followed by Row_count x Column_count lines with each line representing a different Room in the maze. Each room has a name, four connected passageways, and a list of items in that room. Each passageway in a room is one of three types: 1. "-": No passage is allowed 2. "+": Passage is open 3. "item_needed_to_open_passageway": Requires the item(s) specified to open the door The input file for our example maze would look like the following: 23 The Start, -,+, red_key, -, axe blue_key The Landing, -, +, -,+, Master Bedroom, -,-,-,+, red_key The Kitchen, red_key, +,-,-, The Hall, -,+,-,+, The Exit!, -,+,-,+, The Maze Class C Maze rooms: Room** O rows: int cols: int omazeFile: std::ifstream LoadMaze(): void CreatePassage(std::string type): Passage* Mazestd::string maze File) GetRoom(int row, int col): Room* GetNumberRows(): int GetNumberCols(): int -Maze() This class holds the information for the Maze. The Maze is a two-dimensional array of Rooms represented by a Room**. You will need to read the information for the Maze from an input file, assemble the information into Room objects, and add them to the array. In addition to the parameterized constructor and a destructor, this class should have the following methods: LoadMaze () This private helper function is used to read the file and create the two-dimensional array of Room objects. CreatePassage() This private helper function takes in a string of'-,'+, or an item need to open a door, and returns a pointer to an appropriate Passage object. GetRoom (int row, int col) o Takes in a position in terms of a row and col and returns a pointer to the Room object at that location in the Maze. GetNumberRows() GetNumberCols () o Simple getter methods that return the number of rows and columns in the maze. The Room Class C Room name: std::string items: std::vector<:string> O northPassage: Passage* O eastPassage: Passage* O southPassage: Passage* westPassage: Passage* Room) Room(std::string name, Passage*, Passage*, Passage*, Passage*) o GetName() : std::string o GetNorthPassage(): Passage* GetEastPassage(): Passage* o GetSouthPassage(): Passage* GetWestPassage(): Passage* Additem(std::string item): void AcquireNextItem(): std::string This class holds information for a Room in the maze. Each Room object is composed of four passages pointers (one for each direction), a name, and the list of items in that Room. In addition to the parameterized constructor, this class should have the following methods: GetName() o Returns the name of the Room. GetNorthPassage (), GetEastPassage () GetSouthPassage (), GetwestPassage () Each of these methods returns a pointer to the corresponding Passage. This allows for calls such as "someRoom->GetNorthPassage()-> Open()" AddItem (std::string item) Adds an item to the items vector of the Room object. AcquireNextItem() o When a player enters a room, they should receive all items in that room. AcquireNextltem returns one item at a time and removes it from the Room. The Passage Class C Passage isOpen: bool key: std::string o Passage) Passage(bool is Open) . Passage(bool is Open, std::string key) o Is Open(): bool RequiresKey(): bool GetRequiredKey(): std::string .Open() : void This class is responsible for storing information on a passage in the maze. A passage can either be a solid wall, an open passageway, or a door. The first parameterized constructor can be used to create a passage that is not a door. The second takes in an additional key parameter for a door. In addition to the parameterized constructors, this class should have the following methods: IsOpen() o Returns a boolean value to state whether the passage is currently open. Requireskey ) o Returns a boolean (true or false) if the passage requires a key to open. This function allows you to determine whether the passage is a door. GetRequiredkey () o Returns an std::string of the key needed to open the door. For instance a "red_key" is needed to open the door that is South of The Start Open() o Opens a closed door. You should check that the player has the required key before opening the door. A maze is specified by an input file with the following format: Row_count, Column_count Room_name, North_passageway, East_passageway, South_passageway, West_passageway,list_of_items_in_room The first line of the input file is the number of rows (Row_count) and the number of columns (Column_count) in the maze. The first line is followed by Row_count x Column_count lines with each line representing a different Room in the maze. Each room has a name, four connected passageways, and a list of items in that room. Each passageway in a room is one of three types: 1. "-": No passage is allowed 2. "+": Passage is open 3. "item_needed_to_open_passageway": Requires the item(s) specified to open the door The input file for our example maze would look like the following: 23 The Start, -,+, red_key, -, axe blue_key The Landing, -, +, -,+, Master Bedroom, -,-,-,+, red_key The Kitchen, red_key, +,-,-, The Hall, -,+,-,+, The Exit!, -,+,-,+Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started