Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Person.java This class will represent a player in our RPG that will contain the following protected variables String name: this will represent the name of

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Person.java This class will represent a player in our RPG that will contain the following protected variables String name: this will represent the name of the player. int health: this represents the health of the player. Spell[] spells: this represents a list of spells that player knows and can use. static int numPeople: this represents the total number of players created. static int currentlyBattlingHeroes: this represents the number of currently living heroes in a battle. static int currentlyBattlingEnemies: this represents the number of living enemies. This class will have the following public methods void attack (Person person, Spell spell) o First, check to see if the current instance of person calling the method is dead. If so, print out "Cannot attack. You are dead! (Hint: What keyword represents the current instance?) o Then, check to see if the person passed in is dead. If so, print out You can't attack name! They're already dead!" o Then, you also must check to see if the passed in spell is within the spells array. If the passed in parameter has the same reference (hint hint) as one of the elements in the array, then proceed to the directions below. If it doesn't, print out Cannot attack. You haven't learned the spell.", and exit the method. o This will reduce the person's health by the amount of damage the Spell will cause. o If the person dies because of the damage incurred, there are a couple things we need to check: . If the person is an instance of (hint hint) Hero, then reduce currentlyBattlingHeroes and numPeople by one. . If the person is an enemy, then reduce currentlyBattlingEnemies and numPeople by one. If the person is neither an enemy or a hero, then decrease numPeople only. static String whoIsWinning o This will determine who is currently winning based off of our static variables. If there are more currentlyBattlingHeroes than enemies, return a string that says "The heroes are currently winning!". If there are more currentlyBattlingEnemies than heroes, return a string that says "The enemies are currently winning!". If they are the same, return a string that says "It's currently a tie!". void learn Spell(Spell spell) This method will add a spell to the array of spells available to the person. If the array is full, print out "name cannot learn anymore spells." getters and setters for all instance variables. This class will have the following constructors Person(String name, int health) This constructor will initialize name and health with the passed in parameters, and instantiate spells with a length of 5. This will also increment numPeople by one. Hero.java This class will represent a hero in our RPG that will extend Person. This class will contain the following instance methods void learnSpell(Spell spell) . If the evilness of the spell is equal to or greater than 7, then the Hero cannot learn this spell o if the evilness is within the range that a Hero can learn, then call the parent's learnSpell(Spell spell) method. Override void attack (Person person, Spell spell) . This method will override the Person's attack method . If the player is attacking another Hero, no damage should be done to that Hero If the player is attacking an Enemy or a Person, then you should decrease the person's health by the amount of power the spell has. o You must call the parent's attack method if these conditions pass Overload void attack(Person person) o When the Spell that a Hero is attacking another player with is not specified in the method parameter, the attacking Spell should be the first Spell in the Hero's Spell array o If the Hero hasn't learned any spells yet, print out "[name] hasn't learned any spells!" o Be sure to check if the Person is an Enemy or a Hero! The Person's health should only be decremented if the Hero is attacking an Enerny or Person o If the person dies because of the damage incurred, make sure to deal with it the same way as the person's attack method This class has the following constructor: Hero(String name, int health) o This constructor should call Hero's parent constructor o This will also increment currently Battling Heroes Enemy.java This class will represent a enemy in our RPG that will extend Person. This class will contain the following instance methods void learnSpell(Spell spell) An enemy can only learn a Spell if its evilness is greater than or equal to 7 If the Enemy can learn the Spell then, then call the parent's learn Spell(Spell spell) method. Override void attack (Person person, Spell spell) o This method will override the Person's attack method. . If the player is attacking another Enemy, no damage should be done to that Enemy o If the player is attacking an Hero or a Person, then you should decrease the person's health by the amount of power the spell has. o You must call the parent's attack method if these conditions pass. Overload void attack (Person person) o When the Spell that a Enemy is attacking another player with is not specified in the method parameter, the attacking Spell should be the first Spell in the Enemy Spell array o If the Enemy hasn't learned any spells yet, print out "name hasn't learned any spells!" o Be sure to check if the Person is an Enemy or a Hero! The Person's health should only be decremented if the Enemy is attacking a Hero or Person o If the person dies because of the damage incurred, make sure to deal with it the same way as the Person's attack method This class has the following constructor: Enemy(String name, int health) o This constructor should call Enemy parent constructor o This will also increment currentlyBattlingEnemies Spell.java This class will represent a weapon in our RPG that will contain the following private variables String name: this will represent the name of the spell int power: this will represent the amount of damage that the spell can incur double evilness: this will represent the amount of evilness that a particular spell can have This class also has the following instance methods and constructor: Getters and setters for each instance variable Spell(String name, int power, double evilness) o This will initialize the instance variables with the passed in parameters. For this homework, you must write Javadocs. Please refer to the example code provided under the Javadocs folder in Canvas

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+-cach nonempty one contains a rational.

Answered: 1 week ago