Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Assignment You will be developing one of these text-based games by reading in a single file that contains a variable number of room descriptions

C++

Assignment

You will be developing one of these text-based games by reading in a single file that contains a variable number of room descriptions (format of the file follows below).

First, your program will need to read a rooms file, whose name will be given as the first user-supplied command line argument. You must dynamically allocate all memory associated with the rooms file on the heap. Furthermore, the rooms file must be completely read into memory, and then the file must be closed before the game starts.

After all the rooms are read, you will place the user in the very first room (index 0) and provide them with a command line where they may enter one of six commands:

q - Quit (closes the program) l - Look (looks at the room the player is in) n, e, s, w - Moves the user in the given cardinal direction (north, east, south, or west). *If the room does not have an exit in the given direction, you must not move the player, but rather give them an error message. 

The "look" command will print the room information. An example of this information might be:

Short Room Title Description of Room Exits: n e s w ***(Only display the exits that exist in the room)***

The prompt for the user will be a greater than sign (>). You will then wait for the user to provide input until they quit the game using the command "q".

Rooms File

The rooms file is a single text file that may contain one or more room descriptions. A room has the following description in the rooms file:

Room Title ~ Long room description and further text that may span one or more lines, but is still terminated by a tilde '~' ~ exit_direction room_index exit_direction room_index ~ 

Each room will follow this format. Another room may follow, so you must keep reading rooms until you exhaust the file. An example room file may be as follows:

Room #0 ~ This is the first room the player should be in! Welcome to h! ~ w 1 ~ Room #1 ~ This is the second room, which is west of the first room. That also means that.... Room #0 is EAST of this room! ~ e 0 ~

Example Interaction

./lab myroomfile > l Room #0 This is the first room the player should be in! Welcome to h! Exits: w > w You moved WEST. > l Room #1 This is the second room, which is west of the first room. That also means that.... Room #0 is EAST of this room! Exits: e > e You moved EAST. > l Room #0 This is the first room the player should be in! Welcome to h! Exits: w > e You can't go EAST! > q

Restrictions

1. You may not use cout for this lab. You must use printf(). (Tutorial: https://www.codingunit.com/printf-format-specifiers-format-conversions-and-formatted-output (Links to an external site.)Links to an external site.)

2. You may not use cin for this lab. You must use scanf(). (Tutorial: https://computer.howstuffworks.com/c7.htm (Links to an external site.)Links to an external site.)

3. You may not use any arrays, vectors, or resizable data types for this lab. Instead, you must use pointers and dynamic memory to store/manipulate your data (e.g., rooms file).

4. Warnings might be as bad as errors. The -Werror below will ensure that all warnings are considered errors.

6. You may use ifstream, getline, C++ strings, and string streams to parse the room files.

7. You are NOT guaranteed that there will be no tilde's in any room description or title. However, to mark the ending of a file section, you are guaranteed that a tilde will be on a line by itself.

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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

Q.No.1 Explain Large scale map ? Q.No.2 Explain small scale map ?

Answered: 1 week ago