-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonster.java
58 lines (50 loc) · 1.01 KB
/
Monster.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
54
55
56
57
58
import java.util.*;
public class Monster {
private static ArrayList<Integer> arr = new ArrayList<Integer>();
private int health;
public boolean alive = true;
public Monster() {
health = 3;
}
public Monster(int health) {
this.health = health;
}
public boolean checkLife() {
if (health <= 0) {
alive = false;
}
return alive;
}
public int getHealth() {
return health;
}
public void setHealth(int newhealth) {
health = newhealth;
}
public String bodyPart() {
int num = (int) (Math.random() * 8);
String part = "";
while (arr.contains(num)) {
num = (int) (Math.random() * 8);
}
arr.add(num);
if (num == 0) {
part = "left leg";
} else if (num == 1) {
part = "right leg";
} else if (num == 2) {
part = "left arm";
} else if (num == 3) {
part = "right arm";
} else if (num == 4) {
part = "tail";
} else if (num == 5) {
part = "left head";
} else if (num == 6) {
part = "middle head";
} else if (num == 7) {
part = "right head";
}
return part;
}
}