-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonster.java
More file actions
102 lines (84 loc) · 2.32 KB
/
Copy pathMonster.java
File metadata and controls
102 lines (84 loc) · 2.32 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import java.util.*;
public class Monster {
private Random rand;
private String name;
private int maxHp;
private int hp;
private int atk;
private int str;
private int def;
private int order;
private Item drop;
private Map<Integer, Item> dropTable;
public Monster(String name, int maxHp, int atk, int str, int def, int order) {
this.name = name;
this.maxHp = maxHp;
this.hp = maxHp;
this.atk = atk;
this.str = str;
this.def = def;
this.order = order;
this.dropTable = new TreeMap<>();
}
public String getName() {
return this.name;
}
//returns attack of the monster, used to calculate if its attacks will hit
public int getAtk() {
return this.atk;
}
//returns strength of the monster, used to calculate its max hit
public int getStr() {
return this.str;
}
//returns defense of the monster, used to calculate if attacks will be blocked or not
public int getDef() {
return this.def;
}
public int getHp() {
return this.hp;
}
//returns hp of the monster
public int getMaxHp() {
return this.maxHp;
}
public int getOrder() {
return this.order;
}
//reflects damage dealt to a monster
public void monsterHit(int dmg) {
if ((this.hp - dmg) > 0) {
this.hp = this.hp - dmg;
} else {
this.hp = 0;
}
}
public void monsterRespawn() {
this.hp = this.maxHp;
}
public Item getDrop(int roll) {
Item currentDrop = null;
int rollNum = 0;
for (Integer num : dropTable.keySet()) {
if (roll == num) {
currentDrop = dropTable.get(num);
break;
}
}
return currentDrop; // No drop
}
//returns the range of drops from a monster
public int getDropRange() {
int range = -1;
for (Integer num : dropTable.keySet()) {
range++;
}
return range;
}
public void setDrop(Item name, int roll) {
dropTable.put(roll, name);
}
public String toString() {
return this.name;
}
}