forked from fjricci/monopoly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.java
More file actions
509 lines (453 loc) · 12 KB
/
Board.java
File metadata and controls
509 lines (453 loc) · 12 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
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
package monopoly;
class Board {
private final int N = 41;
private final Square[] board; //representation of board
private final Deck chance;
private final Deck community;
//constructor for a new board of squares
public Board(Deck chance, Deck community, boolean deterministic) {
board = new Square[N];
this.chance = chance;
this.community = community;
//initialize board squares
for (int i = 0; i < N; i++)
board[i] = makeSquare(i, deterministic);
makeGroups();
makeRail();
makeUtil();
}
public int size() {
return N;
}
private Property property(String name) {
for (Square sq : board) {
if (sq instanceof Property && sq.name().equals(name))
return (Property) sq;
}
return null;
}
public Square square(int pos) {
return board[pos];
}
//return an array of the squares on the board
public Square[] getBoard() {
return board;
}
private Square makeSquare(int pos, boolean deterministic) {
switch (pos) {
case 0:
return go(pos);
case 1:
return mediterranean(pos);
case 2:
return community(pos);
case 3:
return baltic(pos);
case 4:
return income(pos);
case 5:
return reading(pos);
case 6:
return oriental(pos);
case 7:
return chance(pos);
case 8:
return vermont(pos);
case 9:
return connecticut(pos);
case 10:
return visiting(pos);
case 11:
return charles(pos);
case 12:
return electric(pos, deterministic);
case 13:
return states(pos);
case 14:
return virginia(pos);
case 15:
return pennsylvaniaRR(pos);
case 16:
return james(pos);
case 17:
return community(pos);
case 18:
return tennessee(pos);
case 19:
return newYork(pos);
case 20:
return parking(pos);
case 21:
return kentucky(pos);
case 22:
return chance(pos);
case 23:
return indiana(pos);
case 24:
return illinois(pos);
case 25:
return bAndO(pos);
case 26:
return atlantic(pos);
case 27:
return ventor(pos);
case 28:
return water(pos, deterministic);
case 29:
return marvin(pos);
case 30:
return toJail(pos);
case 31:
return pacific(pos);
case 32:
return carolina(pos);
case 33:
return community(pos);
case 34:
return pennsylvaniaAve(pos);
case 35:
return shortLine(pos);
case 36:
return chance(pos);
case 37:
return park(pos);
case 38:
return luxury(pos);
case 39:
return boardwalk(pos);
case 40:
return jail(pos);
default:
return null;
}
}
private void makeGroups() {
makeGroup("Mediterranean Avenue", "Baltic Avenue");
makeGroup("Oriental Avenue", "Vermont Avenue", "Connecticut Avenue");
makeGroup("St. Charles Place", "States Avenue", "Virginia Avenue");
makeGroup("St. James Place", "Tennessee Avenue", "New York Avenue");
makeGroup("Kentucky Avenue", "Indiana Avenue", "Illinois Avenue");
makeGroup("Atlantic Avenue", "Ventor Avenue", "Marvin Gardens");
makeGroup("Pennsylvania Avenue", "North Carolina Avenue", "Pacific Avenue");
makeGroup("Park Place", "Boardwalk");
}
private void makeRail() {
Railroad a = (Railroad) square(5);
Railroad b = (Railroad) square(15);
Railroad c = (Railroad) square(25);
Railroad d = (Railroad) square(35);
a.createGroup(b, c, d);
b.createGroup(a, c, d);
c.createGroup(a, b, d);
d.createGroup(a, b, c);
}
private void makeUtil() {
Utility a = (Utility) square(12);
Utility b = (Utility) square(28);
a.setOther(b);
b.setOther(a);
}
private void makeGroup(String nameA, String nameB) {
makeGroup(nameA, nameB, null);
}
private void makeGroup(String nameA, String nameB, String nameC) {
Property propA = property(nameA);
Property propB = property(nameB);
Property propC = null;
if (nameC != null)
propC = property(nameC);
if (propA == null || propB == null)
throw new RuntimeException("Bad property");
propA.setGroup(propB, propC);
propB.setGroup(propA, propC);
if (propC != null)
propC.setGroup(propA, propB);
}
private Square luxury(int pos) {
return new Taxes(pos, false);
}
private Square shortLine(int pos) {
return new Railroad("Short Line", pos);
}
private Square toJail(int pos) {
return new Jail("Go to Jail", pos, Jail.JailType.TO_JAIL);
}
private Square water(int pos, boolean deterministic) {
return new Utility("Water Works", pos, deterministic);
}
private Square bAndO(int pos) {
return new Railroad("B & O Railroad", pos);
}
private Square pennsylvaniaRR(int pos) {
return new Railroad("Pennsylvania Railroad", pos);
}
private Square electric(int pos, boolean deterministic) {
return new Utility("Electric Company", pos, deterministic);
}
private Square visiting(int pos) {
return new Jail("Just Visiting", pos, Jail.JailType.VISITING);
}
private Square jail(int pos) {
return new Jail("In Jail", pos, Jail.JailType.IN_JAIL);
}
private Square chance(int pos) {
return new Cards("Chance", pos, Card.CardType.CHANCE, chance);
}
private Square reading(int pos) {
return new Railroad("Reading Railroad", pos);
}
private Square income(int pos) {
return new Taxes(pos, true);
}
private Square community(int pos) {
return new Cards("Community Chest", pos, Card.CardType.COMMUNITY, community);
}
private Square go(int pos) {
return new Inactive("Go", pos);
}
private Square mediterranean(int pos) {
int rent = 2;
int oneH = 10;
int twoH = 30;
int threeH = 90;
int fourH = 160;
int hotel = 250;
int cost = 60;
int houses = 50;
return new Property("Mediterranean Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square baltic(int pos) {
int rent = 4;
int oneH = 20;
int twoH = 60;
int threeH = 180;
int fourH = 320;
int hotel = 450;
int cost = 60;
int houses = 50;
return new Property("Baltic Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square oriental(int pos) {
int rent = 6;
int oneH = 30;
int twoH = 90;
int threeH = 270;
int fourH = 400;
int hotel = 550;
int cost = 100;
int houses = 50;
return new Property("Oriental Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square vermont(int pos) {
int rent = 6;
int oneH = 30;
int twoH = 90;
int threeH = 270;
int fourH = 400;
int hotel = 550;
int cost = 100;
int houses = 50;
return new Property("Vermont Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square connecticut(int pos) {
int rent = 8;
int oneH = 40;
int twoH = 100;
int threeH = 300;
int fourH = 450;
int hotel = 600;
int cost = 120;
int houses = 50;
return new Property("Connecticut Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square charles(int pos) {
int rent = 10;
int oneH = 50;
int twoH = 150;
int threeH = 450;
int fourH = 625;
int hotel = 750;
int cost = 140;
int houses = 100;
return new Property("St. Charles Place", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square states(int pos) {
int rent = 10;
int oneH = 50;
int twoH = 150;
int threeH = 450;
int fourH = 625;
int hotel = 750;
int cost = 140;
int houses = 100;
return new Property("States Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square virginia(int pos) {
int rent = 12;
int oneH = 60;
int twoH = 180;
int threeH = 500;
int fourH = 700;
int hotel = 900;
int cost = 160;
int houses = 100;
return new Property("Virginia Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square james(int pos) {
int rent = 14;
int oneH = 70;
int twoH = 200;
int threeH = 550;
int fourH = 750;
int hotel = 950;
int cost = 180;
int houses = 100;
return new Property("St. James Place", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square tennessee(int pos) {
int rent = 14;
int oneH = 70;
int twoH = 200;
int threeH = 550;
int fourH = 750;
int hotel = 950;
int cost = 180;
int houses = 100;
return new Property("Tennessee Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square newYork(int pos) {
int rent = 16;
int oneH = 80;
int twoH = 220;
int threeH = 600;
int fourH = 800;
int hotel = 1000;
int cost = 200;
int houses = 100;
return new Property("New York Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square kentucky(int pos) {
int rent = 18;
int oneH = 90;
int twoH = 250;
int threeH = 700;
int fourH = 875;
int hotel = 1050;
int cost = 220;
int houses = 150;
return new Property("Kentucky Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square indiana(int pos) {
int rent = 18;
int oneH = 90;
int twoH = 250;
int threeH = 700;
int fourH = 875;
int hotel = 1050;
int cost = 220;
int houses = 150;
return new Property("Indiana Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square illinois(int pos) {
int rent = 20;
int oneH = 100;
int twoH = 300;
int threeH = 750;
int fourH = 925;
int hotel = 1100;
int cost = 240;
int houses = 150;
return new Property("Illinois Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square atlantic(int pos) {
int rent = 22;
int oneH = 110;
int twoH = 330;
int threeH = 800;
int fourH = 975;
int hotel = 1150;
int cost = 260;
int houses = 150;
return new Property("Atlantic Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square ventor(int pos) {
int rent = 22;
int oneH = 110;
int twoH = 330;
int threeH = 800;
int fourH = 975;
int hotel = 1150;
int cost = 260;
int houses = 150;
return new Property("Ventor Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square marvin(int pos) {
int rent = 24;
int oneH = 120;
int twoH = 360;
int threeH = 850;
int fourH = 1025;
int hotel = 1200;
int cost = 280;
int houses = 150;
return new Property("Marvin Gardens", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square pacific(int pos) {
int rent = 26;
int oneH = 130;
int twoH = 390;
int threeH = 900;
int fourH = 1100;
int hotel = 1275;
int cost = 300;
int houses = 200;
return new Property("Pacific Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square carolina(int pos) {
int rent = 26;
int oneH = 130;
int twoH = 390;
int threeH = 900;
int fourH = 1100;
int hotel = 1275;
int cost = 300;
int houses = 200;
return new Property("North Carolina Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square pennsylvaniaAve(int pos) {
int rent = 28;
int oneH = 150;
int twoH = 450;
int threeH = 1000;
int fourH = 1200;
int hotel = 1400;
int cost = 320;
int houses = 200;
return new Property("Pennsylvania Avenue", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square park(int pos) {
int rent = 35;
int oneH = 175;
int twoH = 500;
int threeH = 1100;
int fourH = 1300;
int hotel = 1500;
int cost = 350;
int houses = 200;
return new Property("Park Place", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square boardwalk(int pos) {
int rent = 50;
int oneH = 200;
int twoH = 600;
int threeH = 1400;
int fourH = 1700;
int hotel = 2000;
int cost = 400;
int houses = 200;
return new Property("Boardwalk", pos, rent, oneH, twoH, threeH, fourH, hotel, cost, houses);
}
private Square parking(int pos) {
return new Inactive("Free Parking", pos);
}
}