-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weapon.java
87 lines (72 loc) · 1.68 KB
/
Weapon.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
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
package WOW;
public class Weapon implements Comparable<Weapon> {
private boolean exist = true;// 武器是否存在
private int id;// 武器编号
private String weaponType;// 武器种类
Weapon(int id_, String weaponType_) {
id = id_;
weaponType = weaponType_;
}
@Override
public int compareTo(Weapon w) {
if (id < w.id)
return -1;
if (id > w.id)
return 1;
if (w instanceof Arrow) {
if (((Arrow) this).getUsedTime() > ((Arrow) w).getUsedTime())
return -1;
return 1;
}
return 0;
}
void setExisted(boolean b) {
exist = b;
}
boolean isExisted() {
return exist;
}
int getWeaponId() {
return id;
}
String getWeaponType() {
return weaponType;
}
int usedBy(Hero h) {
return 20 * h.force / 100;
}
}
class Sword extends Weapon {
Sword(int id_, String weaponType_) {
super(id_, weaponType_);
}
}
class Bomb extends Weapon {
Bomb(int id_, String weaponType_) {
super(id_, weaponType_);
}
@Override
int usedBy(Hero h) {
int force = 40 * h.force / 100;
if (!(h instanceof Ninja))
h.life -= force / 2;
setExisted(false);
return force;
}
}
class Arrow extends Weapon {
private int usedTime = 0;
Arrow(int id_, String weaponType_) {
super(id_, weaponType_);
}
@Override
int usedBy(Hero h) {
usedTime++;
if (usedTime == 2)
setExisted(false);
return 30 * h.force / 100;
}
int getUsedTime() {
return usedTime;
}
}