Starting from:
$30

$24

Assignment Inheritance and Polymorphism Solution


Heroes vs. Monsters






For this assignment you will create an inheritance hierarchy and utilize polymorphism. The idea behind the game is that one of three Heroes (Warrior, Sorceress, Thief) chosen by the user will battle one of three randomly selected Monsters (Ogre, Gremlin, Skeleton). The battle is to the death. When a character dies, the user can play again.




The inheritance hierarchy for the program is as follows:




DungeonCharacter (base - abstract)




contains instance variables that any character in the game will have -- protected access is ok (NO public access allowed!)



o name - String




o hit points (how much damage a character can take before it expires) - integer o attack speed - integer (1 is slowest)




o damage range (minimum and maximum amount of damage a character can do on an attack) - two integers




o chance to hit opponent when attacking - double o anything else you deem necessary

constructor to initialize instance variables
get and set methods as you deem necessary



an attack method
first checks if character can attack (based on chance to hit)
if it can, a hit in range of minimum to maximum damage is generated and applied to



opponent -- user should be informed of what happens

if it cannot, a message should be displayed that says the attack failed



Hero (derived from DungeonCharacter -- Hero is also abstract)




contains instance variables that any hero should have



chance to block (a Hero has a chance to block any attack by a Monster -- this should be checked after the Monster has attacked and hit points are about to be removed from the Hero) - double



number of turns in round (number of attacks/special operations a Hero gets to perform per round -- based on Hero attack speed versus Monster attack speed - if Hero is twice as fast then s/he gets two turns, three times as fast gets three turns, etc.) - integer
anything else you deem necessary
constructor - should call base constructor, too



a method to get name of character from user -- should be invoked in constructor after base constructor
get, set, and any other methods (this includes overridden ones) you deem necessary



Warrior (derived from Hero)




instance variables as you deem necessary (none may be necessary!)



a crushingBlow method that does 75 to 175 points of damage but only has a 40% chance of succeeding -- this is the Warrior's special skill



gets, sets, and any other methods you deem necessary (you may want to override the attack method to fit your Warrior)
suggested statistics for Warrior (should be set up in constructor(s))



hit points: 125 o attack speed: 4
o chance to hit: 0.8 (80 percent)

o minimum damage: 35

o maximum damage: 60

o chance to block: 0.2 (20 percent)




Sorceress (derived from Hero)




same game as Warrior except special skill is heal (choose a range of hit points that will be healed)



suggested statistics for Sorceress (should be set up in constructor(s))



hit points: 75 o attack speed: 5
o chance to hit: 0.7 (70 percent)

o minimum damage: 25

o maximum damage: 45

o chance to block: 0.3 (30 percent)




Thief (derived from Hero)




same game as Warrior except special skill is surpriseAttack -- 40 percent chance it is successful. If it is successful, Thief gets an attack and another turn in the current round. There is



a 20 percent chance the Thief is caught in which case no attack is rendered. The other 40 percent is just a normal attack.




suggested statistics for Thief (should be set up in constructor(s)) o hit points: 75
o attack speed: 6

o chance to hit: 0.8 (80 percent)

o minimum damage: 20

o maximum damage: 40

o chance to block: 0.4 (40 percent)




Monster (derived from DungeonCharacter -- abstract)




contains instance variables that any Monster should have



chance to heal (a Monster has a chance to heal after any attack that causes a loss of hit points -- this should be checked after the Monster has been attacked and hit points have been lost -- note that if the hit points lost kill the Monster, it cannot heal itself!) - double



minimum and maximum points a monster can heal itself - two integers o anything else you deem necessary
constructor - should call base constructor, too



get, set, and any other methods (this includes overridden ones) you deem necessary



a heal method that is based on chance to heal and then range of heal points for monster



Ogre (derived from Monster)




instance variables as you deem necessary (none may be necessary!)



gets, sets, and any other methods you deem necessary (you may want to override the attack method to fit your Ogre)



suggested statistics for Ogre (should be set up in constructor(s) -- choose a name for your Ogre) o hit points: 200
o attack speed: 2

o chance to hit: 0.6 (60 percent)

o minimum damage: 30

o maximum damage: 60

o chance to heal: 0.1 (10 percent)

o minimum heal points: 30

o maximum heal points: 60




Gremlin (derived from Monster)




instance variables as you deem necessary (none may be necessary!)



gets, sets, and any other methods you deem necessary (you may want to override the attack method to fit your Gremlin)



suggested statistics for Gremlin (should be set up in constructor(s)-- choose a name for your Gremlin)
o hit points: 70

o attack speed: 5

o chance to hit: 0.8 (80 percent)

o minimum damage: 15

o maximum damage: 30

o chance to heal: 0.4 (40 percent)

o minimum heal points: 20

o maximum heal points: 40




Skeleton (derived from Monster)

instance variables as you deem necessary (none may be necessary!)



gets, sets, and any other methods you deem necessary (you may want to override the attack method to fit your Skeleton)



suggested statistics for Skeleton (should be set up in constructor(s)-- choose a name for your Skeleton)
o hit points: 100

o attack speed: 3

o chance to hit: 0.8 (80 percent)

o minimum damage: 30

o maximum damage: 50

o chance to heal: 0.3 (30 percent)

o minimum heal points: 30

o maximum heal points: 50




HeroesVersusMonsters




contains main method



contains helper methods to run the game (see Game Play section below)



should contain a Hero reference and a Monster reference (for playing the game)












Game Play




User chooses a Hero
Program randomly selects a Monster
Hero and Monster battle until one is defeated



Hero goes first. Hero may have multiple attacks depending on speed of Hero versus Monster



Monster goes second and always attacks. Monster cannot attack if Hero defeated it during Hero attack (duh)
After each round user should be given option to quit.



After battle is complete, user should be given option to play a new game



Throughout game play the user should be given as much information as possible about the battle. Here are things the user should be told:




What happened on an attack (how much damage or that it failed or that it was blocked)



How many hit points remain for a character after the character loses hit points (via an attack) or gains hit points (via healing)
Anything else you can think of to make game play more clear












Group Work




You may work in pairs on this assignment. If you choose to do this, you must complete a write-up that describes very specifically what each person did. You must also implement the extra credit (features 1 and 2 below) as part of the regular assignment. Be sure to insert comments in your submission informing the grader.




Extra Credit if working individually (required if working as a team)




5 points - add a special skill to each Monster. When a Monster attacks this special skill should be randomly chosen (perhaps 30 percent of the time)



5 points - add another Hero. The Hero should have a unique special skill





















To turn in




Submit a zip file to Canvas Assignments (just one if you work in a team) that contains:




all source files necessary to compile and run program



Other documentation (required):



anything you could not get to work o extra credit attempted
o your name(s)

o anything borrowed from elsewhere










Get started ASAP!













NOTE: A prudent strategy is to first write the DungeonCharacter class and make it so two objects of this class can fight (you must temporarily suspend the ‘abstract’ designation for this class.) Once this works, make DungeonCharacter abstract, and move on to Hero and Monster and do the same. Finally, add the sub-classes of Hero and Monster and test those.

More products