Adventure
General
- All submissions must include a work history to be worth credit.
- Submit all files to Canvas. Make sure to name file(s) EXACTLY as specified - including capitalization.
- Make sure your program accepts input in EXACTLY the order and format given.
Do not ask for extra input or change the order of inputs.
If you want to make an expanded version of a program that and get feedback on it, email it to me or show me in class. - Slight variations in output wording/formatting are usually fine
(as long as formatting isn't part of the assignment).
If you do not get the right final output, print out some evidence of the work your program did to demonstrate your progress. - Readability and maintainability of your code counts. Poor formatting, confusing variable names, unnecessarily complex code, etc… will all result in deductions to your score.
Objective
Your goal is to create a simple text-based adventure game based on a Location class.
Requirements
Submit file: assign3.zip
Make sure to compress your entire folder, not just your code file.
I should be able to build your code with:
g++ -g -std=c++17 Location.cpp main.cpp -o program.exe
g++ -g -std=c++17 Location.cpp tests.cpp -o tests.exe
Background
We will be creating a representation of a map like this one:
We need to be able to have locations that connect to each other; it should be possible to travel from "the musty passage" to "a twisting shaft". But we also want to make sure there is only one copy of each location - we can't have two different copies of "a twisting shaft", one that you get to from "the musty passage" and another that you get to from "the shores of an underground lake".
Once this is built, we will use it as the basis for a simple text game where the player tries to find their way to the exit.
Setup
You are provided with this
file of unit tests to ensure that
your Location class works correctly. Copy that code into tests.cpp
.
Eventually, you will also need to build your own main function that has the "real" program.
Make a project using the ComboProject template.
Add new files
Location.h
/Location.cpp
to the folder. You should now have:- Location.h & .cpp - these will get the code for your Location class and be used in both the tester program and "real" program.
- tests.cpp - this will have the unit tests for the Location class. It is only compiled into the tester program. Make sure to use the provided tests.
- main.cpp - this will have a main function for your "real" program. It is only compiled into the "real" program.
Edit your Makefile. It should end up looking like:
# list your .h files here HEADERS = Location.h # list .cpp files here according to main program, tests, or both PROGRAM_FILES = main.cpp TEST_FILES = tests.cpp SHARED_FILES = Location.cpp
Focus on using the tests that are provided (Make sure to select Run Tests) until you get all the Location functions working. Then you can switch to writing code in main.cpp.
Location Class (80%)
The Location class represents a location in the game. Each location can be connected to up to 4 other locations (the locations that are North, South, East and West of the current location). As the player explores locations, they drop bread crumbs to mark where they have been before, so each room keeps track of whether it has been visited yet.
Direction should be defined as an enumeration inside your .h file before the class, like this:
If you wish, you can store four separate pointers for the four possible directions of travel instead of an array of pointers.
You do NOT need doxygen comments.
Function Descriptions
Below are notes about expected behavior for functions.
Location ()
Should just set the name to "?" all neighbors to null and everything else to false.
Location (string, bool)
The two arg constructor should set the name and exit members, setting the rest to null or false as appropriate.
hasNeighbor
Returns true if there is another location in the specified direction, false if there is not (nullptr).
getNeighbor
Returns a pointer to the neighbor in the indicated direction (or nullptr if there is not a neighbor).
setNeighbor
Stores the indicated Location pointer as the designated neighbor.
visit
Marks a room as having been visited.
isVisited
Returns true if a room has been visited.
isExit
Returns true if this Location is an exit.
getName
Returns the name of the location.
getDescription
Should return a string containing the name of the location, a list of the directions you can leave in and if it has been visited before. The first time we get the description for a room, it might say:
"a deep dark cave. Exits: north east south."
Or, for a different room that had been visited, something like:
"a musty passage. You have been here before. Exits: north east south."
Main (20%)
Your main.cpp
file should have the code for the game. It will build
a map like the picture below and then run the game of trying to find
the exit.
Players will type N, S, E or W to move to a new Location from the currentLocation. If they type an unavailable option, say W while in "a deep, dark cave", they should just stay where they are. When they reach the exit ("the surface"), the game should end.
An input of S N E N E S W
, or any other valid sequence of
moves to reach the surface, should play the entire game without you
(or me) having to enter the inputs room by room.
This behavior should happen naturally if you use cin >> charVariable
to get your input.
You can add any helper functions that make sense to you. If you want,
you can use this
starter code for main.cpp
.
It is a good idea to start filling in the function to build the map, and to use the debugger to check that it creates the correct map before trying to implement the game loop.