weight = 17

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.

Resources

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 a value outside of this range is attempted, the die should default to having six sides. The current value of the die should be set to an integer between one and the number of sides the die has, chosen at random when the die object is constructed and whenever the roll() method is called. For example, for a six sided die, the current value must be set to one of the following values with equal likelihood: 1, 2, 3, 4, 5, or 6.

The UML class diagram for the Die class, as well as the other classes required for your assignment, are shown below.

[](lab7.png)

Your code must conform to the design specified in the UML class diagram above; however, you may add additional attributes and methods to the classes as long as they are declared as private. You should use the following files as a starting point: BattleSim.java and Mugwump.java.

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.

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 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 or her Trusty Sword and his or her Shield of Light. The user must decide which to use in each attack.

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

If the Mugwump does not use either of his or her attacks, she or he licks his or her wounds and heals himself or herself! 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

Repeating Play

After each battle completes you will ask the user if they would like to battle.

Sample Run

Welcome to Battle Simulator 3000! The world's more low tech battle simulator!
You are a Valiant Warrior defending your humble village from an evil Mugwump! Fight bravely, 
or the citizens of your town will be the Mugwump's dinner!

You have your Trusty Sword, which deals decent damage, but can be tough to hit with sometimes. 
You also have your Shield of Light, which is not as strong as your sword, but is easier to deal 
damage with.

Let the epic battle begin!

Warrior HP: 29
Mugwump HP 71

The Mugwump attacks first!
The Mugwump snaps at you and misses!
How would you like to attack?
1. Your Trusty Sword
2. Your Shield of Light
Enter choice: 1
You swing your sword and miss the foul creature!
Warrior HP: 29
Mugwump HP 71
.
.
.
Warrior HP: 2
Mugwump HP 1

The Warrior attacks first!
How would you like to attack?
1. Your Trusty Sword
2. Your Shield of Light
Enter choice: 2
You hit the Mugwump with your Shield of Light for 2 points of damage!

The citizens cheer and invite you back to town for a feast as thanks for saving their lives (again)!

Would you like to play again? (yes/no)
no
Thank you for playing Battle Simulator 3000!

Acknowledgement

This laboratory assignment was developed by Prof. Sean Jones.

See your professor's instructions for details on submission guidelines and due dates.