-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiece.java
More file actions
260 lines (235 loc) · 7.01 KB
/
Piece.java
File metadata and controls
260 lines (235 loc) · 7.01 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/**
* @author Edgar Ghahramanyan <edgarquill@gmail.com>
* @version Version 1
* @since 1.6
*/
import java.util.List;
import java.util.ArrayList;
import java.awt.Color;
import java.lang.Boolean;
public class Piece
{
// CONSTANTS
private static int BANK_PAYMENT = 500;
private static int SHOP_MULTIPLIER = 50;
// PRIVATE VALUES
private int last_id;
private Field field;
private Color color;
private int wallet;
private List<Boolean> visited;
private List<Field> shops;
/*
* Initializer for the piece.
* Use default values if you would like, doesn't matter.
*/
public Piece()
{
this.field = null;
this.last_id = -1;
this.color = Color.BLACK;
this.wallet = 1500;
this.visited = new ArrayList<Boolean>();
this.shops = new ArrayList<Field>();
}
/*
* Sets the last id of the field visited.
* Used to determine which way the pieces can move.
* @param id id of the last field the piece was standing on, or -1 for reset.
*/
public void setLastId(int id)
{
this.last_id = id;
}
/*
* Returns the id of the field on which this piece was last on.
* @return id of the last field this piece was on.
*/
public int getLastId()
{
return this.last_id;
}
/*
* Sets the field on which the player is currently on.
* Last id becomes the field on which the player was previously on before moving to this one.
* @param field, the new field to which this piece is moving to.
*/
public void setField(Field field)
{
if(this.getField() != null)
this.setLastId(this.getField().getId());
this.field = field;
}
/*
* Returns the field on which this player is currently standing on.
* @return field on which the player is standing on.
*/
public Field getField()
{
return this.field;
}
/*
* Sets the color of this piece to the passed color.
* Once again I beg whoever is reading this code.
* If you can make better graphics I will be very thankful.
* @param color color to which to set the color of this piece to.
*/
public void setColor(Color color)
{
this.color = color;
}
/*
* Returns the color of this piece. Please there has to be a better way.
* @return color of this piece.
*/
public Color getColor()
{
return this.color;
}
/*
* Sets the wallet to a certain amount of money.
* @param wallet the amount to which to set the current money to.
*/
public void setWallet(int wallet)
{
this.wallet = wallet;
}
/*
* Adds a certain amount of money to the wallet.
* Just pass negative number for substraction.
* @param amount the amount of money you would like to add or substract from the wallet.
*/
public void addMoney(int amount)
{
this.wallet += amount;
}
/*
* Returns how much money the player currently possesses.
* @return the amount of money this player has in his wallet.
*/
public int getWallet()
{
return this.wallet;
}
public int getNetWorth()
{
int amount = 0;
for(int i = 0 ; i < this.shopsOwned(); i++)
amount += (this.getShop(i).getPrice() + this.getShop(i).getInvestment());
return (amount + this.getWallet());
}
/*
* This piece has visited the bank.
* If he visited all the neccessary fields then he will money.
*/
public void bank()
{
if(this.allVisited())
this.wallet += (this.BANK_PAYMENT + this.shopsOwned() * this.SHOP_MULTIPLIER);
}
/*
* Returns the size of the visited fields we have.
* @return the amount of visited spaces the player has to aquire.
*/
public int getVisitedSize()
{
return this.visited.size();
}
/*
* Sets the size of how many fields the player has to visit.
* @param size how many visited spaces there are on the field.
*/
public void setVisitedSize(int size)
{
for(int i = 0; i < size; i++)
this.visited.add(new Boolean(false));
}
/*
* Sets the visited to true.
* If the visited field does exist then it does nothing and returns false.
* @param what visited to set true to.
* @return true if the visited value was changed to true, false otherwise.
*/
public boolean setVisited(int place)
{
if(!(place < this.getVisitedSize()) || (place < 0))
return false;
this.visited.set(place, new Boolean(true));
return true;
}
/*
* Rsets all the visited values to false.
* Is used once you pass the bank.
*/
public void resetVisited()
{
for(int i = 0; i < this.getVisitedSize(); i++)
this.visited.set(i, new Boolean(false));
}
/*
* Returns the value that a certain visited place has.
* If the field does not exist false is returned.
* @param place which position of visited space to check.
* @return true if boolean value for visited is true, and false for any other occasion.
*/
public boolean getVisited(int place)
{
if(!(place < this.getVisitedSize()) || (place < 0))
return false;
return this.visited.get(place).booleanValue();
}
/*
* Tells if the user has visited all of the spaces required.
* @return true if all the spaces have been visited, false otherwise.
*/
public boolean allVisited()
{
for(int i = 0; i < this.getVisitedSize(); i++)
{
if(!this.getVisited(i))
return false;
}
return true;
}
/*
* Add the current shop as a shop owned by this piece.
* @param field field which you would like added as this piece's property.
*/
public void addShop(Field field)
{
this.shops.add(field);
field.setColor(this.color);
field.setInvestment(0);
}
/*
* Removes the specified field from being owned by a player.
* If id is wrong then no shop will be removed.
* @param id id of the field which you want to remove from the piece's ownership.
*/
public void removeShop(int id)
{
for(int i = 0; i < shops.size(); i++)
if(this.shops.get(i).getId() == id)
this.shops.remove(i);
}
/*
* Returns an int which represents how many fields the player owns.
* @return how many stores the piece owns.
*/
public int shopsOwned()
{
return this.shops.size();
}
/*
* Returns owned shop from specified position.
* If position is out of bound it returns null;
* @param position which shop position to return.
* @return field owned by player from list at position specified, or null if out of bounds.
*/
public Field getShop(int position)
{
if(position >= 0 && position < this.shopsOwned())
return this.shops.get(position);
return null;
}
}