CSCI 200 - Spring 2025
Foundational Programming Concepts & Design

A1 - Random Encounter RPG

→This assignment is due by Thursday, January 23, 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


Assignment Code Starter


Make sure you have the appropriate comment header block at the top of every assignment from this point forward. The header block should include the following information at a minimum.

/* CSCI 200: Assignment 1: A1 - Random Encounter RPG
 *  * 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)  */ // The include section adds extra definitions from the C++ standard library. #include <iostream> // For cin, cout, etc. // We will (most of the time) use the standard library namespace in our programs. using namespace std; // Define any constants below this comment. // Must have a function named "main", which is the starting point of a C++ program. int main() { /******** INSERT YOUR CODE BELOW HERE ********/ cout << "Hello world!" << endl; // print Hello world! to the screen /******** INSERT YOUR CODE ABOVE HERE ********/ return 0; // signals the operating system that our program ended OK. }

Random Encounters


Zoinks your trapped in Zork!

Your goal for this assignment is to create a simplified text-based adventure where our Hero randomly encounters different types of baddies and has various success gaining loot or running away. This will be simulated through a series of die rolls and user decisions.

Stay or Go?

The first step is to allow the user the option to keep exploring or leave our infinite universe. Begin by asking the user if they wish to move to the next room or not. If the user enters Y or y then reprompt them until they choose N or n. When they opt to exit, tell them the game is over. At this point, your program should look as follows:

Do you wish to move to the next room? (y/n) Y

Do you wish to move to the next room? (y/n) y

Do you wish to move to the next room? (y/n) n

You finished.

We will assume we have a smart user that will follow instructions and enter the expected inputs. That is, we can trust the user will enter one of Y, y, N, or n.

The Dice

The next step is to properly set up a Mersenne Twister and uniform distributions that correspond to different dice. We will need to simulate the following different types of dice:

Each of these dice will be referenced by their type and will be used in different scenarios. We'll first use the D6 every time we enter a new room. Roll the D6 (e.g. generate a random number from the D6 distribution). If the result is 1, 2, 4, or 5, then print There's an enemy in the room!. Otherwise, if the result is 3 or 6, then print You slip through the room.. Test moving through rooms and sometimes encountering an enemy. A sample run could look like:

You slip through the room.
Do you wish to move to the next room? (y/n) Y

There's an enemy in the room!
Do you wish to move to the next room? (y/n) y

There's an enemy in the room!
Do you wish to move to the next room? (y/n) y

There's an enemy in the room!
Do you wish to move to the next room? (y/n) y

You slip through the room.
Do you wish to move to the next room? (y/n) Y

There's an enemy in the room!
Do you wish to move to the next room? (y/n) N

You finished.

It may be helpful to also print the value of the die roll to confirm you are meeting enemies or not based on the correct conditions.

Which Enemy?

Our D8 die will determine which enemy we encounter. The following die rolls correspond to the different enemies:

  1. Orc
  2. Goblin
  3. Dragon
  4. Orc
  5. Goblin
  6. Dragon
  7. Orc
  8. Goblin

Print which enemy has been encountered inside the room.

You slip through the room.
Do you wish to move to the next room? (y/n) Y

There's an enemy in the room!
You encounter a dragon.
Do you wish to move to the next room? (y/n) y

There's an enemy in the room!
You encounter an orc.
Do you wish to move to the next room? (y/n) y

There's an enemy in the room!
You encounter an orc.
Do you wish to move to the next room? (y/n) y

You slip through the room.
Do you wish to move to the next room? (y/n) Y

There's an enemy in the room!
You encounter a goblin.
Do you wish to move to the next room? (y/n) N

You finished.

Fight or Flee?

When encountering an enemy, our Hero must choose what to do. Do you (f)ight or (r)un away? Prompt the user to make their choice:

You slip through the room.
Do you wish to move to the next room? (y/n) Y

There's an enemy in the room!
You encounter a dragon.
    Do you wish to (f)ight or (r)un? 

Again, we will assume the user will enter one of F, f, R, or r.

The success of each action depends on the enemy and its corresponding die. The following decision tree will determine the hero's fate:

Be sure to inform the user what they need to roll to succeed before they make their. Inform them of the result. If they defeated the enemy or escaped, then ask the user if they wish to continue to another room. If they were defeated by the enemy or were caught during escape, then end the game.

Additionally, keep track of how many total enemies the Hero has slain. When the program ends, inform the user of their total.

At this point our program will have the following outcomes:

Hero Defeats Enemy
There's an enemy in the room!
You encounter a dragon.
    Roll a D20 greater than 16 to win or less than 17 to run.
    Do you wish to (f)ight or (r)un? f
Your D20 rolls a 18
    You slayed the dragon!

Do you wish to move to the next room? (y/n) n

You finished and killed 1 enemies.
Hero Loses To Enemy
There's an enemy in the room!
You encounter a dragon.
    Roll a D20 greater than 16 to win or less than 17 to run.
    Do you wish to (f)ight or (r)un? f
Your D20 rolls a 3
    The dragon gobbled you up.  Game Over.

You finished and killed 0 enemies.
Hero Escapes From Enemy
There's an enemy in the room!
You encounter a dragon.
    Roll a D20 greater than 16 to win or less than 17 to run.
    Do you wish to (f)ight or (r)un? r
Your D20 rolls a 3
    You escaped the dragon's lair.

Do you wish to move to the next room? (y/n) n

You finished and killed 0 enemies.
Hero Caught By Enemy
There's an enemy in the room!
You encounter a dragon.
    Roll a D20 greater than 16 to win or less than 17 to run.
    Do you wish to (f)ight or (r)un? r
Your D20 rolls a 19
    The dragon's flame burns you to a crisp.  Game Over.

