Lab 7
Start Now

Overview

For this assignment, you will implement the class described by the UML diagram below along with a game that makes use of objects from the class.

Assignment

Prior to the end of lab you must have the Die class completely implemented. The Die class represents a die with a specified number of sides (selected by passing an integer to the constructor). The die must have at least two sides and no more than 100. If no value is passed or if a value outside of this range is attempted, the die should default to having twenty sides. The roll method must return an integer between one and the number of sides the die has, chosen at random. For example, for a six sided die, the method must return one of the following values with equal likelihood: 1, 2, 3, 4, 5, or 6.

The UML class diagram for the Die class is shown below.

Die
- numberOfSides
+ Die()
+ Die(numberOfSides: int)
+ roll(): int

Battle Simulator 3000

The program simulates an epic battle between a Valiant Warrior (human player) and an evil Mugwump (computer player). Using rules from some generic tabletop game, the player will attempt to vanquish the evil scourge and save the kingdom.

Running the Program

When the program begins and after each battle completes you will ask the user if they would like to battle.

  • They should be able to enter any of the following to indicate yes: y, Y, yes, and Yes.
  • If they do not enter any of the above, the game should exit.

A battle consists of a sequence of attacks which alternate between the two combatants.

Starting a Battle

Each player begins with a number of Hit Points. As long as the player has a positive number of Hit Points, she or he has not lost the battle.

  • The Valiant Warrior uses six 10-sided dice (d10) to calculate his or her starting Hit Points.
  • The Mugwump uses ten d10 to calculate his or her starting Hit Points.

The battle consists of a number of attack rounds.

An Attack Round

Each attack round consists of an opportunity for each player to mount an attack (unless the second attacker is eliminated prior to his or her turn). To determine the first attacker for the round, both the Mugwump and the Valiant Warrior will roll a d10. Whoever rolls higher gets to attack first. In the case of a tie, both re-roll.

The attacker chooses an attack strategy and attempts to hit his or her opponent by rolling the die. If a hit is made, she or he rolls the appropriate die/dice to determine the damage, and then deducts that damage from the opponent's Hit Points.

The Valiant Warrior has two possible attacks: His Trusty Sword and his or her Shield of Light. The user must decide which to use in each attack.

  • His Trusty Sword hits the Mugwump on a roll of 12 or greater on a 20-sided die (d20) and rolls two 8-sided dice (d8) for damage.
  • His Shield of Light hits the Mugwump on a roll of 8 or greater on a d20 and rolls a 4-sided die (d4) for damage.

The evil Mugwump also has two possible attacks: His Razor-Sharp Claws and his or her Fangs of Death.

  • His Razor-Sharp Claws hit on a roll of 12 or greater on a d20 and rolls two 6-sided dice (d6) for damage. The Mugwump uses this attack 75% of the time.
  • His Fangs of Death hit on a roll of 16 or greater on a d20 and rolls three d6 for damage. The Mugwump uses this attack 15% of the time.

If the Mugwump does not use either of his or her attacks, she or he licks his or her wounds and heals himself! Roll one d6 and add the result to the Mugwump's Hit Points, not exceeding his or her starting Hit Points.

After each attack, the attack strategy, resulting damage (or healing), and the Hit Points remaining for each combatant must be displayed.

Battle End

The battle ends when one combatant's Hit Points goes to zero below or below

  • If the Valiant Warrior succeeds, an appropriately exultant message is displayed.
  • If the Valiant Warrior fails, she or he is mocked by the evil Mugwump.

Lab Deliverables

See your professor's instructions for details on submission guidelines and due dates.
Prof. Contino's class: See Blackboard
Prof. Jones' class: See Blackboard
See Dr. Dennis for instructions
Dr. Riley's class: See Blackboard
Dr. Taylor's class: See below
See Prof. Thomas for instructions
If you have any questions, consult your instructor.

Acknowledgement

This laboratory assignment was developed by Prof. Sean Jones.

Monday, 17-Oct-2016 10:08:28 EDT