-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvestor.java
316 lines (276 loc) · 7.16 KB
/
Investor.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
306
307
308
309
310
311
312
313
314
315
316
package game;
public class Investor {
private String investorName;
private int green;
private int location;
/**
* Default constructor set up for testing
*/
public Investor() {
this.setInvestorName("Tester");
this.setGreen(200);
this.setLocation(0);
}
/**
* Constructor
*
* @param investorName
*/
public Investor(String investorName) {
this.setInvestorName(investorName);
this.setGreen(200);
this.setLocation(0);
}
/**
* Constructor with args
*
* @param investorName
* @param green
* @param location
*/
public Investor(String investorName, int green, int location) {
this.setInvestorName(investorName);
this.setGreen(green);
this.setLocation(location);
}
/**
* Green is the money in this game
*
* @param greenTotal
*/
public void updateGreen(int greenTotal) {
this.setGreen(this.getGreen() + greenTotal);
}
/**
*
* @param greenTotal
* @return
*/
public String showGreenUpdate(int greenTotal) {
return String.format("\n%s updated to G%d", this.showCurrentGreen(), (this.getGreen() + greenTotal));
}
/**
*
* @param green
*/
public void collectGreen(int green) {
System.out.println(this.showGreenUpdate(green));
this.updateGreen(green);
}
/**
*
* @param investor
* @param greenTotal
*/
public void invest(Investor investor, int greenTotal) {
this.updateGreen(-greenTotal);
investor.updateGreen(greenTotal);
}
/**
* This method determines how much an investment will cost and then processes
* the payment between two Investors
*
* @param ownerOfLocation
* @param greenTotal
* @throws
*/
public void payInvestment (Investor ownerOfLocation, int greenTotal, SavingField sf) {
int investmentCost;
int numberOfEcoBubble = sf.getEcoBubble();
switch (sf.getSavingFieldTypes()) {
case REDUCE:
if (sf.isEcoDome()) {
investmentCost = 51; // eco dome
} else if (numberOfEcoBubble == 3) {
investmentCost = 31; // 3 eco bubbles
} else if (numberOfEcoBubble == 2) {
investmentCost = 21; // 2 eco bubbles
} else if (numberOfEcoBubble == 1) {
investmentCost = 11; // 1 eco bubble
} else {
investmentCost = 1; // land only investment
}
break;
case RECYCLE:
if (sf.isEcoDome()) {
investmentCost = 55;
} else if (numberOfEcoBubble == 3) {
investmentCost = 35;
} else if (numberOfEcoBubble == 2) {
investmentCost = 25;
} else if (numberOfEcoBubble == 1) {
investmentCost = 15;
} else {
investmentCost = 5; // land only investment
}
break;
case REBUILD:
if (sf.isEcoDome()) {
investmentCost = 60;
} else if (numberOfEcoBubble == 3) {
investmentCost = 40;
} else if (numberOfEcoBubble == 2) {
investmentCost = 30;
} else if (numberOfEcoBubble == 1) {
investmentCost = 20;
} else {
investmentCost = 10; // land only investment
}
break;
case RETHINK:
if (sf.isEcoDome()) {
investmentCost = 70;
} else if (numberOfEcoBubble == 3) {
investmentCost = 50;
} else if (numberOfEcoBubble == 2) {
investmentCost = 40;
} else if (numberOfEcoBubble == 1) {
investmentCost = 30;
} else {
investmentCost = 20; // land only investment
}
break;
default:
throw new IllegalArgumentException("Sorry, there has been an error");
}
if(!ownerOfLocation.hasNoGreen()) {
System.out.printf("\n%s paid G%d on an investment to %s!", this.getInvestorName(), investmentCost,
ownerOfLocation.getInvestorName());
System.out.println(this.showGreenUpdate(-investmentCost));
System.out.println(ownerOfLocation.showGreenUpdate(investmentCost));
this.invest(ownerOfLocation, investmentCost);
}else {
System.out.printf("\n%s paid G%d on an investment to our Planet!", this.getInvestorName(), investmentCost);
System.out.println(this.showGreenUpdate(-investmentCost));
}
}
public String showCurrentGreen() {
return String.format("%s's Green: G%d", this.getInvestorName(), this.getGreen());
}
/**
*
* @return
*/
public boolean hasNoGreen() {
return (this.getGreen() < 0);
}
/**
* returns true if the Investor owns at least one savingFieldType
*
* @param investor
* @return
*/
public boolean canBuy(GameBoard SaveOurPlanet) {
int SavingFieldTypesOwned = 0;
// iterates over each constant in SavingFieldTypes
for (SavingFieldTypes savingFieldTypes : SavingFieldTypes.values()) {
if (this.SavingFieldsOwnedBy(SaveOurPlanet, savingFieldTypes)) {
SavingFieldTypesOwned++;
}
}
return SavingFieldTypesOwned > 0;
}
public boolean canBuyEcoBubble(GameBoard saveOurPlanet) {
if (!this.canBuy(saveOurPlanet)) {
return false;
} else {
return saveOurPlanet.SavingFieldDevelopedBy(this).size() > 0;
}
}
public boolean canBuyEcoDome(GameBoard saveOurPlanet) {
if (!this.canBuy(saveOurPlanet)) {
return false;
} else {
return saveOurPlanet.SavingFieldWithThreeEcoBubbles(this).size() > 0;
}
}
public boolean ownsSavingFieldTypes(GameBoard SaveOurPlanet, SavingFieldTypes savingFieldTypes) {
return (SaveOurPlanet.SavingFieldOwnedBy(this)
.containsAll(SaveOurPlanet.SavingFieldsInGroup(savingFieldTypes)));
}
public boolean SavingFieldsOwnedBy(GameBoard saveOurPlanet, SavingFieldTypes savingFieldTypes) {
return (saveOurPlanet.SavingFieldOwnedBy(this)
.containsAll(saveOurPlanet.SavingFieldsInGroup(savingFieldTypes)));
}
/**
* returns true if the Investor will pass the Go Position while moving to target
* Position returns false if the target Position is the Collect Green Position,
* to avoid activating it twice
*
* @param investor: the Investor
* @param targetPositionIndex: int, where Investor will move to
* @return boolean
*/
public boolean willCollectGreen(int targetPositionIndex) {
if (targetPositionIndex == 0) {
return false;
} else {
// if the Investor collects green, the index of the target Position will always
// be smaller than index of their current position
return (this.getLocation() > targetPositionIndex);
}
}
/**
* Getter for investorName
*
* @return
*/
public String getInvestorName() {
return investorName;
}
/**
* Setter for investorName This includes a business rule that the investor name
* cannot be left blank
*
* @param investorName
* @throws IllegalArgumentException
*/
public void setInvestorName(String investorName) throws IllegalArgumentException {
if (investorName.toLowerCase().length() > 0) {
this.investorName = investorName;
} else {
throw new IllegalArgumentException("Invalid name");
}
}
/**
* Getter for green
*
* @return
*/
public int getGreen() {
return green;
}
/**
* Setter for green
*
* @param green
*/
public void setGreen(int green) {
if (this.green < 0) {
SaveOurPlanet.checkWinnerCondition();
} else {
this.green = green;
}
}
/**
* Getter for location
*
* @return
*/
public int getLocation() {
return location;
}
/**
* Setter for location
*
* @param location
* @throws IllegalArgumentException
*/
public void setLocation(int location) throws IllegalArgumentException {
if (location < 0) {
throw new IllegalArgumentException("Cannot set location as a negative position!");
} else {
this.location = location;
}
}
}