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.
2.1 KiB
2.1 KiB
AdventurAbstract
Instructions
Let's change things a bit: make the Character
as abstract
. You can now try to instantiate a Character object, it will fail :)
Change attack
and takeDamage
methods : make them abstract
too.
Now, if you try to launch an example, it will fail. Indeed, you need to implement both methods in all subclasses. Do this as follows :
Remember that in all cases, currentHealth
should not be lower than 0.
- For Monster class :
- the method
attack
should make 7 damages to the character in parameter. - the method
takeDamage
should take 80% of all the damages, rounded to the inferior integer.
- the method
- For the
Sorcerer
class :- the method
attack
should heal itself (using theheal
method) then make 10 damages to the character in parameter. - the method
takeDamage
should take all the damages.
- the method
- For the
Templar
class :- the method
attack
should heal itself (using the methodheal
) then make 6 damages to the character in parameter. - the method
takeDamage
should take the damage given in parameter minus the shield value.
- the method
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
------------------------------------------
$