-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
236 lines (192 loc) · 4.41 KB
/
Copy pathPlayer.java
File metadata and controls
236 lines (192 loc) · 4.41 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
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
import java.util.ArrayList;
public class Player implements PlayerAPI {
private static final int MAX_NUM_JAIL_EXIT_ATTEMPTS = 3;
private String name;
private int position;
private int balance;
private int amount;
private String tokenName;
private int tokenId;
private boolean passedGo;
private ArrayList<Property> properties = new ArrayList<Property>();
private boolean inJail;
private int numJailExitAttempts;
private ArrayList<Card> cards = new ArrayList<Card>();
// CONSTRUCTORS
Player (String name, String tokenName, int tokenId) {
this.name = name;
this.tokenName = tokenName;
this.tokenId = tokenId;
position = 0;
balance = 0;
passedGo = false;
inJail = false;
return;
}
Player (Player player) { // copy constructor
this(player.getName(), player.getTokenName(), player.getTokenId());
}
// METHODS DEALING WITH PLAYER DATA
public String getName () {
return name;
}
public String getTokenName () {
return tokenName;
}
public int getTokenId () {
return tokenId;
}
// METHODS DEALING WITH TOKEN POSITION
public int getPosition () {
return position;
}
public void move (int squares) {
position = position + squares;
if (position >= Board.NUM_SQUARES) {
position = position - Board.NUM_SQUARES;
passedGo = true;
} else {
passedGo = false;
}
if (position < 0) {
position = position + Board.NUM_SQUARES;
}
return;
}
public void moveTo (int square) {
if (square < position) {
passedGo = true;
} else {
passedGo = false;
}
position = square;
return;
}
public boolean passedGo () {
return passedGo;
}
// METHODS DEALING WITH JAIL
public void goToJail () {
position = Board.POS_JAIL;
inJail = true;
numJailExitAttempts = 0;
return;
}
public void freeFromJail () {
position = Board.POS_JAIL;
inJail = false;
return;
}
public boolean isInJail () {
return inJail;
}
public void failedJailExitAttempt () {
numJailExitAttempts++;
return;
}
public boolean exceededJailExitAttempts () {
return numJailExitAttempts >= MAX_NUM_JAIL_EXIT_ATTEMPTS;
}
public void addCard (Card card) {
cards.add(card);
return;
}
public boolean hasGetOutOfJailCard () {
boolean hasCard = false;
if (cards.size()> 0) {
hasCard = cards.get(0).getAction() == CardDeck.ACT_GET_OUT_OF_JAIL;
}
return hasCard;
}
public Card getCard () {
Card card = cards.get(0);
cards.remove(0);
return card;
}
// METHODS DEALING WITH MONEY
public void doTransaction (int amount) {
balance = balance + amount;
this.amount = amount;
return;
}
public int getTransaction () {
return amount;
}
public int getBalance () {
return balance;
}
public int getAssets () {
int assets = balance;
for (Property property: properties) {
assets = assets + property.getPrice();
}
return assets;
}
// METHODS DEALING WITH PROPERTY
public void addProperty (Property property) {
property.setOwner(this);
properties.add(property);
return;
}
public int getNumProperties () {
return properties.size();
}
public Property getLatestProperty () {
return properties.get(properties.size()-1);
}
public ArrayList<Property> getProperties () {
return properties;
}
public boolean isGroupOwner (Site site) {
boolean ownsAll = true;
ColourGroup colourGroup = site.getColourGroup();
for (Site s : colourGroup.getMembers()) {
if (!s.isOwned() || (s.isOwned() && s.getOwner() != this))
ownsAll = false;
}
return ownsAll;
}
public int getNumStationsOwned () {
int numOwned = 0;
for (Property p : properties) {
if (p instanceof Station) {
numOwned++;
}
}
return numOwned;
}
public int getNumUtilitiesOwned () {
int numOwned = 0;
for (Property p : properties) {
if (p instanceof Utility) {
numOwned++;
}
}
return numOwned;
}
public int getNumHousesOwned () {
int numHousesOwned = 0;
for (Property p : properties) {
if (p instanceof Site) {
numHousesOwned = numHousesOwned + ((Site) p).getNumHouses();
}
}
return numHousesOwned;
}
public int getNumHotelsOwned () {
int numHotelsOwned = 0;
for (Property p : properties) {
if (p instanceof Site) {
numHotelsOwned = numHotelsOwned + ((Site) p).getNumHotels();
}
}
return numHotelsOwned;
}
// COMMON JAVA METHODS
public boolean equals (String name) {
return this.name.toLowerCase() == name;
}
public String toString () {
return name + " (" + tokenName + ")";
}
}