mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
davhojt
1cf114eb85
|
1 year ago | |
---|---|---|
.. | ||
README.md | 1 year ago |
README.md
AdventurAbstract
Instructions
Let's change some things : make the Character
as abstract
. You can now try to instantiate a Character object, it will fail :)
Change the attack
and takeDamage
methods : put them as abstract
too.
Now, if you try to launch some example, it will fail. Indeed, you need to implement both methods in all subclasses. Do this as follow :
Remember that in all cases, the currentHealth
should not be lower than 0.
- For Monster class :
- the
attack
method should deal 7 damages to the character as parameter. - the
takeDamage
method should take 80% of all the damages, rounded to the inferior integer.
- the
- For the
Sorcerer
class :- the
attack
method should heal itself (using theheal
method) then deal 10 damages to the character as parameter. - the
takeDamage
method should take all the damages.
- the
- For the
Templar
class :- the
attack
method should heal itself (using theheal
method) then deal 6 damages to the character as parameter. - the
takeDamage
method should take the damage as parameter minus the shield value.
- the
Usage
Here is a possible ExerciseRunner.java to test your function :
public class ExerciseRunner {
public static void main(String[] args) {
Templar alistair = new Templar("Alistair", 18, 2, 4);
Sorcerer morrigan = new Sorcerer("Morrigan", 21, 5);
Monster dragon = new Monster("Dragon", 12);
dragon.attack(alistair);
dragon.attack(morrigan);
alistair.attack(dragon);
morrigan.attack(dragon);
System.out.println(Character.printStatus());
}
}
and its output :
$ javac *.java -d build
$ java -cp build ExerciseRunner
------------------------------------------
Characters currently fighting :
- Alistair is a strong Templar with 17 HP. It can heal 2 HP and has a shield of 4.
- Morrigan is a sorcerer with 19 HP. It can heal 5 HP.
- Dragon is a monster and is dead
------------------------------------------
$