-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cell.java
193 lines (171 loc) · 3.62 KB
/
Cell.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package map;
import bomb.Bomb;
import items.Item;
/**
* Basic unit of map, with information of current status of certain position on
* the map, including Barrier information, Bomb information and explosion effect
* information
*
* @author Zhuofan Chen
* @version 1.0
*/
public class Cell {
// Define this cell with wall/bomb/item or not
private boolean withBomb = false;
private boolean withWall = false;
private boolean withItem = false;
// If a wall on this cell is destructible, true when no wall is on this cell
private boolean wallIsDestructible = true;
private int wallID = 7;
// Define explosion effects exerted on current this
private int explosionEffect = 0;
// Item/bomb on current cell
Item item = null;
Bomb bomb = null;
/**
* Call all member methods needing refreshing
*/
public void refresh() {
explosionDecay();
if (withBomb)
bomb.refresh();
}
/**
* A cell is available means a player or monster can move to it or a bomb can be
* set on it
*/
public boolean isAvailable() {
return (!withWall) && (!withBomb);
}
/**
* set a bomb on this cell
*
* @return if the bomb is successfully set
*/
public boolean setBomb(Bomb b) {
if (b == null || !isAvailable())
return false;
withBomb = true;
bomb = b;
return true;
}
/**
* remove a bomb from this cell
*
* @return false when this cell was originally without bomb
*/
public boolean removeBomb() {
if (!withBomb)
return false;
withBomb = false;
bomb = null;
return true;
}
/**
* @return if a bomb is on this cell
*/
public boolean isWithBomb() {
return withBomb;
}
/**
* Activate a explosion effect on this cell
*/
public void explosionActivate() {
if (wallIsDestructible) {
explosionEffect = 20;
withWall = false;
}
if (withBomb) {
bomb.setBombTime(0); // explode other bomb
}
}
/**
* Explosion effect decays when refreshed
*/
public void explosionDecay() {
if (explosionEffect > 0)
explosionEffect--;
}
/**
* @return this cell is now at explosion
*/
public boolean isAtExplosion() {
return (explosionEffect > 0);
}
/**
* set a wall at this cell
*
* @param destructible: whether the wall to be set is destructible
*/
public void setWall(boolean destructible) {
withWall = true;
wallIsDestructible = destructible;
if (destructible)
wallID = (int) (7 * (float)Math.random());
}
/**
* remove wall from this cell
*/
public void removeWall() {
withWall = false;
wallIsDestructible = true;
}
/**
* @return if a wall is on this cell
*/
public boolean isWithWall() {
return withWall;
}
/**
* @return if a destructible wall is on this cell
*/
public boolean isWithDestructibleWall() {
return (withWall && wallIsDestructible);
}
/**
* @return if an indestructible wall is on this cell
*/
public boolean isWithIndestructibleWall() {
return (withWall && !wallIsDestructible);
}
/**
* @return if an item is on this cell
*/
public boolean isWithItem() {
return withItem;
}
/**
* @return if the item is successfully created
*/
public boolean setItem(Item i) {
if (i == null || !isAvailable())
return false;
withItem = true;
item = i;
return true;
}
/**
* @return if an item is successfully removed from this cell
*/
public boolean removeItem() {
if (!withItem)
return false;
item = null;
withItem = false;
return true;
}
/**
* @return ID of current Item on this cell. Return -1 while no Item is on this cell
*/
public int getItemID() {
if(withItem)
return item.getItemID();
return -1;
}
public Item getItem() {
return item;
}
public int getWallID() {
return wallID;
}
}