Question
(Wizard.java, Healer.java, Barbarian.java, HeroTester.java, Hero.java, Goblin.java) (15 marks) Consider the abstract hero class and the three subclasses shown below: UML Diagram: Where you are provided
(Wizard.java, Healer.java, Barbarian.java, HeroTester.java, Hero.java, Goblin.java) (15 marks) Consider the abstract hero class and the three subclasses shown below:
UML Diagram:
Where you are provided the Hero.java class which is as follows:
public abstract class Hero { private String name; private int health; /** * Argumented constructor * @param name Hero's name. */ public Hero(String name){ if(name == "" || name.length() == 0) this.name = "anonymous"; else this.name = name; this.health = 100; } /** * Accessor for health. * @return Hero's current health. */ public int getHealth() { return health; } /** * Accessor for Name * @return Hero's name. */ public String getName() { return name; } /** * Add to the hero's health. * @param addHealth how much health to add. */ public void heal(int addHealth){ this.health += addHealth; } /** * Hero takes damage from enemy. * @param damage how much damage to take. */ public void takeDamage(int damage){ this.health -= damage; if(health
You are also given the Goblin.java class, which you must use. It is as follows:
public abstract class Goblin { private int health; /** * Argumented constructor */ public Goblin(){ this.health = (int)(Math.random()*15)+45; } /** * Accessor for health. * @return Goblin's current health. */ public int getHealth() { return health; } /** * Goblin takes damage from enemy. * @param damage how much damage to take. */ public void takeDamage(int damage){ this.health -= damage; if(health
Review the hero class to see how it works (its in the project/package for you already). Your job is to implement the following subclasses. Each of the subclasses has an extra data field that relates to their specific hero talent. Some help with these special talents and other methods are below.
Fighter.java details:
-The fighter has an extra data field called Strength and a method called Berserk. When the fighter calls Berserk they do damage equal to 1/3 of their existing health BUT they lose 1/4 of their existing health (round to integer values). Using Berserk costs one Strength point. When a fighter is constructed they have 3 strength points.
-the dealDamage() method for the fighter does between 7 and 10 points of damage.
Magician.java details:
-The magician has an extra data field called Mana and a method called Lightning. When the magician calls Lightning the damage they inflict is quadruple (which means 4 times) what it would have been otherwise. Call the existing dealDamage function and quadruple the value before dealing it to the enemy. Using Lightning costs 1 Mana point and a magician has 4 Mana points to start with.
- the dealDamage() method for the magician does between 4 and 6 points of damage
Healer.java details:
-The healer has an extra data field called Dexterity and a method called Heal. When the healer calls Heal each LIVING member of the party receives between 5 and 10 health points (not to pass 100) and each receives one point back to their special skill (dexterity, mana or strength). Calling Heal costs 2 Dexterity points and a healer starts with 4 Dexterity. Hint: The heal method determines how many points are restored to each party members health. Let your main method do the actual work of healing the surviving heroes.
-the dealDamage() method for the Healer does between 3 and 5 points of damage
If your hero is out of special skill points they can only call the base dealDamage() method (i.e., they cannot use their special skill). Once a hero is dead, they cant do anything because, theyre dead. In addition to any extra accessors and mutators you should override the toString method for easy printing of the hero state.
Oncer you have completed above, do the following tester shown below (name it HeroTester.java):
- Create an array of three heroes (one of each type)
- Create an array of 10 goblins (already in the project/package)
- Ask the user to select which hero they want to send into battle, which goblin they want to attack and whether or not to do regular damage or use their special attack (Berserk, Lightning, or Heal). The rules of the game must be maintained. They cannot attack with dead heroes and cannot attack dead goblins.
- Heroes have a 40% chance of using their special skill. The other 60% is regular damage. If a hero tries to use their special skill but they have no special skill points left, they simply do regular damage.
- Wage an epic battle between the groups. The heroes attack first in sequence:
- They attack the goblins in sequence (each hero attacks the first goblin in the array until it is vanquished and then they move onto the next)
- Goblins attack next in order (goblin[0], then goblin[1] and so on) but they attack a random hero. If a hero dies it cannot attack nor be attacked any further, skip it in the rotation. Same for ex-goblins.
- At any point, if all the heroes have met their doom, the goblins win. If any of the heroes live and the goblins are all dispatched, then yay!.
- Your tester should keep you updated on how the battle is progressing by telling you how many goblins are left, what is the state of your heroes after the round, who has died (if anyone) and when there is a win condition.
FOR THE SAMPLE OUTPUT DO THE FOLLOWING:
- Show that the Berserk, Lightning, and Heal method works in the sample output during the battle.
- Ask the user to choose which hero to attack after the first one has already been selected.
- Show the skill points left after the special attack has been used.
Thanks!
Hero -health name +Hero (name String) +deal Damage : int +takeDamage (damage int): +heal (addHealth int) +getHealth): int +getName) String tisDead boolean +toString) String Magician Fighter Healer -mana: int -strength: int -dexterity: int +Magician () +dealDamage int +lightning int +getMana) : int +addMana (addMana int) : +toString String +Healer ) +heal) int +Fighter () +dealDamage int +berserk) int +getStrenght ) int +addStrength (addStrength: int): +toString String +toString) String Hero -health name +Hero (name String) +deal Damage : int +takeDamage (damage int): +heal (addHealth int) +getHealth): int +getName) String tisDead boolean +toString) String Magician Fighter Healer -mana: int -strength: int -dexterity: int +Magician () +dealDamage int +lightning int +getMana) : int +addMana (addMana int) : +toString String +Healer ) +heal) int +Fighter () +dealDamage int +berserk) int +getStrenght ) int +addStrength (addStrength: int): +toString String +toString) StringStep 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