Question: This class simply serves as driver for the other two classes: It has a single, static method, fight, which takes one Monster and one Hero,
This class simply serves as driver for the other two classes: It has a single, static method, fight, which takes one Monster and one Hero, and causes them to exchange damage until one of them is defeated. Use the following method signature:
public static String fightHero h Monster m
To accomplish this, this method should perform the following steps in a loop until either a the hero does not have any remaining hit points, or b the monster is defeated:
Call the receiveAttack method of the Monster object, passing in the Hero object's attackValue.
Call the receiveAttack method of the Hero object, passing in the Monster object's attackValue.
Check if the hero hasHPRemaining, and if not, the hero should useHealingPotion.
Once either condition has been met, the loop should end. If the hero was defeated, the following String should be returned: "The type has defeated name. Game over." where type should be replaced with the string stored in the monster's type field, and name should be replaced with the string stored in the hero's name field. If the monster was defeated, the hero should receiveXP equal to the monster's xpValue, and increase their number of healingPotions by the goldValue of the monster divided by three, and the following string should be returned: "name has defeated the type earning G gold and E XP leveling up X times." where all of the strings in italics are replaced by the appropriate values.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
