-
Notifications
You must be signed in to change notification settings - Fork 5
/
PlayerSimple.java
305 lines (266 loc) · 6.68 KB
/
PlayerSimple.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
package core.player;
import java.util.Collection;
import cards.Card;
import cards.equipments.Equipment;
import cards.equipments.Equipment.EquipmentType;
import core.heroes.Hero;
import exceptions.server.game.InvalidPlayerCommandException;
import listeners.game.CardDisposalListener;
import listeners.game.CardOnHandListener;
import listeners.game.DelayedListener;
import listeners.game.EquipmentListener;
import listeners.game.HealthListener;
import listeners.game.HeroListener;
import utils.DelayedStackItem;
import utils.DelayedType;
/**
* client side simple player implementation, used to hold information of
* "other players"
*
* @author Harry
*
*/
public class PlayerSimple extends Player {
private HealthListener healthListener;
private CardOnHandListener cardsOnHandListener;
private EquipmentListener equipmentListener;
private CardDisposalListener disposalListener;
private HeroListener heroListener;
private DelayedListener delayedListener;
private int cardsCount;
private boolean wineEffective; // whether wine is currently effective
public PlayerSimple(String name, int position) {
super(name, position);
cardsCount = 0;
wineEffective = false;
}
/**
* register health listener to monitor the change in health
*
* @param listener
*/
public void registerHealthListener(HealthListener listener) {
healthListener = listener;
}
/**
* register card-on-hand listener to monitor the change of card-on-hand
*
* @param listener
*/
public void registerCardOnHandListener(CardOnHandListener listener) {
cardsOnHandListener = listener;
}
/**
* register equipment listener to monitor the change of equipments
*
* @param listener
*/
public void registerEquipmentListener(EquipmentListener listener) {
equipmentListener = listener;
}
/**
* register card disposal listener to monitor the use and disposal of cards
*
* @param listener
*/
public void registerCardDisposalListener(CardDisposalListener listener) {
disposalListener = listener;
}
public void registerHeroListener(HeroListener listener) {
this.heroListener = listener;
}
public void registerDelayedListener(DelayedListener listener) {
this.delayedListener = listener;
}
/**
* <li>{@link HealthListener} notified
*/
@Override
public void setHealthLimit(int n) {
super.setHealthLimit(n);
healthListener.onSetHealthLimit(n);
}
/**
* <li>{@link HealthListener} notified
*/
@Override
public void changeHealthLimitBy(int n) {
super.changeHealthLimitBy(n);
healthListener.onSetHealthLimit(getHealthLimit());
}
/**
* <li>{@link HealthListener} notified
*/
@Override
public void setHealthCurrent(int n) {
super.setHealthCurrent(n);
healthListener.onSetHealthCurrent(n);
}
/**
* <li>{@link HealthListener} notified
*
* @param n
*/
@Override
public void changeHealthCurrentBy(int n) {
super.changeHealthCurrentBy(n);
healthListener.onHealthChangedBy(n);
}
/**
* <li>{@link CardOnHandListener} notified
*
* @param card
*/
@Override
public void addCard(Card card) {
cardsCount++;
cardsOnHandListener.onCardAdded(card);
}
/**
* <li>{@link CardOnHandListener} notified
* <li>{@link CardDisposalListener} notified
*
* @param card
* @throws InvalidPlayerCommandException
*/
@Override
public void useCard(Card card) throws InvalidPlayerCommandException {
cardsCount--;
cardsOnHandListener.onCardRemoved(card);
disposalListener.onCardUsed(card);
}
@Override
public void setHero(Hero hero) {
super.setHero(hero);
heroListener.onHeroRegistered(hero);
}
/**
* <li>{@link CardDisposalListener} notified</li>
* <li>{@link CardOnHandListener} notified</li>
* @param card
*/
@Override
public void discardCard(Card card) throws InvalidPlayerCommandException {
cardsCount--;
cardsOnHandListener.onCardRemoved(card);
disposalListener.onCardDisposed(card);
}
@Override
public int getHandCount() {
return cardsCount;
}
public CardDisposalListener getDisposalListener() {
return disposalListener;
}
/**
* Show a card on the disposal area. The card is neither used or discarded.
* <li>{@link CardDisposalListener} notified
*
* @param card
*/
public void showCard(Card card) {
disposalListener.onCardShown(card);
}
/**
* Show a collection of cards
*
* @param cards
*/
public void showCards(Collection<? extends Card> cards) {
for (Card card : cards)
showCard(card);
}
@Override
public void removeCardFromHand(Card card) throws InvalidPlayerCommandException {
cardsCount--;
cardsOnHandListener.onCardRemoved(card);
}
@Override
public void pushDelayed(Card card, DelayedType type) {
super.pushDelayed(card, type);
this.delayedListener.onDelayedAdded(card, type);
}
@Override
public DelayedStackItem removeDelayed(DelayedType type) {
DelayedStackItem item = super.removeDelayed(type);
this.delayedListener.onDelayedRemove(item.type);
return item;
}
@Override
public DelayedStackItem removeDelayed(Card card) {
DelayedStackItem item = super.removeDelayed(card);
this.delayedListener.onDelayedRemove(item.type);
return item;
}
/**
* discard an equipment
* <li>{@link EquipmentListener} notified
*
* @param type
* @throws InvalidPlayerCommandException
*/
@Override
public void unequip(EquipmentType type) throws InvalidPlayerCommandException {
super.unequip(type);
equipmentListener.onUnequipped(type);
}
/**
* equip new equipment
* <li>{@link EquipmentListener} notified
*
* @param equipment
* : new equipment
* @throws InvalidPlayerCommandException
*/
@Override
public void equip(Equipment equipment) throws InvalidPlayerCommandException {
super.equip(equipment);
equipmentListener.onEquipped(equipment);
}
/**
* {@link HealthListener} notified
*/
@Override
public void kill() {
super.kill();
healthListener.onDeath();
// Player role is revealed upon death
heroListener.onRoleRevealed(getRole());
}
public void clearDisposalArea() {
disposalListener.refresh();
}
public void useWine() throws InvalidPlayerCommandException {
wineEffective = true;
heroListener.onWineEffective(true);
}
public boolean isWineEffective() {
return this.wineEffective;
}
public void resetWineEffective() {
if (this.wineEffective) {
this.wineEffective = false;
heroListener.onWineEffective(false);
}
}
@Override
public void setRole(Role role) {
super.setRole(role);
heroListener.onRoleAssigned(role);
}
@Override
public void flip() {
super.flip();
heroListener.onFlipped(isFlipped());
}
@Override
public void chain() {
super.chain();
heroListener.onChained(isChained());
}
@Override
public void setChained(boolean chained) {
super.setChained(chained);
heroListener.onChained(chained);
}
}