The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Question:
You are tasked with writing a program that will allow the player to navigate and explore a dungeon that is described with a level file. A level file will specify the rooms on the first line delimited by a space, following that, each line will describe a room's pathway to another room.
Â
The first room listed on the first line is the starting point of the level.
Â
The level file structure :
START FOYER ELEVATOR START > NORTH > FOYER FOYER > SOUTH > START START > WEST > ELEVATOR
Â
Each pathway is broken up by spaces and the > symbols. <roomA> > WEST > <roomB> this translates to:
roomA's west's pathway connects to roomB
Â
Annotation fo the test level file:
START FOYER ELEVATOR //START is the first room of the dungeon. START > NORTH > FOYER //START's north pathway connects to the FOYER FOYER > SOUTH > START //FOYER's south pathway connects to the START START > WEST > ELEVATOR //START's west pathway connects to the ELEVATOR
Â
The commands that a player can input:
NORTH SOUTH EAST WEST QUIT
Â
QUITÂ command allows the user to quit the program, please ensure that you clean up any memory you have allocated.
Â
The NORTH, SOUTH, EAST and WEST commands will allow the player to move between the rooms via the room's pathways. Each room has a maximum of 4 pathways.
Â
A room will outline if the paths that are available to it by specifying the direction at the side of the room. For example if the room has a path to another room by going north it will show N on the north side of the room. Example:
---N--- | | | | | | | | | | -------
If it does not have a path, it will be a - or | depending on the side it is on.
Â
If a user specifies a direction that does not have a pathway the program should output:
No Path This Way
Â
If the user inputs an invalid command the program should respond with:
What?
Â
The room is always 9 x 5 (with a space at the start and end of the top and bottom of the room);
The name should also be outputted before drawing the room.
NORTH START ---N--- | | | | W | | | | | -------
Â
Specific functions to know for this task:
fopen, fgets, sscanf, malloc, realloc, free, memset, strcpy, strcmp
Â
Assumptions/Clarifications:
* 8192 is largest number of characters in a line from the level file.
* Room name can be variable length.
* Commands are case sensitive
* On every command (even invalid ones) you need to redraw the room
* You may assume the test files are correct.
* Room pathways do not have logical entries. If the player moves NORTH you do not need to map the previous room to SOUTH of the current room.
* If a room's pathway has already been assigned it can be overridden when reading the level file.
Â
Examples:
Â
Example 1:
./dungeon test_dungeon.dg
Â
START ---N--- | | | | W | | | | | ------- NORTH FOYER ------- | | | | | | | | | | ---S--- SOUTH START ---N--- | | | | W | | | | | ------- QUIT
Â
Example 2:
./dungeon test_dungeon.dg
Â
START ---N--- | | | | W | | | | | ------- WEST ELEVATOR ------- | | | | | | | | | | ------- NORTH No Path This Way ELEVATOR ------- | | | | | | | | | | ------- EAST No Path This Way ELEVATOR ------- | | | | | | | | | | ------- QUIT
Â
Example 3:
./dungeon
Â
No Level File Specified
Â
Example 4:
./dungeon test_dungeon.dg
Â
START ---N---Â | |Â | |Â WÂ | |Â | |Â | ------- ksamdkl What? START ---N--- |Â | |Â | W |Â | |Â | |Â -------
test_dungeon.dg
Â
START FOYER ELEVATOR
START > NORTH > FOYER
FOYER > SOUTH > START
START > EAST > ELEVATOR
-----------