You finished and killed 0 enemies.

Grab the Loot

The final step is gather the loot upon vanquishing an enemy. If the enemy has been defeated, then award the following amount to the Hero:

Additionally, if the Hero moves into a room with no enemy, then award them with 1 piece of loot that they find laying on the ground.

As the Hero progresses through the dungeon, keep track of the total amount of loot gained. If at any point the Hero has 100 loot or more, then end the game victoriously! The game can now end one of three ways:

When the program ends, inform the user of the following information:

  1. If they won or lost
  2. How much loot they gathered
  3. How many enemies they killed

A full sample run of the program may look as follows:

There's an enemy in the room!
You encounter an orc.
        Roll a D8 greater than 1 to win.
        Roll a D8 less than 8 to escape.
        Do you wish to (f)ight or (r)un? > f
Your D8 rolls a 5
        You killed the orc!
        You take 3 gold coins from the orc's treasure chest.
Do you wish to move to the next room? (y/n) y

There's an enemy in the room!
You encounter a dragon.
        Roll a D20 greater than 16 to win.
        Roll a D20 less than 16 to escape.
        Do you wish to (f)ight or (r)un? > r
Your D20 rolls a 2
        You escaped the dragon's lair.
Do you wish to move to the next room? (y/n) y

You slip through the room and find a gold coin.
Do you wish to move to the next room? (y/n) y

There's an enemy in the room!
You encounter a goblin.
        Roll a D12 greater than 3 to win.
        Roll a D12 less than 11 to escape.
        Do you wish to (f)ight or (r)un? > f
Your D12 rolls a 1
        The goblin slays you with his sword.  Game Over.

You finished with 4 gold coins and killed 1 enemies.

Congrats! We've now fully finished our RPG! See how few enemies you can kill to win the game.

Complete the Technical Build Process

Now that the program is working, be sure you have set up the build process correctly and have created a Makefile to use with the build. When you build your program, you need to be using a Makefile and make to compile and link your code. See the Submission section of the needed files to properly submit the assignment.

> make
g++ -o main.o -c main.cpp
g++ -o A1 main.o
> ./A1
There's an enemy in the room!

Extra Credit! Strength and Hit Points


For extra credit, expand your program to track the health of the Hero and each enemy. Each character in our game will start with the following health:

We'll also use uniform distributions to simulate the damage inflicted by each character. Each character has the following damage ranges:

When the Hero chooses to fight, the die roll now determines hit or miss. If the Hero hits, then the Hero does a random amount of damage to the enemy. If the Hero misses, then the enemy does a random amount of damage to the Hero. The battle continues until one of the character's health reaches zero. Good luck achieving victory now!

A sample run of the program could look like:

There's an enemy in the room!  You have 100 HP.
You encounter a goblin with 25 HP.
        Roll a D12 greater than 3 to hit.
        Roll a D12 less than 10 to escape.
        Do you wish to (f)ight or (r)un? > f
Your D12 rolls a 1
        You missed the goblin.  You're attacked for 10 and have 90 HP remaining
Your D12 rolls a 11
        You hit the goblin for 8 and it has 17 HP remaining
Your D12 rolls a 1
        You missed the goblin.  You're attacked for 5 and have 85 HP remaining
Your D12 rolls a 3
        You missed the goblin.  You're attacked for 6 and have 79 HP remaining
Your D12 rolls a 12
        You hit the goblin for 13 and it has 4 HP remaining
Your D12 rolls a 8
        You hit the goblin for 14 and it has 0 HP remaining
        You killed the goblin!
        You take 11 gold coins from the goblin's purse.
You have 11 gold coins, do you wish to move to the next room? (y/n) y

You slip through the room and find a gold coin.
You have 12 gold coins, do you wish to move to the next room? (y/n) y

There's an enemy in the room!  You have 79 HP.
You encounter a dragon with 50 HP.
        Roll a D20 greater than 16 to hit.
        Roll a D20 less than 16 to escape.
        Do you wish to (f)ight or (r)un? > f
Your D20 rolls a 14
        You missed the dragon.  You're attacked for 15 and have 64 HP remaining
Your D20 rolls a 1
        You missed the dragon.  You're attacked for 14 and have 50 HP remaining
Your D20 rolls a 3
        You missed the dragon.  You're attacked for 11 and have 39 HP remaining
Your D20 rolls a 17
        You hit the dragon for 7 and it has 43 HP remaining
Your D20 rolls a 20
        You hit the dragon for 11 and it has 32 HP remaining
Your D20 rolls a 8
        You missed the dragon.  You're attacked for 15 and have 24 HP remaining
Your D20 rolls a 17
        You hit the dragon for 12 and it has 20 HP remaining
Your D20 rolls a 7
        You missed the dragon.  You're attacked for 13 and have 11 HP remaining
Your D20 rolls a 17
        You hit the dragon for 8 and it has 12 HP remaining
Your D20 rolls a 6
        You missed the dragon.  You're attacked for 12 and have 0 HP remaining
        The dragon gobbled you up.  Game Over.

You lost with 12 gold coins and killed 1 enemies.

Grading Rubric


Your submission will be graded according to the following rubric:

PointsRequirement Description
0.5Submitted correctly by Thursday, January 23, 2025, 11:59 PM
0.5Project builds without errors nor warnings.
2.0Best Practices and Style Guide followed.
0.5Program follows specified user I/O flow.
0.5Public and private tests successfully passed.
2.0Fully meets specifications.
6.00Total Points

Extra Credit PointsRequirement Description
+1.0 Health and Damage extension added in


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, Makefile files and name the zip file A1.zip. Upload this zip file to Canvas under A1.


→This assignment is due by Thursday, January 23, 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.←