-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonster.java
More file actions
36 lines (31 loc) · 1.12 KB
/
Monster.java
File metadata and controls
36 lines (31 loc) · 1.12 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
public abstract class Monster extends DungeonCharacter{
private Details monsterdetails;
public Monster(final String name, final Details details) {
super(name, details);
monsterdetails = details;
}
public void heal() {
boolean canHeal = (Math.random() <= monsterdetails.getChanceToHeal()) && (monsterdetails.getHealthPoints() > 0);
int hp = 0;
int[] healRange = monsterdetails.getHealRange();
if (canHeal) {
hp = (int) (Math.random() * (healRange[1] - healRange[0] + 1)) + healRange[0];
this.addHitPoints(hp);
}
}
public void addHitPoints(final int hp) {
System.out.println(super.getName() + " healed themself for [" + hp + "] points.\n");
super.addHitPoints(hp);
System.out.println();
}
public void subtractHitPoints(final int hp, final DungeonCharacter opponent) {
this.heal();
super.subtractHitPoints(hp, opponent);
}
public void randomDrop(Hero opponent) {
if (Math.random() > .9) {
System.out.println(this.getName() + "dropped a healing potion!");
opponent.addHealthPotion();
}
}
}