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.

Overview video

GitHub Classroom

Accept the assignment invitation from your instructor and create a new IntelliJ project from version control to clone the repository onto your computer.

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. Note: The Die class specified for this assignment is slightly different that the Die class specified in exercise 5.

Die
- numSides: int
- currentValue: int
- generator: Random
+ Die(numsides:int)
+ getCurrentValue(): int
+ roll(): void
BattleSim
- INITIATIVE_DIE: Die {readOnly} = new Die(10);
+ main(args: String[]): void
- intro(): void
-round(warrior:Warrior, mugwump: Mugwump, in: Scanner, order:int): String
- report(warrior: Warrior, mugwump: Mugwump, order: int, numRound: int): void
- actionChoice(in: Scanner): int
- initiative(): int
- victory(victor:String): void
- playAgain(in: Scanner): boolean
Warrior
- hitPoints: int
- d100: Die
- d20: Die
- d12: Die
- d10: Die
- d8: Die
- temporaryHitPoints: int
+ Warrior()
+ getHitPoints(): int
+ takeDamage(damage: int): void
+ action(mugwump: Mugwump): void
- ai(): int
- setInitialHitPoints(numDice: int): int
Mugwump
- hitPoints: int
- maximumHP: int
- d100: Die
- d20: Die
- d10: Die
- d8: Die
- d6: Die
- d4: Die
+ Mugwump()
+ getHitPoints(): int
+ takeDamage(damage: int): void
+ action(warrior: Warrior): void
- heal(healAmount: int): void
- setInitialHitPoints(numDice: int): int

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. The Git repository has starter code for several of these classes.

This assignment has several components to it and is more complicated that previous assignments. It is helpful to think about the problem at different levels of abstraction. We recommend that you read over the entire assignment carefully to understand the overall goal for the program. You may find it helpful to "play" the game with a partner to become familiar with the rules of the game. Then focus on particular aspects. For example, you may choose to develop the Die class first and then move on to the Mugwump class. A Playground class has been provided that is intended to help you verify that your implementation of the Mugwump and Warriorclasses are implemented correctly.

By building and testing each class incrementally, it will be easier build up to the final solution.

Battle Simulator 3000

The program simulates an epic battle between a Peaceful Mugwump (human player) and an arrogant Warrior (computer player). Using rules from some generic tabletop game, the player will attempt to vanquish the arrogant nuisance and continue on their way.

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, they have not lost the battle.

The battle consists of a number of attack rounds. Before the first round, each player roles an initiative die (d10) that determines their order (first or second) for every round in the battle. Whoever rolls higher gets to attack first. In the case of a tie, both re-roll.

An Attack Round

Each attack round, who ever goes first, as determined by the initial initiative roll, gets to perform an action. Depending on the character that action could be to attack, gain temporary hit points, or heal. Once the first character is done, if the second character is not defeated, (i.e., hit points less than or equal to zero) then they get to perform an action.

If a character attacks, they first attempt to hit their opponent. The character rolls a d20 and adds the hit modifier of whatever attack they are using and compares that to their opponent's armor value. If the value they rolled plus their modifier is greater than or equal to the opponent's armor value, the attack his. The character then rolls the appropriate die/dice to determine the damage amount and applies it to the opponent.

For some attacks there are secondary affects, such as healing or self-damage, that occur on a miss or a hit. A character would roll the appropriate die/dice for the affect and apply it to the appropriate target.

The Peaceful Mugwump has three possible actions: Their Razor-Sharp Claws, their Vampiric Fangs, and Meditative Stance.

The evil Mugwump also has two possible attacks: Their Razor-Sharp Claws and their Fangs of Death.

If the Mugwump does not use either of their attacks, they lick their wounds and heal themself! The amount of hit points to be restored is determined by rolling on d10; however, the total number of hit points for the Mugwump must not exceed the Mugwumps 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 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 51

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 51
.
.
.
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.