-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemon.java
More file actions
60 lines (50 loc) · 1.57 KB
/
Demon.java
File metadata and controls
60 lines (50 loc) · 1.57 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
import java.util.ArrayList;
public class Demon {
double health;
double power;
double maxHealth;
ArrayList<String> moves = new ArrayList<String>();
// Constructor - initializes health and power
public Demon(Player player) {
power = player.getEmotion()/1.5;
health = 1 + power*2;
maxHealth = health;
// Add moves
moves.add("slashs");
moves.add("stabs");
moves.add("claws");
moves.add("slices");
moves.add("sinks its teeth into");
}
// Returns a boolean of whether the demon can see the player
public boolean canSee(Player player) {
return player.getEmotion() != 0;
}
// Simulates a demon attack
public void attack(Player player) {
// Select the move
int loc = (int)(Math.random() * moves.size());
String move = moves.get(loc);
// Run the dialogue
System.out.println("The demon " + move + " you. -" + power + " Life.");
// Change player health
player.changeHealth(-1*power);
}
// Retrieves the health value
public double getHealth() {
return health;
}
// Changes the health of the demon by n
public void changeHealth(double n) {
// Following if statements make sure the health never exceeds 10 or drops below 0
if (health + n >= maxHealth) {
health = maxHealth;
}
else if (health + n <= 0) {
health = 0;
}
else {
health += n;
}
}
}