CSCI 200 - Summer 2023
Foundational Programming Concepts & Design

Lab 2C - Samodelkin Battle Simulator

This lab is due by Saturday, May 27, 2023, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.


Classes


For this lab, you will create the following Die and Player classes as outlined in the following UML diagram. More details on the makeup of each class are given below. Recall that a minus symbol - denotes a private member while a plus symbol + denotes a public member. Be sure to follow the style guide and naming scheme as appropriate. We want to be following the separation of private data members and public member functions that provide access as appropriate to the underlying data members.

Die & Player UML

The diamond arrow in the UML diagram denotes an "association." Since the Player class holds an instance of a Die object, the arrow points to the structure of the corresponding Die class. This arrow comes out of the side of the box to denote this dependency upon another class.


Die Class


The Die class will be used to simulate the process of a random die roll. A description of each class member is given below:

To test that your Die class is working properly, in main() create a D6 object for a Die with six sides. In a loop, print the result of ten rolls. These values should all be different within the range of one to six.

Then create a D20 object for a Die with twenty sides. In a loop, print the result of ten rolls. These values should all be different within the range of one to twenty.

When you are satisfied with the performance of your random die, remove these testing loops from main() and continue with the next class.


Player Class


The Player class will be used to represent the characters in our Samodelkin battle simulation. They will roll a number of dice to determine their attack strength. A description of each class member is given below:


Steps for main()


Now in main(), implement the following program flow to simulate a battle for the ages:

  1. Create a Player object whose name is Gandalf, has 100 health, is blessed, and rolls three four-sided dice.
  2. Create a Player object whose name is Balrog, has 150 health, is not blessed, and rolls two eight-sided dice.
  3. While both players are still alive
    1. Have Gandalf attack the Balrog
    2. Print how much damage Gandalf dealt
    3. If the Balrog is still alive, then
      1. Have the Balrog attack Gandalf
      2. Print how much damage the Balrog dealt
  4. If Gandalf is still alive, then print Gandalf has vanquished Balrog
  5. Else if the Balrog is still alive, then print Balrog has vanquished Gandalf

A sample run of the program is given below:

Gandalf attacks Balrog dealing 8 damage
Balrog counterattacks Gandalf dealing 11 damage
Gandalf attacks Balrog dealing 8 damage
Balrog counterattacks Gandalf dealing 7 damage
Gandalf attacks Balrog dealing 14 damage
Balrog counterattacks Gandalf dealing 12 damage
Gandalf attacks Balrog dealing 9 damage
Balrog counterattacks Gandalf dealing 10 damage
Gandalf attacks Balrog dealing 12 damage
Balrog counterattacks Gandalf dealing 3 damage
Gandalf attacks Balrog dealing 8 damage
Balrog counterattacks Gandalf dealing 10 damage
Gandalf attacks Balrog dealing 10 damage
Balrog counterattacks Gandalf dealing 14 damage
Gandalf attacks Balrog dealing 11 damage
Balrog counterattacks Gandalf dealing 10 damage
Gandalf attacks Balrog dealing 16 damage
Balrog counterattacks Gandalf dealing 10 damage
Gandalf attacks Balrog dealing 8 damage
Balrog counterattacks Gandalf dealing 16 damage
Balrog has vanquished Gandalf

As well as the other possible outcome:

Gandalf attacks Balrog dealing 10 damage
Balrog counterattacks Gandalf dealing 6 damage
Gandalf attacks Balrog dealing 6 damage
Balrog counterattacks Gandalf dealing 15 damage
Gandalf attacks Balrog dealing 9 damage
Balrog counterattacks Gandalf dealing 4 damage
Gandalf attacks Balrog dealing 16 damage
Balrog counterattacks Gandalf dealing 6 damage
Gandalf attacks Balrog dealing 14 damage
Balrog counterattacks Gandalf dealing 4 damage
Gandalf attacks Balrog dealing 7 damage
Balrog counterattacks Gandalf dealing 15 damage
Gandalf attacks Balrog dealing 20 damage
Balrog counterattacks Gandalf dealing 9 damage
Gandalf attacks Balrog dealing 22 damage
Balrog counterattacks Gandalf dealing 8 damage
Gandalf attacks Balrog dealing 20 damage
Balrog counterattacks Gandalf dealing 6 damage
Gandalf attacks Balrog dealing 6 damage
Balrog counterattacks Gandalf dealing 4 damage
Gandalf attacks Balrog dealing 16 damage
Balrog counterattacks Gandalf dealing 9 damage
Gandalf attacks Balrog dealing 9 damage
Gandalf has vanquished Balrog

Lab Submission


Submit your main.cpp, Die.h, Die.cpp, Player.h, Player.cpp, Makefile file(s).

You will submit your solution to this lab with the rest of Set2. Detailed instructions for doing this are posted in Assignment 2.


This lab is due by Saturday, May 27, 2023, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.