-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoss.java
More file actions
68 lines (61 loc) · 2.39 KB
/
Copy pathBoss.java
File metadata and controls
68 lines (61 loc) · 2.39 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.util.List;
import java.util.Random;
/**
* A boss encounter. Every boss shares this behaviour and differs only in data - its health, rune
* reward, dialogue, and the combos it uses in each phase - so {@link Bestiary} builds them all from
* one class rather than a subclass apiece. A boss enters phase 2 once its health drops to half.
*/
public class Boss {
private final int originalHp;
private final int runes;
private final String winLine;
private final String phaseLine;
private final String deathLine;
private final List<Combo> phase1Combos;
private final List<Combo> phase2Combos;
private final Random random = new Random();
private int hp;
private int phase = 1;
public Boss(int hp, int runes, String winLine, String phaseLine, String deathLine,
List<Combo> phase1Combos, List<Combo> phase2Combos) {
this.hp = hp;
this.originalHp = hp;
this.runes = runes;
this.winLine = winLine;
this.phaseLine = phaseLine;
this.deathLine = deathLine;
this.phase1Combos = phase1Combos;
this.phase2Combos = phase2Combos;
}
public int getHp() { return hp; }
public void setHp(int hp) { this.hp = hp; }
public int getRunes() { return runes; }
public int getPhase() { return phase; }
public void setPhase(int p) { this.phase = p; }
public String getWinLine() { return winLine; }
public String getDeathLine(){ return deathLine; }
/** Reduces the boss's health by {@code amount} and returns the amount lost. */
public int loseHp(int amount) {
hp -= amount;
return amount;
}
/** Picks a random combo from the boss's current phase. */
public Combo nextCombo() {
List<Combo> combos = (phase == 1) ? phase1Combos : phase2Combos;
if (combos == null || combos.isEmpty()) {
combos = phase1Combos; // defensive: never draw from an empty list
}
return combos.get(random.nextInt(combos.size()));
}
/**
* If the boss has dropped to half health while still in phase 1, announces the phase transition
* and reports it (the caller advances the phase). Returns false otherwise.
*/
public boolean checkPhase() {
if (hp <= originalHp / 2 && phase == 1) {
Console.speak(phaseLine);
return true;
}
return false;
}
}