→This assignment is due by Tuesday, September 30, 2025, 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.←
Jump To: · Rubric · Submission ·
Jump to a specific subsection:
· Technical Requirements
· Helper Functions
· main
Function
· Extra Credit
· Sample Output
·
Be sure to read all the of the specifications and requirements before beginning to implement this project. The task is to create a simple dungeon crawler where your Hero explores rooms, finding items, fighting baddies, and hoping to escape alive!
Technical Requirements
- All helper functions must be abstracted across separate files named
samodelkin.h
andsamodelkin.cpp
. - The helper function interfaces must match as outlined below.
- The helper functions must be used appropriately.
- Your
main()
function will reside inmain.cpp
. - Your functions must use Pass-by-Value and Pass-by-Pointer appropriately. We will not be using Pass-by-Reference for this assignment.
- Create global constants in the appropriate file to store the following integers:
- The number of rooms that can be explored (for testing, we recommend setting this to
10
) - The room number the key can be found in (for testing, we recommend setting this to
3
) - The room number the weapon can be found in (for testing, we recommend setting this to
7
) - The room number the exit can be found in (for testing, we recommend setting this to
5
)
- The number of rooms that can be explored (for testing, we recommend setting this to
- Create global constants in the appropriate file to store the following integers for the game state:
- Playing =
1
- Player Won =
2
- Player Lost =
3
- Player Quit =
4
- Playing =
- When prompted, the user can only enter an upper or lowercase
Y
orN
. If the user enters any other value, they shall be reprompted. - Use const where ever appropriate.
- The program must build with no errors and no warnings.
- The text does not need to match 100%. Have fun with theming your quest!
Helper Functions
The required helper functions are described below.
generate_random_room_number()
- Input: Nothing
- Return: An integer
- Task: Generates a random integer within the range
1
and the number of rooms that exist
empty_room()
- Input: Nothing
- Return: Nothing
- Task: Prints a message saying there is nothing in here.
key_room()
- Input: A boolean if the hero currently has a key
- Return: Nothing
- Task:
- Prints a message alluding there is something in this room.
- If the user already has the key, prints a message saying the key was already found.
- If the user doesn't have the key, ask the user if they wany to pick something up.
- If the user says they wish to pick something up, then set the boolean to be true and print a message saying the key has been found.
- If the user does not want to pick something up, then print a message warning this may be a bad choice.
weapon_room()
- Input: A boolean if the hero currently has a weapon
- Return: Nothing
- Task:
- Prints a message alluding there is something in this room.
- If the user already has a weapon, prints a message saying the weapon was already found.
- If the user doesn't have a weapon, ask the user if they wany to pick something up.
- If the user says they wish to pick something up, then set the boolean to be true and print a message saying the weapon has been found.
- If the user does not want to pick something up, then print a message warning this may be a bad choice.
enemy_room()
- Input: A boolean if the hero currently has a weapon, An integer for the hero's current health, An integer for the current game state
- Return: Nothing
- Task:
- Generate a random integer in the inclusive range of
20
to35
for the enemy's health and print this value. - Simulate a battle until the enemy health is no longer positive or the hero's health is no longer positive.
- Each round of the battle both the enemy and hero attack simultaneously.
- The enemy attack is a random integer in the inclusive range of
5
to10
. Print the enemy damage done and deduct from the hero's health. - If the hero has a weapon, then the damage is a random integer in the inclusive range of
10
to15
. - If the hero does not have a weapon, the damage is a random integer in the inclusive range of
1
to5
. - Print the hero damage done and deduct from the enemy's health.
- If the enemy dies, then print a message stating it is slain.
- If the hero dies, then set the game state to the lose state and print a message the hero died.
- Generate a random integer in the inclusive range of
potion_room()
- Input: An integer for the hero's current health
- Return: Nothing
- Task: Generates a random integer between the inclusive range of
5
and15
. Adds this to the hero's health and prints how much health was added.
exit_room()
- Input: A boolean if the hero currently has a key, An integer for the current game state
- Return: Nothing
- Task:
- Prints a message there is a locked gate.
- If the hero has the key, set the game state to the win state and print a message that the gate is unlocked.
- Otherwise, print a message to continue searching.
enter_room()
- Input: An integer for the room number, An integer for the hero's current health, A boolean if the hero currently has a key, A boolean if the hero currently has a weapon, An integer for the current game state
- Return: Nothing
- Task:
- Cleanly prints what room number the hero is in, the hero's current health, and what is currently in the hero's inventory (key and/or weapon).
- If the current room number is the key room number, then calls
key_room
. - If the current room number is the weapon room number, then calls
weapon_room
. - If the current room number is the exit room number, then calls
exit_room
. - Otherwise, there is a 20% chance the room is empty. There is a 20% chance the room contains a potion. There is a 60% chance the room contains an enemy. Note: this isn't a random chance. The same room number will always resolve to the same outcome every time the hero visits that room number. (Hint: modulus is handy here.)
The main
Function
The main
function will track the overall game state and implement the game flow.
- Store the game state variables:
- Number of rooms explored (initially zero)
- The current game state (initially playing)
- The hero's health (initially 100)
- If the hero has a key (initially no)
- If the hero has a weapon (initially no)
- While the game is in a playing state
- Generate a random room number
- Enter the room
- Increment the number of rooms explored
- If after visiting, still in a playing state ask if the user wishes to continue exploring. If no, then set the game state to quit.
- Print how many rooms were explored.
- If the user won, congratulate the user!
- If the user lost, encourage them to play again.
- If the user quit, print their inventory and hint they may need to find the various equipment pieces.
Extra Credit
There are several extensions you can add in:
- After defeating an enemy, discover a random amount of gold. Track the hero's total gold.
- Add a room to find armor, which halves the amount of damage taken by an enemy.
- At the start of the game, allow the user to select the game difficulty. The higher the difficulty, the more rooms that can be randomly generated. For example:
- Easy - 10 rooms
- Medium - 25 rooms
- Hard - 50 rooms
- Insane - 100 rooms
- Except for the exit room, do not allow a room to be visited more than once. If the user decides not to pick up the key, weapon, or armor then they should be allowed to revisit that room. If they pick it up, then they can't return.
Sample Game Output
Below is a sample running of the game (with all the extensions implemented):
% ./A2
Difficulties:
(1) Easy
(2) Medium
(3) Hard
(4) Insane
Select game difficulty: 8
Select game difficulty: 1
You continue deeper into the dungeon, this time exploring Room #4
You enter room #4. You have 100HP, Key = No, Weapon = No, Armor = No, Gold = 0GP
A fountain flows in the middle of the room. Cautiously you take a drink.
You've restored 6HP.
Do you wish to continue exploring? (Y/N): Y
You continue deeper into the dungeon, this time exploring Room #10
You enter room #10. You have 106HP, Key = No, Weapon = No, Armor = No, Gold = 0GP
You look around, there's nothing here
Do you wish to continue exploring? (Y/N): d
Do you wish to continue exploring? (Y/N): y
You continue deeper into the dungeon, this time exploring Room #7
You enter room #7. You have 106HP, Key = No, Weapon = No, Armor = No, Gold = 0GP
You appear to be in what was once an armory of sorts. There are many broken weapons and shields scattered about.
Mounted upon the wall is the mighty sword Excalibur. Do you wish to take it with you? (Y/N): n
You hope you don't regret that choice.
Do you wish to continue exploring? (Y/N): Y
You continue deeper into the dungeon, this time exploring Room #2
You enter room #2. You have 106HP, Key = No, Weapon = No, Armor = No, Gold = 0GP
There's a monster with 21HP in here! Battle ensues!
You punch the beast dealing 1 damage.
The beast beats you dealing 10 damage.
You punch the beast dealing 1 damage.
The beast beats you dealing 7 damage.
You punch the beast dealing 4 damage.
The beast beats you dealing 9 damage.
You punch the beast dealing 1 damage.
The beast beats you dealing 6 damage.
You punch the beast dealing 3 damage.
The beast beats you dealing 9 damage.
You punch the beast dealing 1 damage.
The beast beats you dealing 5 damage.
You punch the beast dealing 4 damage.
The beast beats you dealing 5 damage.
You punch the beast dealing 5 damage.
The beast beats you dealing 6 damage.
You punch the beast dealing 3 damage.
The beast beats you dealing 9 damage.
You have slain the enemy and found 16GP.
Do you wish to continue exploring? (Y/N): y
You continue deeper into the dungeon, this time exploring Room #7
You enter room #7. You have 40HP, Key = No, Weapon = No, Armor = No, Gold = 16GP
You appear to be in what was once an armory of sorts. There are many broken weapons and shields scattered about.
Mounted upon the wall is the mighty sword Excalibur. Do you wish to take it with you? (Y/N): y
You instantly feel more powerful.
Do you wish to continue exploring? (Y/N): y
You continue deeper into the dungeon, this time exploring Room #5
You enter room #5. You have 40HP, Key = No, Weapon = Yes, Armor = No, Gold = 16GP
There's a massive locked gate blocking your way.
Perhaps you need to find a key somewhere?
Do you wish to continue exploring? (Y/N): y
You continue deeper into the dungeon, this time exploring Room #3
You enter room #3. You have 40HP, Key = No, Weapon = Yes, Armor = No, Gold = 16GP
There doesn't seem to be much here, just a pile of things on the floor.
You notice something shiny in the corner. Do you wish to pick it up? (Y/N): y
You've found a key! Now to find what it goes to.
Do you wish to continue exploring? (Y/N): y
You continue deeper into the dungeon, this time exploring Room #8
You enter room #8. You have 40HP, Key = Yes, Weapon = Yes, Armor = No, Gold = 16GP
There's a monster with 32HP in here! Battle ensues!
You swing Excalibur dealing 13 damage.
The beast beats you dealing 10 damage.
You swing Excalibur dealing 11 damage.
The beast beats you dealing 10 damage.
You swing Excalibur dealing 12 damage.
The beast beats you dealing 8 damage.
You have slain the enemy and found 28GP.
Do you wish to continue exploring? (Y/N): y
You continue deeper into the dungeon, this time exploring Room #5
You enter room #5. You have 12HP, Key = Yes, Weapon = Yes, Armor = No, Gold = 44GP
There's a massive locked gate blocking your way.
You try the key you found earlier. It fits!
After visiting 9 rooms and finding 44GP, you have finally escaped alive!
A second run of the game with a different outcome is shown below:
% ./A2
Difficulties:
(1) Easy
(2) Medium
(3) Hard
(4) Insane
Select game difficulty: 3
You continue deeper into the dungeon, this time exploring Room #15
You enter room #15. You have 100HP, Key = No, Weapon = No, Armor = No, Gold = 0GP
You look around, there's nothing here
Do you wish to continue exploring? (Y/N): y
You continue deeper into the dungeon, this time exploring Room #25
You enter room #25. You have 100HP, Key = No, Weapon = No, Armor = No, Gold = 0GP
You look around, there's nothing here
Do you wish to continue exploring? (Y/N): y
You continue deeper into the dungeon, this time exploring Room #26
You enter room #26. You have 100HP, Key = No, Weapon = No, Armor = No, Gold = 0GP
There's a monster with 20HP in here! Battle ensues!
You punch the beast dealing 5 damage.
The beast beats you dealing 7 damage.
You punch the beast dealing 2 damage.
The beast beats you dealing 6 damage.
You punch the beast dealing 5 damage.
The beast beats you dealing 10 damage.
You punch the beast dealing 1 damage.
The beast beats you dealing 10 damage.
You punch the beast dealing 3 damage.
The beast beats you dealing 5 damage.
You punch the beast dealing 4 damage.
The beast beats you dealing 8 damage.
You have slain the enemy and found 24GP.
Do you wish to continue exploring? (Y/N): n
After visiting 3 rooms and finding 24GP, you have given up, forever destined to wander the dungeon.
Maybe you will some day find the key to unlock the gate.
Perhaps a sword could make the escape quicker.
Perhaps you would have stayed longer with some armor.
Grading Rubric
Your submission will be graded according to the following rubric:
Points | Requirement Description |
0.5 | Submitted correctly by Tuesday, September 30, 2025, 11:59 PM |
0.5 | Project builds without errors nor warnings. |
2.0 | Best Practices and Style Guide followed. |
0.5 | Program follows specified user I/O flow. |
0.5 | Public and private tests successfully passed. |
2.0 | Fully meets specifications. |
6.00 | Total Points |
Extra Credit Points | Requirement Description |
+0.1 | +0.1 for each extension fully & correctly implemented |
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.
Zip together your main.cpp, samodelkin.h, samodelkin.cpp, Makefile
files and name the zip file A2_USERNAME.zip
. Upload this zip file to Canvas under A2.
→This assignment is due by Tuesday, September 30, 2025, 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.←