-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fighter.java
53 lines (43 loc) · 907 Bytes
/
Fighter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
abstract class Fighter {
boolean isVulnerable() {
return false;
}
abstract int damagePoints(Fighter fighter);
}
class Warrior extends Fighter {
@Override
public String toString() {
return "Fighter is a Warrior";
}
@Override
int damagePoints(Fighter wizard) {
if (wizard.isVulnerable()) {
return 10;
}
return 6;
}
}
class Wizard extends Fighter {
boolean spellPrepared = false;
@Override
public String toString() {
return "Fighter is a Wizard";
}
@Override
boolean isVulnerable() {
if (spellPrepared) {
return false;
}
return true;
}
@Override
int damagePoints(Fighter warrior) {
if (spellPrepared) {
return 12;
}
return 3;
}
void prepareSpell() {
spellPrepared = true;
}
}