Comp 152 Project 3:
Inheritance
Due: Friday March 7th at 11:55pm
Project:
You will write a program which will demostrate inheritance using some
simple classes which might form the backend of a game with bit
more work. Implement the UML found below:
Methods:
The methods in the UML class diagram aboce should be implemented as follows:
- GameEntity Class
- doesCollide: should return true if the rect for this one
overlaps the rect for the other GameEntity (hint: see the
java.awt.Rectangle documentation for a method to do this for you)
- takeDamange: reduces health by amount
- toString should print out the entity and its health
- Player
- swapWeapon: should set weaponDamage to newDamage
- changeArmor: should set armor to newArmorValue
- getArmor: should return armor
- attack : should call takeDamage on the enemy
- takeDamage: should reduce the damage by (armor/1000) percent and
then call the parent class takeDamage
- toString: standard toString then call parent class toString
- Bad_Guy:
- attackClose should call takeDamage on victim passing closeUpDamage
as the parameter
- attackFromFar should call takeDamage on victim passing
distanceDamage as the parameter
- the Constructor should initialize the two instance variables to some
int between 100 and 200 of your choice
- Boss
- Constructor should set the three special damages to three values
from 100 to 500 (you choose how)
- attackClose should call chooseSpecialAttack and then us its return
value as a parameter to call takeDamage on victim
- chooseSpecialAttack should randomly choose (using a
java.util.Random object) a value from one to three and return that
specialDamage value as its return value (for example if you randomly
choose twothen return SpecialDamage2)
- Tester
- main: this is the driver. It should test the various classes as
follows
- create a player, a bad guy and a boss.
- This is the repeat marker
- ask the user what the players armor should be
- changeArmor to that value
- ask the user what the players weapon should be
- have the Bad_Guy attackClose on the player
- have the Player attack the Bad_Guy
- print out the each of your three objects (you'll need to use your
toString)
- Have the player attack the Boss
- have the boss attack the player
- print out the each of your three objects (you'll need to use your
toString) again
- repeat everything above starting from "This is the repeat marker"
one more time.
Extra requirements for the project
Comment your code.
Include a readme.txt with your project telling me
your name
Anything you didn't get done
Submission:
Zip up your project into a single zip file
Submit using Moodle as before.