Question
Programming Task 1: The Creature Class The getDamage() method outputs and returns the damage this creature can inflict in one round of combat. The rules
Programming Task 1: The Creature Class
The getDamage() method outputs and returns the damage this creature can inflict in one round of combat. The rules for calculating the damage are as follows:
-Every creature inflicts damage that is a random number r, where 0 hit points.
-Demons have a 5% chance of inflicting a demonic attack, which is an additional 50 damage points. Balrogs and Cyberdemons are demons.
-Elves have a 10% chance to inflict a magical attack that doubles the normal amount of damage.
-Balrogs are very fast, so they get to attack twice.
Programming Task 2: The Game Program
The game has two phases:
1.Add each player to the game as a Creature object; each player enters their name and selects their species Any number of players can be added to a game (an partially-filled array or (better) a (java.util.)ArrayList of Creatures would work perfectly for this)
2.Each player plays in turn; for each turn a player may:
i.Attack another player: The player entes The damage points are subtracted from the attacked opponent's strength If that opponent's strength is then 0, the opponent is dead and is removed from the game
ii.Pass their turn to the next player
iii.Quit the game
The second phase keeps going until only one player is left; that player is the winner.
Sample Run (user input in red):
Welcome to the Fantasy Game 1. Add the game players 2. Players play in turn until only one is left Good Luck! First, let's add some players: Enter player's name ('quit' when no more players): Grue Grue, which species are you? b/B: Balrog c/C: Cyberdemon e/E: Elf h/H: Human Select Grue's species: b Enter player's name ('quit' when no more players): Tesserac Tesserac, which species are you? b/B: Balrog c/C: Cyberdemon e/E: Elf h/H: Human Select Tesserac's species: c Enter player's name ('quit' when no more players): Legolas Legolas, which species are you? b/B: Balrog c/C: Cyberdemon e/E: Elf h/H: Human Select Legolas's species: e Enter player's name ('quit' when no more players): John John, which species are you? b/B: Balrog c/C: Cyberdemon e/E: Elf h/H: Human Select John's species: h Enter player's name ('quit' when no more players): quit Current Players: NAME | SPECIES | STRENGTH | HIT POINTS Grue | Balrog | 82 | 15 Tesserac | Cyberdemon | 61 | 13 Legolas | Elf | 43 | 11 John | Human | 109 | 11 The Players are ready! Let the Battle begin! Grue, select one of the following options: a/A: Attack an opponent p/P: Pass (go to the next player) q/Q: Quit the game Grue, make your selection: a Which player are you attacking? John Current Players: NAME | SPECIES | STRENGTH | HIT POINTS Grue | Balrog | 82 | 15 Tesserac | Cyberdemon | 61 | 13 Legolas | Elf | 43 | 11 John | Human | 82 | 11 Tesserac, select one of the following options: a/A: Attack an opponent p/P: Pass (go to the next player) q/Q: Quit the game Tesserac, make your selection: a Which player are you attacking? Grue Current Players: NAME | SPECIES | STRENGTH | HIT POINTS Grue | Balrog | 80 | 15 Tesserac | Cyberdemon | 61 | 13 Legolas | Elf | 43 | 11 John | Human | 82 | 11 Legolas, select one of the following options: a/A: Attack an opponent p/P: Pass (go to the next player) q/Q: Quit the game Legolas, make your selection: a Which player are you attacking? Grue Current Players: NAME | SPECIES | STRENGTH | HIT POINTS Grue | Balrog | 56 | 15 Tesserac | Cyberdemon | 61 | 13 Legolas | Elf | 43 | 11 John | Human | 82 | 11 John, select one of the following options: a/A: Attack an opponent p/P: Pass (go to the next player) q/Q: Quit the game John, make your selection: a Which player are you attacking? Legolas Current Players: NAME | SPECIES | STRENGTH | HIT POINTS Grue | Balrog | 56 | 15 Tesserac | Cyberdemon | 61 | 13 Legolas | Elf | 3 | 11 John | Human | 82 | 11 Grue, select one of the following options: a/A: Attack an opponent p/P: Pass (go to the next player) q/Q: Quit the game Grue, make your selection: a Which player are you attacking? Legolas Sorry, Legolas, but you are dead. Thanks for playing! Current Players: NAME | SPECIES | STRENGTH | HIT POINTS Grue | Balrog | 56 | 15 Tesserac | Cyberdemon | 61 | 13 John | Human | 82 | 11 Tesserac, select one of the following options: a/A: Attack an opponent p/P: Pass (go to the next player) q/Q: Quit the game Tesserac, make your selection: a Which player are you attacking? John Current Players: NAME | SPECIES | STRENGTH | HIT POINTS Grue | Balrog | 56 | 15 Tesserac | Cyberdemon | 61 | 13 John | Human | 35 | 11 John, select one of the following options: a/A: Attack an opponent p/P: Pass (go to the next player) q/Q: Quit the game John, make your selection: a Which player are you attacking? Tesserac Current Players: NAME | SPECIES | STRENGTH | HIT POINTS Grue | Balrog | 56 | 15 Tesserac | Cyberdemon | 29 | 13 John | Human | 35 | 11 Grue, select one of the following options: a/A: Attack an opponent p/P: Pass (go to the next player) q/Q: Quit the game Grue, make your selection: a Which player are you attacking? Tesserac Sorry, Tesserac, but you are dead. Thanks for playing! Current Players: NAME | SPECIES | STRENGTH | HIT POINTS Grue | Balrog | 56 | 15 John | Human | 35 | 11 John, select one of the following options: a/A: Attack an opponent p/P: Pass (go to the next player) q/Q: Quit the game John, make your selection: a Which player are you attacking? Grue Current Players: NAME | SPECIES | STRENGTH | HIT POINTS Grue | Balrog | 45 | 15 John | Human | 35 | 11 Grue, select one of the following options: a/A: Attack an opponent p/P: Pass (go to the next player) q/Q: Quit the game Grue, make your selection: a Which player are you attacking? John Current Players: NAME | SPECIES | STRENGTH | HIT POINTS Grue | Balrog | 45 | 15 John | Human | 9 | 11 John, select one of the following options: a/A: Attack an opponent p/P: Pass (go to the next player) q/Q: Quit the game John, make your selection: a Which player are you attacking? Grue Current Players: NAME | SPECIES | STRENGTH | HIT POINTS Grue | Balrog | 41 | 15 John | Human | 9 | 11 Grue, select one of the following options: a/A: Attack an opponent p/P: Pass (go to the next player) q/Q: Quit the game Grue, make your selection: a Which player are you attacking? John Sorry, John, but you are dead. Thanks for playing! Grue, you are the only remaining player: You Won! Thanks for playing!
Creature int strength - int hitPoints - String name - String species strength and hitPoints variables should each be set to O at declaration name and species variables should each be set to " (empty string) at declaration Neither int variable can ever be negative species must only be one of Balrog, Cyberdemon, Elf, Human) String getSpecies0 +init(String newName, String newSpecies, int newStrength, int newHit) throws lllegalArgumentException + void setStrength(int newStrength) throws llegalArgumentException +int getStrengthO + void setHitPoints(int newHit) throws legalArgumentException +int getHitPoints0 Damage0 function subtracts the givern +int getDamageO + void Damage(int damage) throws lllegalArgumentException +boolean isDead( damage from the strength strength is always >= 0 (i.e., if strength =:0) matches the given name isDead) indicates if the creature is dead + String getName0 + boolean isNamed(String aName) isNamed) indicates if the creature's nameStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started