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.
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 6.
Die |
---|
- numSides: int {readOnly} - currentValue: int - generator: Random {readOnly} |
+ 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): String - report(warrior: Warrior, mugwump: Mugwump, order: int): void - actionChoice(in: Scanner): int - initiative(): int - victory(victor: String): void - playAgain(in: Scanner): boolean |
Warrior |
---|
- hitPoints: int - armorValue: int {readOnly} - d100: Die {readOnly} - d20: Die {readOnly} - d12: Die {readOnly} - d10: Die {readOnly} - d8: Die {readOnly} - temporaryHitPoints: int |
+ Warrior(numHitPointsDice: int, armorValue: int) + getHitPoints(): int + getArmorValue(): int + takeDamage(damage: int): void + action(mugwump: Mugwump): void + status(): String - ai(): int - setInitialHitPoints(numDice: int): int |
Mugwump |
---|
- hitPoints: int - maximumHP: int {readOnly} - armorValue: int {readOnly} - d100: Die {readOnly} - d20: Die {readOnly} - d10: Die {readOnly} - d8: Die {readOnly} |
+ Mugwump(numHitPointsDice: int, armorValue: int) + getHitPoints(): int + getArmorValue(): int + takeDamage(damage: int): void + action(warrior: Warrior): void + status(): String - 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 and JavaDoc
comments for several of these classes.
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 Warrior
classes 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 two characters: a Guardian Mugwump (human player) and an Aspiring Warrior (computer player). Using rules from some generic tabletop game, the player will attempt to defeat the Aspiring Warrior and prevent them from entering a dangerous dungeon.
A battle consists of a sequence of attacks which alternate between the two combatants.
Starting a Battle
Each character begins with a number of Hit Points. As long as a character has a positive number of Hit Points, they have not lost the battle.
The battle consists of a number of rounds. Before the first round, each character roles an initiative die (d10) that determines their order (first or second) in the battle. In the case of a tie, re-roll. This order is fixed for the every round in the battle and does not change.
Actions Per Round
Each round, whoever goes first, as determined by the initial initiative roll, gets to perform an action. Depending on the character that action could be attacking, gaining temporary hit points, or healing. Once the first character is done, if the neither character is defeated, (i.e., hit points less than or equal to zero) the second character gets to perform an action. The round finishes after the second character goes. After each action, a brief description of the action and resulting damage (or healing) is displayed. After each round the remaining Hit Points and Temporary Hit Points for each character must be displayed.
If a character chooses to attack as their action, they first attempt to hit their opponent. The character rolls a d20 and adds the hit modifier of the attack they are using and compares that to their opponent's armor value. If the value they rolled plus the modifier is greater than or equal to the opponent's armor value, the attack hits. 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 crash-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, either themselves or the opponent.
If a character can give themselves temporary hit points, those temporary hit points act as a buffer for their actual hip points. When the character takes damage, their temporary hit points, if any, are reduced first. If the temporary hit points are reduced to zero, any remaining damage is applied to the actual hit points. Temporary hit points do not stack, so any new application of temporary hit points overwrites any existing temporary hit points.
If a character can heal, they gain hit points up to their maximum hit points.
Characters
Mugwump
The Guardian Mugwump has an armor value of 14 and an initial hit points of 6d10. They have three possible actions: Razor-Sharp Claws, Vampiric Fangs, and Meditative Stance.
- Razor-Sharp Claws has a +4 hit modifier and does 2d8 of damage on a hit.
- Vampiric Fangs has a +6 hit modifier. On a hit, it does 1d12 of damage to the opponent, and heals the Mugwump for half the amount of damage given rounded down, with a minimum of 1.
- Meditative Stance heals the Mugwump for 1d8 hit points.
The Mugwump is controlled by the human player.
Warrrior
The Aspiring Warrior has an armor value of 16 and an initial hit points of 4d10. They have three possible actions: Trusty Sword, Charge of Determination, and Rune of Protection.
- Trusty Sword has a +6 hit modifier and does 2d8 of damage on a hit.
- Charge of Determination has a -2 hit modifier. On a hit, this attack does 2d12 damage to the opponent and on a miss it does half of that to the Warrior round down, with a minimum of 1.
- Rune of Protection generates 1d12 temporary hit points for the Warrior.
The Aspiring Warrior is controlled by an AI. If they have no temporary hit points, they will activate their Rune of Protection 100% of the time. If they have temporary hit points, they use their Trusty Sword 35% of the time and do a Charge of Determination the remaining 65% of the time.
Battle End
The battle ends when one character's hit points goes to zero.
- If the Guardian Mugwump wins, they console the Warrior and tell them they need more training to proceed.
- If the Aspiring Warrior wins, they are congratulated by the Guardian Mugwump and allowed to proceed.
Repeating Play
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.
Sample Run
Welcome to Battle Simulator 3000! The world's most low tech battle simulator!
You are a Mugwump charged with guarding the entrance to an extremely dangerous
temple from foolhardy adventures who are unprepared for the challenges within.
One day you are challenged by an aspiring Warrior who wants to prove themselves
by delving into the dungeon and surviving its challenges.
You have your Razor-Sharp Claws, which deals decent damage, but can be
tough to hit with sometimes. You also have your Vampiric Fangs, which are
more accurate and not as damaging, but they heal you. Lastly, you can take
a moment to meditate and heal a modest amount of health.
The Warrior wins the initiative and will go first.
Let the epic battle begin!
==========Top of the Round==========
Warrior HP: 9(0)
Mugwump HP: 30
The Warrior touches the rune on their shield and now has 7 temporary hit points.
How would you like to act?
1. Your dexterous claws.
2. Your sharp fangs.
3. Meditative healing.
Enter choice: 1
You swipe your claws, but the Warrior narrowly avoids it!
==========Top of the Round==========
Warrior HP: 9(7)
Mugwump HP: 30
The Warrior charges with their shield and hits! You take 12 points of damage!
How would you like to act?
1. Your dexterous claws.
2. Your sharp fangs.
3. Meditative healing.
Enter choice: 2
You attempt to bite the Warrior, but they dodge just in time. Darn!!!
==========Top of the Round==========
Warrior HP: 9(7)
Mugwump HP: 18
The Warrior misses their charge and crashes into the ground receiving 8 damage.
How would you like to act?
1. Your dexterous claws.
2. Your sharp fangs.
3. Meditative healing.
Enter choice: 2
You bite down on the Warrior and inflict 4 points of damage! Yum!!!
You heal for 2 of hp.
==========Top of the Round==========
Warrior HP: 4(0)
Mugwump HP: 20
The Warrior touches the rune on their shield and now has 6 temporary hit points.
How would you like to act?
1. Your dexterous claws.
2. Your sharp fangs.
3. Meditative healing.
Enter choice: 2
You bite down on the Warrior and inflict 8 points of damage! Yum!!!
You heal for 4 of hp.
==========Top of the Round==========
Warrior HP: 2(0)
Mugwump HP: 24
The Warrior touches the rune on their shield and now has 2 temporary hit points.
How would you like to act?
1. Your dexterous claws.
2. Your sharp fangs.
3. Meditative healing.
Enter choice: 1
You swipe your claws, but the Warrior narrowly avoids it!
==========Top of the Round==========
Warrior HP: 2(2)
Mugwump HP: 24
The warrior swings their sword and hits! You take 12 points of damage!
How would you like to act?
1. Your dexterous claws.
2. Your sharp fangs.
3. Meditative healing.
Enter choice: 2
You attempt to bite the Warrior, but they dodge just in time. Darn!!!
==========Top of the Round==========
Warrior HP: 2(2)
Mugwump HP: 12
The Warrior misses their charge and crashes into the ground receiving 5 damage.
You defeat the Aspiring Warrior and tell them they fought well and valiantly,
but they are not ready and need to train more.
Would you like to play again? (yes/no)
no
Thank you for playing Battle Simulator 3000!
Acknowledgement
This laboratory assignment was originally developed by Prof. Sean Jones.