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.

68 lines
2.0 KiB

## AdventureTemplar
### Instructions
We will now implement our second interface through a new class : `Templar` in a file named `Templar.java`.
This class implements the `Healer` and the `Tank` interfaces and inherits from `Character`.
It has two new attributes :
- a non modifiable integer `healCapacity`,
- a non modifiable integer `shield`.
It has a constructor with four parameters :
- `name`,
- `maxHealth`,
- `healCapacity`,
- `shield`
From the `Healer` interface :
- `getHealCapacity` returns the property `healCapacity`
- `heal` add `healCapacity` to the currentHealth of the `Character` in parameter. Beware that the `currentHealth` can't be greater the `maxHealth`.
From the `Tank` interface :
- `getShield` return the property `shield`.
You will override the `toString` method with the following format : `<name> is a strong Templar with <currentHealth> HP. It can heal <healCapacity> HP and has a shield of <shield>.`
If it's `currentHeal` is equal to 0, the format is `<name> has been beaten, even with its <shield> shield. So bad, it could heal <healCapacity> HP.`
### Usage
Here is a possible ExerciseRunner.java to test your function :
```java
public class ExerciseRunner {
public static void main(String[] args) {
Templar alistair = new Templar("Alistair", 20, 5, 4);
Templar roderick = new Templar("Roderick", 10, 3, 2);
Character.fight(alistair, roderick);
alistair.heal(alistair);
System.out.println(Character.printStatus());
}
}
```
and its output :
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
------------------------------------------
Characters currently fighting :
- Alistair is a strong Templar with 16 HP. It can heal 5 HP and has a shield of 4.
- Roderick has been beaten, even with its 2 shield. So bad, it could heal 3 HP.
------------------------------------------
$
```
### Notions
[Implementation](https://docs.oracle.com/javase/tutorial/java/IandI/usinginterface.html)
[Inheritance](https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html)