→This assignment is due by Saturday, May 27, 2023, 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L2A,
L2B,
L2C
←
→ Do not forget to complete zyBooks Assignment 2 for this set.←
· Instructions · Rubric · Best Practices · Submission Process · Submission Contents ·
For this assignment you will build upon Lab2C - Samodelkin Battle Simulator. The expanded version will feature the hero moving through a series of random rooms, sometimes encountering a monster and acquiring valuable treasure. The following UML diagram lists all the components. Click the image to enlarge the image. More details about each class are given after the image.
![Samodelkin Game UML](images/uml_samodelkin_game.png)
Item
Class
The Item
class contains a name and value of some item. There is only a parameterized constructor that sets the name and value
properties of the object. There exists an associated getter for the name and value. There are no setters as these value will never be changed
once set.
Room
class
The Room
is the container that holds all the objects of interest for our world. The members of a Room
are as follows:
private
members:Player *monster
: a pointer to aMonster
object. If the pointer is anullptr
, then there is no monster in the room. If the pointer is not anullptr
, then the object corresponds to an enemy monster in the room.Item *treasure
: a pointer to anItem
object. If the pointer is anullptr
, then there is no treasure in the room. If the pointer is not anullptr , then the object corresponds to the treausre in the room.std::string name
: name or title of the room.std::string description
: description of the room.
public
members:Room()
: default constructor that sets the monster and treasure pointers to be anullptr
, sets thename
to beGeneric Room
, and the description to beNothing to see here.
Room(Player*, Item*, std::string, std::string)
: parameterized constructor that sets the monster pointer, treasure pointer, name, and description of the room.std::string getRoomName()
: returns the name of the roomstd::string getRoomDescription()
: returns the description of the roombool hasMonster()
: returnstrue
if the monster pointer is not anullptr
.false
otherwise.bool hasTreasure()
: returnstrue
if the treasure pointer is not anullptr
.false
otherwise.bool monsterIsDefeated()
: returnstrue
if the room has a monster and the monster health is not positive. returnstrue
if the room does not have a monster.false
otherwise.bool battleMonster(Player*)
: if the room has a monster, then the provided player object fights the room's monster (note: this is the implementation from Lab2C). returnstrue
if the monster dies or the room does not have monster. returnsfalse
if the monster wins the battle.Item* takeTreasure()
: if the monster is defeated or the room doesn't have a monster, returns the current treasure pointer and updates the treasure pointer to be anullptr
. otherwise, does nothing.
Game
class
The Game
contains our full game logic. It does not contain many things, but puts everything together. The description of the members are as follows:
private
members:Player hero
: the human's character they will bring through the world.Room currentRoom
: the current room the hero is in.Room createNewRoom()
: method to randomly generate a room. You have freedom, flexibility, and creative license with this function. It needs to randomly assign a monster (denoted by a name, health, and dice) or not. It needs to randomly assign an item (denoted by name and value) or not. It needs to randomly assign a name and description. This could be as simple as using anif
/else
structure to randomly choose predeterminedRoom
objects.
public
members:Game()
: default constructor that initialize the hero to aPlayer
with 100 health, is blessed, and rolls three five-sided dice. AssignscurrentRoom
to a randomly generated room.void play()
: contains the running of the game logic. See the next section for a thorough description of how the game plays.
Game::play()
Instructions
For this assignment, main()
will be very simple. Its contents will be:
#include "Game.h"
int main() {
Game samodelkinGame;
samodelkinGame.play();
return 0;
}
All our program logic, and thus game logic, is contained within Game::play()
. The following game play needs to be implemented:
- while the hero is still alive
- Print the following message with values in {} replaced with the current variable values:
{hero's name} enters {room name}
- Print the room description
- while the hero is in the room and alive
- Ask the user what they wish to do. Present them with the following options:
- L - look around
- F - fight monster
- T - take treasure
- E - exit room
- Have the user enter a character to denote their choice. The user may enter an upper or lower case character. React accordingly to the user's choice
- If the user chose to look around
- If there is a monster in the current room that is not defeated, print
There's a monster in here!
- If there is treasure in the current room that has not been taken, print
There's treasure in here!
- If there is no monster and no treasure, print
There's nothing here.
- If there is a monster in the current room that is not defeated, print
- If the user chose to fight the monster
- If the current room has a monster but it's already been defeated, print
The monster has already been defeated.
- If the current room has a monster that hasn't been defeated, have the hero battle the monster.
- If there's no monster in the current room, print
There's no monster in here.
- If the current room has a monster but it's already been defeated, print
- If the user chose to take the treasure
- If the current room has treasure and also has a monster that hasn't been defeated, print
There's a monster blocking the treasure!
- If the current room has treasure and no monster in the way, take the treasure. Print what was gained.
- If the current room doesn't have treasure, print
There's no treasure in here.
- If the current room has treasure and also has a monster that hasn't been defeated, print
- If the user chose to exit the room
- If the current room has a monster that hasn't been defeated, print
There's a monster blocking the exit!
- If the current room does not have a monster in the way, leave the current room and generate a new random room.
- If the current room has a monster that hasn't been defeated, print
- If the user chose anything else invalid, tell the user to enter a valid choice
- Ask the user what they wish to do. Present them with the following options:
- Print the following message with values in {} replaced with the current variable values:
You will need to use additional variables to track some of the information necessary to the game state.
Extra Credit
Add a way for the game to "keep score." Count how many rooms the hero has successfully exited. Additionally, maintain an inventory of all treasure gained. Upon game end, print out how many rooms were passed and the total value of treasure collected.
Sample Game Output
Below is a sample running of the game (with the extra credit component):
% ./A2
Gandalf enters Mushroom Circle
You feel like you're being watched.
What do you want to do?
L) Look around
F) Fight monster
T) Take treasure
I) Inventory
E) Exit current room
Choice: l
There's a monster in here!
There's treasure in here!
What do you want to do?
L) Look around
F) Fight monster
T) Take treasure
I) Inventory
E) Exit current room
Choice: f
The battle has commenced!
Gandalf attacks Faery dealing 10 damage
Gandalf has vanquished Faery
What do you want to do?
L) Look around
F) Fight monster
T) Take treasure
I) Inventory
E) Exit current room
Choice: t
You gain Mushroom worth 0.1 doubloons
What do you want to do?
L) Look around
F) Fight monster
T) Take treasure
I) Inventory
E) Exit current room
Choice: l
There's nothing here
What do you want to do?
L) Look around
F) Fight monster
T) Take treasure
I) Inventory
E) Exit current room
Choice: e
Gandalf exits Mushroom Circle with 100 health remaining and 0.1 doubloons worth of treasure
Gandalf enters Forest
There's something in the bushes.
What do you want to do?
L) Look around
F) Fight monster
T) Take treasure
I) Inventory
E) Exit current room
Choice: l
There's treasure in here!
What do you want to do?
L) Look around
F) Fight monster
T) Take treasure
I) Inventory
E) Exit current room
Choice: t
You gain Rusty Shield worth 1.1 doubloons
What do you want to do?
L) Look around
F) Fight monster
T) Take treasure
I) Inventory
E) Exit current room
Choice: t
There's no treasure in here.
What do you want to do?
L) Look around
F) Fight monster
T) Take treasure
I) Inventory
E) Exit current room
Choice: i
Gandalf is currently holding:
Mushroom (0.1)
Rusty Shield (1.1)
What do you want to do?
L) Look around
F) Fight monster
T) Take treasure
I) Inventory
E) Exit current room
Choice: e
Gandalf exits Forest with 100 health remaining and 1.2 doubloons worth of treasure
Gandalf enters Foggy Woods
What's that smell?
What do you want to do?
L) Look around
F) Fight monster
T) Take treasure
I) Inventory
E) Exit current room
Choice: l
There's a monster in here!
There's treasure in here!
What do you want to do?
L) Look around
F) Fight monster
T) Take treasure
I) Inventory
E) Exit current room
Choice: t
There's a monster blocking the treasure!
What do you want to do?
L) Look around
F) Fight monster
T) Take treasure
I) Inventory
E) Exit current room
Choice: e
There's a monster blocking the exit!
What do you want to do?
L) Look around
F) Fight monster
T) Take treasure
I) Inventory
E) Exit current room
Choice: f
The battle has commenced!
[...]
Balrog counterattacks Gandalf dealing 12 damage
Balrog has vanquished Gandalf
Gandalf conquered 12 rooms and collected 23.2 doubloons worth of treasure
Best Practices To Follow
· Code Style · Code Correctness · Code Structure · Dynamic Memory Management · Software Engineering Design Principles ·
Code Style
The following set of guidelines ensure all code in this class will be written in a similar and consistent manner, allowing any reader to understand the program's intent and contents.
- One clear and consistent coding style used (such as K&R, 1TBS, or Allman).
- Course naming scheme is followed for variable, function, class, and other identifiers. See the course style guide for more specifics.
- Code is self-documenting. Variables sensibly named, function names descriptive of their purpose.
Code Correctness
The following set of guidelines ensure all programs written in this class behave properly without side effects.
- Code compiles and links without any errors or warnings.
- Program runs without any run time errors. Exceptions are properly caught, user input is validated appropriately, and program exits successfully without error.
- Use
const
wherever possible:- If you declare a variable and that variable is never modified, that variable should be
const
. - If your function takes a parameter and does not modify that parameter, that parameter should be
const
. - If a member function does not modify the callee, that member function should be
const
. - If you are pointing at a value that does not change, the pointer should point at a constant value (e.g.
const T*
). - If the pointer itself is never modified, the pointer should be a constant pointer (e.g.
T* const
). - If the pointer itself is never modified AND the value pointed at does not change, the pointer should be a constant pointer AND the pointer should point at a constant value (e.g.
const T* const
).
- If you declare a variable and that variable is never modified, that variable should be
Code Structure
The following set of guidelines ensure all programs written in this class are done in an abstracted, modular, extendable, and flexible manner.
- Do not use global variables unless absolutely necessary. Instead, encapsulate them and design your interfaces effectively. If there is no way around using a global variable, be prepared to defend and justify its usage.
- Program flow uses structural blocks (conditionals/loops) effectively, appropriately, and efficiently.
- Keep your headers clean. Put the absolute minimum required in your headers for your interface to be used.
Anything that can go in a source file should. Do not
#include
any system headers in your .h files that are not absolutely required in that file specifically. Do not addusing namespace
in headers. - Use header guards correctly and appropriately.
- Place templated class and function definitions in a
*.hpp
file. - Place static class and function definitions in abstracted
*.h
and*.cpp
files. - Place each class and structure in their own files as appropriate based on their makeup.
Dynamic Memory Management
The following set of guidelines ensure all programs written in this class behave properly without side effects.
- Implement the Big-3 as appropriate.
- Do not leak memory. Every allocation using
new
needs to have a correspondingdelete
.
Software Engineering Design Principles
The following set of guidelines ensure all program components written in this class are done in an abstracted, modular, extendable, and flexible manner.
- Follow and apply the following design principles:
- Write Once, Use Many / Write Once, Read Many (WORM) / Don't Repeat Yourself (DRY): Use loops, functions, classes, and
const
as appropriate. - Encapsulate what varies: Use functions and classes as appropriate. Identify the aspects that vary and separate them from what stays the same.
- Favor composition over inheritance.
- Program to an interface, not an implementation & SOLID Principles: When using object-oriented inheritance & polymorphism, do the following:
- No variable should hold a reference to a concrete class.
- No class should derive from a concrete class.
- No method should override an implemented method from any of its base classes.
- Use appropriate inheritance access. Only expose necessary members to derived classes and/or publicly.
- Use
virtual
andoverride
as appropriate. Mark members asfinal
wherever possible and/or appropriate on derived classes.
- Write Once, Use Many / Write Once, Read Many (WORM) / Don't Repeat Yourself (DRY): Use loops, functions, classes, and
Grading Rubric
Your submission will be graded according to the following rubric.
Points | Requirement Description |
15 | All labs completed and submitted L2A, L2B, L2C |
4 | Die class structured and implemented correctly. |
6 | Player class structured and implemented correctly. |
4 | Item class structured and implemented correctly. |
8 | Room class structured and implemented correctly. |
4 | Game class structured and implemented correctly. |
7 | Game::play() follows expected flow. |
+3 | Extra credit: Game keeps score of rooms passed along with inventory. |
5 | Best practices are followed:
|
0 | Submission structured appropriately. Submissions structured improperly will receive deductions. |
53 | Total Points |
→This assignment is due by Saturday, May 27, 2023, 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L2A,
L2B,
L2C
←
→ Do not forget to complete zyBooks Assignment 2 for this set.←
Submission
Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available.
It is critical that you follow these steps when submitting homework.
If you do not follow these instructions, your assignment will receive a major deduction. Why all the fuss? Because we have several hundred of these assignments to grade, and we use computer tools to automate as much of the process as possible. If you deviate from these instructions, our grading tools will not work.
Submission Instructions
Here are step-by-step instructions for submitting your homework properly:
-
Make sure you have the appropriate comment header block at the top of every source code file for this set. The header
block should include the following information at a minimum.
Be sure to fill in the appropriate information, including:/* CSCI 200: Assignment 2: A2 - Samodelkin Dungeon Crawler
* * Author: XXXX (INSERT_NAME) * Resources used (Office Hours, Tutoring, Other Students, etc & in what capacity): * // list here any outside assistance you used/received while following the * // CS@Mines Collaboration Policy and the Mines Academic Code of Honor * * XXXXXXXX (MORE_COMPLETE_DESCRIPTION_HERE) */- Assignment number
- Assignment title
- Your name
- If you received any type of assistance (office hours - whose, tutoring - when), then list where/what/who gave you the assistance and describe the assistance received
- A description of the assignment task and what the code in this file accomplishes.
Additionally, update theMakefile
for A2 to generate a target executable namedA2
.
- File and folder names are extremely important in this process.
Please double-check carefully, to ensure things are named correctly.
- The top-level folder of your project must be named
Set2
- Inside
Set2
, create 4 sub-folders that are required for this Set. The name of each sub-folder is defined in that Set (e.g.L2A
,L2B
,L2C
, andA2
). - Copy your files into the subdirectories of
Set2
(steps 2-3), zip thisSet2
folder (steps 4-5), and then submit the zipped file (steps 6-11) to Canvas. - For example, when you zip/submit
Set2
, there will be 4 sub-folders calledL2A
,L2B
,L2C
, andA2
inside theSet2
folder, and each of these sub-folders will have the associated files.
- The top-level folder of your project must be named
- Using Windows Explorer (not to be confused with Internet Explorer), find the files
named
main.cpp, Die.h, Die.cpp, Game.h, Game.cpp, Item.h, Item.cpp, Player.h, Player.cpp, Room.h, Room.cpp, Makefile
.
STOP: Are you really sure you are viewing the correct assignment's folder? - Now, for A2, right click on
main.cpp, Die.h, Die.cpp, Game.h, Game.cpp, Item.h, Item.cpp, Player.h, Player.cpp, Room.h, Room.cpp, Makefile
to copy the files. Then, return to theSet2/A2
folder and right click to paste the files. In other words, put a copy of your homework'smain.cpp, Die.h, Die.cpp, Game.h, Game.cpp, Item.h, Item.cpp, Player.h, Player.cpp, Room.h, Room.cpp, Makefile
source code into theSet2/A2
folder.
Follow the same steps for each lab to put a copy of each lab's deliverable into theSet2/L2
folders. Do this process forSet2/L2A
(main.cpp, Makefile
),Set2/L2B
(coordinate_conversion.h, coordinate_conversion.cpp, main.cpp, Makefile
),Set2/L2C
(main.cpp, Die.h, Die.cpp, Player.h, Player.cpp, Makefile
).
STOP: Are you sure yourSet2
folder now has all your code to submit?
The structure of the submission is as follows:- Set2/
- A2/
- main.cpp
- Die.h
- Die.cpp
- Game.h
- Game.cpp
- Item.h
- Item.cpp
- Player.h
- Player.cpp
- Room.h
- Room.cpp
- Makefile
- L2A/
- main.cpp
- Makefile
- L2B/
- coordinate_conversion.h
- coordinate_conversion.cpp
- main.cpp
- Makefile
- L2C/
- main.cpp
- Die.h
- Die.cpp
- Player.h
- Player.cpp
- Makefile
- A2/
*
only if present and appropriate to the implementation.
- Set2/
- Now, right-click on the
"Set2"
folder.- In the pop-up menu that opens, move the mouse
"Send to..."
and expand the sub-menu. - In the sub-menu that opens, select
"Compressed (zipped) folder"
.
STOP: Are you really sure you are zipping aSet2
folder with sub-folders that each contain amain.cpp
file in it?
- In the pop-up menu that opens, move the mouse
- After the previous step, you should now see a
"Set2.zip"
file.
- Now visit the Canvas page for this course
and click the
"Assignments"
button in the sidebar.
- Find Set2, click on it, find the
"Submit Assignment"
area, and then click the"Choose File"
button.
- Find the
"Set2.zip"
file created earlier and click the"Open"
button.
STOP: Are you really sure you are selecting the right homework assignment? Are you double-sure?
- WAIT! There's one more super-important step. Click on the blue
"Submit Assignment"
button to submit your homework.
- No, really, make sure you click the
"Submit Assignment"
button to actually submit your homework. Clicking the"Choose File"
button in the previous step kind of makes it feel like you're done, but you must click the Submit button as well! And you must allow the file time to upload before you turn off your computer!
- Canvas should say "Submitted!". Click "Submission Details" and you can download the zip file you just submitted. In other words, verify you submitted what you think you submitted!
In summary, you must zip the "Set2"
folder
and only the "Set2"
folder, this zip folder must have several sub-folders, you must name all these folders correctly, you must submit the correct zip file for this
homework, and you must click the "Submit Assignment"
button. Not doing these steps is like bringing your
homework to class but forgetting to hand it in. No concessions will be made for
incorrectly submitted work. If you incorrectly submit your homework, we will not be able to
give you full credit. And that makes us unhappy.
→This assignment is due by Saturday, May 27, 2023, 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L2A,
L2B,
L2C
←
→ Do not forget to complete zyBooks Assignment 2 for this set.←