Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview In the late 1990s and early 2000s, text-based multi-user games called MUDs (Multi-User Dungeons) were frequented by gamers. While nothing like the 3 dimensional

Overview

In the late 1990s and early 2000s, text-based multi-user games called MUDs (Multi-User Dungeons) were frequented by gamers. While nothing like the 3 dimensional graphic shooters or builders (e.g., Minecraft), these were a way for computer gamers from all over the world to connect to a central server and socialize with others.

You will be designing a very simple MUD that only supports a single user and several rooms.

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. 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:

The Room of DOOM ~ This is the first room the player should be in! Welcome to COSC130! ~ w 1 ~ A Gloomy Room ~ This is the second room, which is west of the first room. That also means that.... The doom room 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 COSC130! 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 COSC130! Exits: w > e You can't go EAST! > q

The following is a test room file with 25 rooms: room1

Restrictions and Hints

  1. You must use new and delete to create the memory to store all of the rooms. Recall that there are two versions of new: new and new[] and two versions of delete: delete and delete[]. Please see my COSC102 review slides if you do not remember this or if this is "greek" to you.
    1. You will need to count the number of rooms in the file before you actually read the rooms into memory that you created with new. To do this, notice that there are three tildes ~ per room and these tildes will be on their own line. You can use the getline() function to read a line at a time and see if the line is just a tilde ~. If you see three of these, you've seen one room. In other words, count the number of tildes you see and divide by 3. This quotient will give you the number of rooms you have.
    2. You should use a structure to store the data for a room. You can create multiple rooms by using the new[] function as follows: Room *rooms = new Room [ num_tildes / 3 ];
    3. Notice that there are four exits: n, s, e, and w. However, the room that each one points to is a room index. Therefore, room index -1 is not possible, so you can use this sentinel value to mark an invalid exit. Then, you can use an if statement: if (room != -1) { cout << "w"; }. This is purely an example, and your code should look better.
    4. Always delete memory and close your files when they are no longer needed. Do this as soon as you can.
  2. You may use C++ style strings (#include ).
  3. You may not use any vectors or resizable data types (other than C++ strings) 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.
  5. You must comment your code, like you did in COSC102, including a header, any TA or student who helped you, and inline-code comments.

Compiling

g++ -g -O0 -std=c++11 -Wall -Werror -o lab lab.cpp

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions

Question

Question Can any type of stock or securities be used in an ESOP?

Answered: 1 week ago