-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonopoly.java
More file actions
3084 lines (2637 loc) · 104 KB
/
Copy pathMonopoly.java
File metadata and controls
3084 lines (2637 loc) · 104 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
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Purpose: The game runs a game of monopoly with all the neccessary features to enjoy with your friends(Buying, Upgrading, Rent, Rolling, Ending Turn), and even features individual jail features(double role, pay 50, wait turn)!
import java.awt.*;
import javax.swing.*;
import javax.swing.ImageIcon;
import java.awt.event.*;
import java.util.*;
import java.io.*;
public class Monopoly extends JFrame implements ActionListener {
// Array for all the property houses
JButton mediterraneanhouses[], Baltichouses[], orientalhouses[], vermonthouses[], connecticuthouses[],
StCharlesHouses[], StatesAveHouses[], VirginiaAveHouses[], StJamesHouses[], TennesseHouses[],
NewYorkHouses[], KentuckyHouses[], IndianaHouses[], IllinoisHouses[], AtlanticHouses[], VentnorHouses[],
MarvinHouses[], PacificAvenueHouses[], NorthCarolinaHouses[], PennsylvaniaAveHouses[], parkPlaceHouses[],
boardwalkHouses[];
static JButton posButtonsBlue[] = new JButton[40]; // Array for player 2 positions along the board
static JButton posButtonsRed[] = new JButton[40]; // Array for player 1 positions along the board
static ImageIcon images[] = new ImageIcon[40]; // All images for each space on the board
JTextArea commentary, p1List, p2List; // text areas for the ingame commentary and player properties owned
boolean turn = true; // to differenitiate player turns
int p1Pos = 0, p2Pos = 0; // positions for players
static int p1Money = 500, p2Money = 500; // player money
static boolean player1Roll = true; // flag so the fiirst thing player does is roll
static boolean player2Roll = true; // same for player 2
// all the properties that can be bought
boolean buyableProperties[] = { false, true, false, true, false, true, true, false, true, true, false, true, true,
true, true, true, true, false, true, true, false, true, false, true, true, true, true, true, true, true,
false, true, true, false, true, true, false, true, false, true };
// the amount they cost
int PropertyPrice[] = { 0, 60, 0, 60, 0, 200, 100, 0, 100, 120, 0, 140, 150, 140, 160, 200, 180, 0, 180, 200, 0,
220, 0, 220, 240, 200, 260, 260, 150, 280, 0, 300, 300, 0, 320, 200, 0, 350, 0, 400 };
// The names of all the properties
String[] properties = { "Go", "Mediterranean Avenue", "Community Chest", "Baltic Avenue", "Income Tax",
"Reading Railroad", "Oriental Avenue", "Chance", "Vermont Avenue", "Connecticut Avenue",
"Jail/Just Visiting", "St. Charles Place", "Electric Company", "States Avenue", "Virginia Avenue",
"Pennsylvania Railroad", "St. James Place", "Community Chest", "Tennessee Avenue", "New York Avenue",
"Free Parking", "Kentucky Avenue", "Chance", "Indiana Avenue", "Illinois Avenue", "B&O Railroad",
"Atlantic Avenue", "Ventnor Avenue", "Water Works", "Marvin Gardens", "Go to Jail", "Pacific Avenue",
"North Carolina Avenue", "Community Chest", "Pennsylvania Avenue", "Short Line", "Chance", "Park Place",
"Luxury Tax", "Boardwalk" };
// panel for the title deeds to be added on
JPanel DeedCard;
// vectors for player properites owned
Vector player1Assets = new Vector();
Vector player2Assets = new Vector();
int dice = 0; // dice
// all the title deed cards
String titleDeedNames[] = { "./assets/blank.jpg", "./assets/MediterraneanTD.jpg", "./assets/blank.jpg", "./assets/BalticTD.jpg", "./assets/blank.jpg",
"./assets/ReadingRRTD.jpg", "./assets/orientalTD.jpg", "./assets/blank.jpg", "./assets/vermontTD.jpg", "./assets/connecticutTD.jpg", "./assets/blank.jpg",
"./assets/StCharlesTD.jpg", "./assets/electricTD.jpg", "./assets/StatesTD.jpg", "./assets/virginiaTD.jpg", "./assets/PennsylvaniaRRTD.jpg",
"./assets/StJamesTD.jpg", "./assets/blank.jpg", "./assets/TennesseeTD.jpg", "./assets/NewYorkTD.jpg", "./assets/blank.jpg", "./assets/kentuckyTD.jpg",
"./assets/blank.jpg", "./assets/IndianaTD.jpg", "./assets/illinoisTD.jpg", "./assets/B_ORRTD.jpg", "./assets/atlanticTD.jpg", "./assets/ventnorTD.jpg",
"./assets/waterTD.jpg", "./assets/marvinTD.jpg", "./assets/blank.jpg", "./assets/pacificTD.jpg", "./assets/carolinaTD.jpg", "./assets/blank.jpg",
"./assets/pennsylvaniaTD.jpg", "./assets/ShortLineRRTD.png", "./assets/blank.jpg", "./assets/parkPlaceTD.jpg", "./assets/blank.jpg", "./assets/boardwalkTD.jpg" };
// imageicons holding the names of title deed cards
ImageIcon titleDeedCards[] = new ImageIcon[40];
LandingPage25 abc = new LandingPage25(); // starting page
String p1Name; // names
String p2Name;
// community chest and chance cards
String CommunityChest[] = { "./assets/BankErrorCommunityChest.jpg", "./assets/BeautyContestCommunityChest.jpg",
"./assets/CC_Advance_to_GoCommunityChest.jpg", "./assets/ConsultancyFeeCommunityChest.jpg", "./assets/DoctorFeeCommunityChest.jpg",
"./assets/GetOutOfJailCommunityChest.jpg", "./assets/GoToJailCommunityChest.jpg", "./assets/HolidayFundMatureCommunityChest.jpg",
"./assets/IncomeTaxRefundCommunityChest.jpg", "./assets/Inherit100CommunityChest.jpg",
"./assets/LifeInsuranceMaturesCommunityChest.jpg", "./assets/PayHospitalCommunityChest.jpg", "./assets/StockSaleCommunityChest.jpg" };
String ChanceCards[] = { "./assets/Advance_To_BoardwalkChance.jpg", "./assets/Advance_To_GoChance.jpg",
"./assets/AdvanceIllinoisAvenueChance.jpg", "./assets/AdvanceToStCharlesChance.jpg", "./assets/BackThreeChance.jpg",
"./assets/ChairMaxChance.jpg", "./assets/DividenDChance.jpg", "./assets/GoToJailChance.jpg", "./assets/LoanMatureChance.jpg",
"./assets/OutOfJailChance.jpg", "./assets/tripreadingrailroadChance.jpg" };
int p1numRR = 0; // num railroads owned
int p1numUtilities = 0; // num of utitlites
int p2numRR = 0;
int p2numUtilities = 0;
static ImageIcon[] Chest = new ImageIcon[13]; // imageicon for community cards
static ImageIcon[] Chance = new ImageIcon[11]; // imageicons for chance
boolean jp1Rights = false; // rights to check if you chose an outcome in jail for both players
boolean jp2Rights = false;
boolean jailallowed = false; // ensures when p1 is jail only their options are accessed and vice versa for p2
boolean p1flag = false; // To ensure actionlistneres are activated twice
boolean p2flag = false;
EndScreen efg = new EndScreen(); // ending screen
boolean winner; // to see who won
int score1 = 0; // score for overall wins
int score2 = 0;
boolean p1jailCard = false; // get out jail free cards
boolean p2jailCard = false;
int propertyUpgrades[] = { 6, 0, 6, 0, 6, 6, 0, 6, 0, 0, 6, 0, 6, 0, 0, 6, 0, 6, 0, 0, 6, 0, 6, 0, 0, 6, 0, 0, 6, 0,
6, 0, 0, 6, 0, 6, 6, 0, 6, 0 }; // num of upgrades for each property
ImageIcon backChest; // image of the back card of the community chest
JLabel chestBack; // label to hold image
boolean p1Jail = false, p2Jail = false; // if players in jail
int p1jailturn = 0; // amount of turns spent in jail
int p2jailturn = 0;
ImageIcon backChance; // same thing as community chest but for chance
JLabel chanceBack;
ImageIcon backDeed; // same thing as community chest but for chance
JLabel DeedBack;
boolean p1Rights, p2Rights; // rights ensure the player has rolled before perfomring an action
String word; // to get the existing text in the commentary
String prop1, prop2; // string to get existing texts in the property owned textfields
int[][] rentData = {
// Rent for a property with no house, 1 house, 2 houses, 3 houses, 4 houses,
// hotel
{ 0, 0, 0, 0, 0, 0 }, // Go
{ 2, 10, 30, 90, 160, 250 }, // Mediterranean Avenue
{ 0, 0, 0, 0, 0, 0 }, // Community Chest
{ 4, 20, 60, 180, 320, 450 }, // Baltic Avenue
{ 0, 0, 0, 0, 0, 0 }, // Income Tax
{ 0, 0, 0, 0, 0, 0 }, // Reading Railroad
{ 6, 30, 90, 270, 400, 550 }, // Oriental Avenue
{ 0, 0, 0, 0, 0, 0 }, // Chance
{ 6, 30, 90, 270, 400, 550 }, // Vermont Avenue
{ 8, 40, 100, 300, 450, 600 }, // Connecticut Avenue
{ 0, 0, 0, 0, 0, 0 }, // Jail
{ 10, 50, 150, 450, 625, 750 }, // St. Charles Place
{ 0, 0, 0, 0, 0, 0 }, // Electric Company
{ 10, 50, 150, 450, 625, 750 }, // States Avenue
{ 12, 60, 180, 500, 700, 900 }, // Virginia Avenue
{ 0, 0, 0, 0, 0, 0 }, // Pennsylvania Railroad
{ 14, 70, 200, 550, 750, 950 }, // St. James Place
{ 0, 0, 0, 0, 0, 0 }, // Community Chest
{ 14, 70, 200, 550, 750, 950 }, // Tennessee Avenue
{ 16, 80, 220, 600, 800, 1000 }, // New York Avenue
{ 0, 0, 0, 0, 0, 0 }, // Free Parking
{ 18, 90, 250, 700, 875, 1050 }, // Kentucky Avenue
{ 0, 0, 0, 0, 0, 0 }, // Chance
{ 18, 90, 250, 700, 875, 1050 }, // Indiana Avenue
{ 20, 100, 300, 750, 925, 1100 }, // Illinois Avenue
{ 0, 0, 0, 0, 0, 0 }, // B. & O. Railroad
{ 22, 110, 330, 800, 975, 1150 }, // Atlantic Avenue
{ 22, 110, 330, 800, 975, 1150 }, // Ventnor Avenue
{ 0, 0, 0, 0, 0, 0 }, // Water Works
{ 24, 120, 360, 850, 1025, 1200 }, // Marvin Gardens
{ 0, 0, 0, 0, 0, 0 }, // Go to Jail
{ 26, 130, 390, 900, 1100, 1275 }, // Pacific Avenue
{ 26, 130, 390, 900, 1100, 1275 }, // North Carolina Avenue
{ 0, 0, 0, 0, 0, 0 }, // Community Chest
{ 28, 150, 450, 1000, 1200, 1400 }, // Pennsylvania Avenue
{ 0, 0, 0, 0, 0, 0 }, // Short Line Railroad
{ 0, 0, 0, 0, 0, 0 }, // Chance
{ 35, 175, 500, 1200, 1400, 1700 }, // Park Place
{ 0, 0, 0, 0, 0, 0 }, // Luxury Tax
{ 50, 200, 600, 1400, 1700, 2000 } }; // Boardwalk
public static void main(String args[]) {
new Monopoly();
}
public Monopoly() {
JFrame frame = new JFrame();
// Create a JFrame (main window)
JPanel MainPanel = (JPanel) frame.getContentPane();
frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
backChest = new ImageIcon("./assets/CommunityChestBackCard.jpg");
chestBack = new JLabel(backChest); // adding back card of community chest
backChance = new ImageIcon("./assets/ChanceBackCard.jpg");
chanceBack = new JLabel(backChance); // adding back card of chance
backDeed = new ImageIcon("./assets/blank.jpg");
DeedBack = new JLabel(backDeed);
String names[] = abc.LandingPage22(); // calling landing page and choosing names
p1Name = names[0]; // storing names
p2Name = names[1];
JPanel panel = new JPanel(new GridBagLayout()); // Grid Bag layout: Allows you to store components in a
// grid-like structure, however it also gives you the
// flexibitliy of placing components where you want using
// constraints and we can also use it make componenets span
// across different rows and columns
GridBagConstraints constraints = new GridBagConstraints(); // Constraints for layout
// names of all the properties
String imageNames[] = { "./assets/Go.jpg", "./assets/Mediterranean.jpg", "./assets/community_chest.jpg",
"./assets/Baltic.jpg", "./assets/IncomeTax.jpg", "./assets/Reading Railroad.jpg",
"./assets/Oriental.jpg", "./assets/Chance.jpg", "./assets/vermont.jpg",
"./assets/Connecticut Avenue.jpg", "./assets/In Jail.jpg", "./assets/St. Charles Place.jpg",
"./assets/Electric Company.jpg", "./assets/States Avenue.jpg", "./assets/Virginia Avenue.jpg",
"./assets/Pennsylvania RailRoad.jpg", "./assets/St. James Place.jpg", "./assets/community_chest2.jpg",
"./assets/Tennessee Avenue.jpg", "./assets/New York Avenue.jpg", "./assets/FreeParking.jpg",
"./assets/Kentucky Avenue.jpg", "./assets/Chance2.jpg", "./assets/Indiana Avenue.jpg",
"./assets/Illinois Avenue.jpg", "./assets/B_O RailRoad.jpg", "./assets/Atlantic Avenue.jpg",
"./assets/Ventnor Avenue.jpg", "./assets/Water Works.jpg", "./assets/Marvin Gardens.jpg",
"./assets/GoToJail.jpg", "./assets/Pacific Avenue.jpg", "./assets/North Carolina Avenue.jpg",
"./assets/CommunityChest3.jpg", "./assets/Pennsylvania Avenue.jpg", "./assets/Short Line railroad.jpg",
"./assets/Chance3.jpg", "./assets/Park Place.jpg", "./assets/Luxury Tax.jpg",
"./assets/Boardwalk.jpg" };
for (int count = 0; count < 40; count++) // connecting the file names with the image icons for the title deed
{
titleDeedCards[count] = new ImageIcon(titleDeedNames[count]);
}
// Community Chest
for (int count = 0; count < 13; count++) // doing the same thing for community chest
{
Chest[count] = new ImageIcon(CommunityChest[count]);
}
// Chance
for (int count = 0; count < 11; count++) // doing the same thing for chance
{
Chance[count] = new ImageIcon(ChanceCards[count]);
}
// Board Panelss
for (int count = 0; count < 40; count++) // doing the same thing for the board panels
{
images[count] = new ImageIcon(imageNames[count]);
}
// storing each image into the labels
JLabel pos[] = new JLabel[40];
for (int count = 0; count < 40; count++) {
pos[count] = new JLabel(images[count]);
}
// for pos buttons
for (int count = 0; count < 40; count++) {
posButtonsBlue[count] = new JButton(""); // creating 40 buttons for each pos for blue and red
posButtonsRed[count] = new JButton("");
if (count <= 10) // horizontal buttons for bottom side
{
posButtonsRed[count].setPreferredSize(new Dimension(28, 14)); // changing size of buttons
posButtonsBlue[count].setPreferredSize(new Dimension(28, 14));
}
if (count > 10 && count <= 20) // vertical buttons for left side
{
posButtonsRed[count].setPreferredSize(new Dimension(14, 28));
posButtonsBlue[count].setPreferredSize(new Dimension(14, 28));
}
if (count > 20 && count <= 30) // horizontal for top buttons
{
posButtonsRed[count].setPreferredSize(new Dimension(28, 14));
posButtonsBlue[count].setPreferredSize(new Dimension(28, 14));
}
if (count > 30 && count <= 40) // vertical buttons for right side
{
posButtonsRed[count].setPreferredSize(new Dimension(14, 28));
posButtonsBlue[count].setPreferredSize(new Dimension(14, 28));
}
}
// Go panel
JPanel GoPanel = new JPanel();
GoPanel.add(pos[0]); // adding the label on the panel
JPanel GOPos = new JPanel(); // creating a panel for the buttons
GOPos.setLayout(new GridLayout(1, 2)); // setting a layout
posButtonsRed[0].setPreferredSize(new Dimension(40, 14)); // buttons on GO, JAIL, FREE PARKING, JUST VISITING,
// are these sizes
posButtonsBlue[0].setPreferredSize(new Dimension(40, 14));
GOPos.add(posButtonsRed[0]); // adding buttons onto the panel
GOPos.add(posButtonsBlue[0]);
// mediterranean card - pos = 1
JPanel mediterraneanCard = new JPanel(); // creating panel for the actual image card
mediterraneanCard.add(pos[1]);
// mediterranean Houses - pos = 1
JPanel mediterraneanHouse = new JPanel(); // creating panel the houses
mediterraneanHouse.setLayout(new GridLayout(1, 5)); // creating layout
mediterraneanhouses = new JButton[5];
for (int count = 0; count < 5; count++) // adding buttons to the panel
{
mediterraneanhouses[count] = new JButton();
mediterraneanhouses[count].setPreferredSize(new Dimension(11, 13));
mediterraneanHouse.add(mediterraneanhouses[count]);
}
// mediterranean player pos = 1
JPanel mediterraneanPos = new JPanel(); // creating panel for the position buttons
mediterraneanPos.setLayout(new GridLayout(1, 2));
mediterraneanPos.add(posButtonsRed[1]); // adding buttons to the panel
mediterraneanPos.add(posButtonsBlue[1]);
// This process above is for all the properties except for railroad, utilites,
// Income and Luxury Tax, community chest and chance.
// The specificed space will not have houses
// community chest pos = 2
JPanel CCCard = new JPanel();
CCCard.add(pos[2]);
// community chest pos pos = 2
JPanel CCPos = new JPanel();
CCPos.setLayout(new GridLayout(1, 2));
CCPos.add(posButtonsRed[2]);
CCPos.add(posButtonsBlue[2]);
// baltic card - pos = 3
JPanel balticCard = new JPanel();
balticCard.add(pos[3]);
// baltic Houses - pos = 3
JPanel balticHouse = new JPanel();
balticHouse.setLayout(new GridLayout(1, 5));
Baltichouses = new JButton[5];
for (int count = 0; count < 5; count++) {
Baltichouses[count] = new JButton();
Baltichouses[count].setPreferredSize(new Dimension(11, 13));
balticHouse.add(Baltichouses[count]);
}
// baltic player pos =3
JPanel balticPos = new JPanel();
balticPos.setLayout(new GridLayout(1, 2));
balticPos.add(posButtonsRed[3]);
balticPos.add(posButtonsBlue[3]);
// Income Tax pos = 4
JPanel IncomeTax = new JPanel();
IncomeTax.add(pos[4]);
// Income Tax pos = 4
JPanel ITPos = new JPanel();
ITPos.setLayout(new GridLayout(1, 2));
ITPos.add(posButtonsRed[4]);
ITPos.add(posButtonsBlue[4]);
// Reading railroad pos = 5
JPanel ReadingRR = new JPanel();
ReadingRR.add(pos[5]);
// community chest pos pos = 2
JPanel ReadingRRPos = new JPanel();
ReadingRRPos.setLayout(new GridLayout(1, 2));
ReadingRRPos.add(posButtonsRed[5]);
ReadingRRPos.add(posButtonsBlue[5]);
JPanel orientalCard = new JPanel();
orientalCard.add(pos[6]);
// oriental houses pos = 6
JPanel OrientalHouse = new JPanel();
OrientalHouse.setLayout(new GridLayout(1, 5));
orientalhouses = new JButton[5];
for (int count = 0; count < 5; count++) {
orientalhouses[count] = new JButton();
orientalhouses[count].setPreferredSize(new Dimension(11, 13));
OrientalHouse.add(orientalhouses[count]);
}
// oriental player pos = 6
JPanel orientalPos = new JPanel();
orientalPos.setLayout(new GridLayout(1, 2));
orientalPos.add(posButtonsRed[6]);
orientalPos.add(posButtonsBlue[6]);
// Chance Cards
JPanel ChanceCard = new JPanel();
ChanceCard.add(pos[7]);
// chance card pos = 7
JPanel ChancePos = new JPanel();
ChancePos.setLayout(new GridLayout(1, 2));
ChancePos.add(posButtonsRed[7]);
ChancePos.add(posButtonsBlue[7]);
// vermont Card - pos = 8
JPanel vermontCard = new JPanel();
vermontCard.add(pos[8]);
// vermont houses pos = 8
JPanel VermontHouse = new JPanel();
VermontHouse.setLayout(new GridLayout(1, 5));
vermonthouses = new JButton[5];
for (int count = 0; count < 5; count++) {
vermonthouses[count] = new JButton();
vermonthouses[count].setPreferredSize(new Dimension(11, 13));
VermontHouse.add(vermonthouses[count]);
}
// vermont player pos = 8
JPanel vermontPos = new JPanel();
vermontPos.setLayout(new GridLayout(1, 2));
vermontPos.add(posButtonsRed[8]);
vermontPos.add(posButtonsBlue[8]);
// connecticut
JPanel connecticutCard = new JPanel();
connecticutCard.add(pos[9]);
// connecticut houses pos = 9
JPanel connecticutHouse = new JPanel();
connecticutHouse.setLayout(new GridLayout(1, 5));
connecticuthouses = new JButton[5];
for (int count = 0; count < 5; count++) {
connecticuthouses[count] = new JButton();
connecticuthouses[count].setPreferredSize(new Dimension(11, 13));
connecticutHouse.add(connecticuthouses[count]);
}
// connecticut player pos = 9
JPanel connecticutPos = new JPanel();
connecticutPos.setLayout(new GridLayout(1, 2));
connecticutPos.add(posButtonsRed[9]);
connecticutPos.add(posButtonsBlue[9]);
// Jail Card = 10
JPanel JailCard = new JPanel();
JailCard.add(pos[10]);
// Jail Card = 10
JPanel JailPos = new JPanel();
JailPos.setLayout(new GridLayout(1, 2));
posButtonsRed[10].setPreferredSize(new Dimension(40, 14));
posButtonsBlue[10].setPreferredSize(new Dimension(40, 14));
JailPos.add(posButtonsRed[10]);
JailPos.add(posButtonsBlue[10]);
// St Charles
JPanel StCharlesCard = new JPanel();
StCharlesCard.add(pos[11]);
// St Charles Houses - pos = 11
JPanel StCharlesHouse = new JPanel();
StCharlesHouse.setLayout(new GridLayout(5, 1));
StCharlesHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
StCharlesHouses[count] = new JButton();
StCharlesHouses[count].setPreferredSize(new Dimension(13, 11));
StCharlesHouse.add(StCharlesHouses[count]);
}
// St Charles player pos = 11
JPanel StCharlesPos = new JPanel();
StCharlesPos.setLayout(new GridLayout(2, 1));
StCharlesPos.add(posButtonsRed[11]);
StCharlesPos.add(posButtonsBlue[11]);
// Electric Company
JPanel ElectricCard = new JPanel();
ElectricCard.add(pos[12]);
JPanel ElectricPos = new JPanel();
ElectricPos.setLayout(new GridLayout(2, 1));
ElectricPos.add(posButtonsRed[12]);
ElectricPos.add(posButtonsBlue[12]);
// States Avenue
JPanel StatesAveCard = new JPanel();
StatesAveCard.add(pos[13]);
JPanel StatesAveHouse = new JPanel();
StatesAveHouse.setLayout(new GridLayout(5, 1));
StatesAveHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
StatesAveHouses[count] = new JButton();
StatesAveHouses[count].setPreferredSize(new Dimension(13, 11));
StatesAveHouse.add(StatesAveHouses[count]);
}
JPanel StatesAvePos = new JPanel();
StatesAvePos.setLayout(new GridLayout(2, 1));
StatesAvePos.add(posButtonsRed[13]);
StatesAvePos.add(posButtonsBlue[13]);
// Virigina Avenue
JPanel VirginiaAveCard = new JPanel();
VirginiaAveCard.add(pos[14]);
JPanel VirginiaAveHouse = new JPanel();
VirginiaAveHouse.setLayout(new GridLayout(5, 1));
VirginiaAveHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
VirginiaAveHouses[count] = new JButton();
VirginiaAveHouses[count].setPreferredSize(new Dimension(13, 11));
VirginiaAveHouse.add(VirginiaAveHouses[count]);
}
JPanel VirginiaAvePos = new JPanel();
VirginiaAvePos.setLayout(new GridLayout(2, 1));
VirginiaAvePos.add(posButtonsRed[14]);
VirginiaAvePos.add(posButtonsBlue[14]);
// Pennsylvania railroad
JPanel PennsylvaniaRRCard = new JPanel();
PennsylvaniaRRCard.add(pos[15]);
JPanel PennsylvaniaRRPos = new JPanel();
PennsylvaniaRRPos.setLayout(new GridLayout(2, 1));
PennsylvaniaRRPos.add(posButtonsRed[15]);
PennsylvaniaRRPos.add(posButtonsBlue[15]);
// St James
JPanel StJamesCard = new JPanel();
StJamesCard.add(pos[16]);
JPanel StJamesHouse = new JPanel();
StJamesHouse.setLayout(new GridLayout(5, 1));
StJamesHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
StJamesHouses[count] = new JButton();
StJamesHouses[count].setPreferredSize(new Dimension(13, 11));
StJamesHouse.add(StJamesHouses[count]);
}
JPanel StJamesPos = new JPanel();
StJamesPos.setLayout(new GridLayout(2, 1));
StJamesPos.add(posButtonsRed[16]);
StJamesPos.add(posButtonsBlue[16]);
// Community Chest 2
JPanel CCCard2 = new JPanel();
CCCard2.add(pos[17]);
JPanel CCCard2Pos = new JPanel();
CCCard2Pos.setLayout(new GridLayout(2, 1));
CCCard2Pos.add(posButtonsRed[17]);
CCCard2Pos.add(posButtonsBlue[17]);
// Tennesse Avenue
JPanel TennesseCard = new JPanel();
TennesseCard.add(pos[18]);
JPanel TennesseHouse = new JPanel();
TennesseHouse.setLayout(new GridLayout(5, 1));
TennesseHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
TennesseHouses[count] = new JButton();
TennesseHouses[count].setPreferredSize(new Dimension(13, 11));
TennesseHouse.add(TennesseHouses[count]);
}
JPanel TennessePos = new JPanel();
TennessePos.setLayout(new GridLayout(2, 1));
TennessePos.add(posButtonsRed[18]);
TennessePos.add(posButtonsBlue[18]);
// New York Avenue
JPanel NewYorkCard = new JPanel();
NewYorkCard.add(pos[19]);
JPanel NewYorkHouse = new JPanel();
NewYorkHouse.setLayout(new GridLayout(5, 1));
NewYorkHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
NewYorkHouses[count] = new JButton();
NewYorkHouses[count].setPreferredSize(new Dimension(13, 11));
NewYorkHouse.add(NewYorkHouses[count]);
}
JPanel NewYorkPos = new JPanel();
NewYorkPos.setLayout(new GridLayout(2, 1));
NewYorkPos.add(posButtonsRed[19]);
NewYorkPos.add(posButtonsBlue[19]);
// Free Parking
JPanel FreeParking = new JPanel();
FreeParking.add(pos[20]);
JPanel FreeParkingPos = new JPanel();
FreeParkingPos.setLayout(new GridLayout(2, 1));
posButtonsRed[20].setPreferredSize(new Dimension(14, 40));
posButtonsBlue[20].setPreferredSize(new Dimension(14, 40));
FreeParkingPos.add(posButtonsRed[20]);
FreeParkingPos.add(posButtonsBlue[20]);
// Kentucky Avenue
JPanel KentuckyCard = new JPanel();
KentuckyCard.add(pos[21]);
JPanel KentuckyHouse = new JPanel();
KentuckyHouse.setLayout(new GridLayout(1, 5));
KentuckyHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
KentuckyHouses[count] = new JButton();
KentuckyHouses[count].setPreferredSize(new Dimension(11, 13));
KentuckyHouse.add(KentuckyHouses[count]);
}
JPanel KentuckyPos = new JPanel();
KentuckyPos.setLayout(new GridLayout(1, 2));
KentuckyPos.add(posButtonsRed[21]);
KentuckyPos.add(posButtonsBlue[21]);
// Chance 2
JPanel ChanceCard2 = new JPanel();
ChanceCard2.add(pos[22]);
JPanel ChanceCard2Pos = new JPanel();
ChanceCard2Pos.setLayout(new GridLayout(1, 2));
ChanceCard2Pos.add(posButtonsRed[22]);
ChanceCard2Pos.add(posButtonsBlue[22]);
// Indiana Avenue
JPanel IndianaCard = new JPanel();
IndianaCard.add(pos[23]);
JPanel IndianaHouse = new JPanel();
IndianaHouse.setLayout(new GridLayout(1, 5));
IndianaHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
IndianaHouses[count] = new JButton();
IndianaHouses[count].setPreferredSize(new Dimension(11, 13));
IndianaHouse.add(IndianaHouses[count]);
}
JPanel IndianaPos = new JPanel();
IndianaPos.setLayout(new GridLayout(1, 2));
IndianaPos.add(posButtonsRed[23]);
IndianaPos.add(posButtonsBlue[23]);
// Illinois
JPanel IllinoisCard = new JPanel();
IllinoisCard.add(pos[24]);
JPanel IllinoisHouse = new JPanel();
IllinoisHouse.setLayout(new GridLayout(1, 5));
IllinoisHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
IllinoisHouses[count] = new JButton();
IllinoisHouses[count].setPreferredSize(new Dimension(11, 13));
IllinoisHouse.add(IllinoisHouses[count]);
}
JPanel IllinoisPos = new JPanel();
IllinoisPos.setLayout(new GridLayout(1, 2));
IllinoisPos.add(posButtonsRed[24]);
IllinoisPos.add(posButtonsBlue[24]);
// B&O Railroad
JPanel B_0RRCard = new JPanel();
B_0RRCard.add(pos[25]);
JPanel B_0RRPos = new JPanel();
B_0RRPos.setLayout(new GridLayout(1, 2));
B_0RRPos.add(posButtonsRed[25]);
B_0RRPos.add(posButtonsBlue[25]);
// Atlantic
JPanel AtlanticCard = new JPanel();
AtlanticCard.add(pos[26]);
JPanel AtlanticHouse = new JPanel();
AtlanticHouse.setLayout(new GridLayout(1, 5));
AtlanticHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
AtlanticHouses[count] = new JButton();
AtlanticHouses[count].setPreferredSize(new Dimension(11, 13));
AtlanticHouse.add(AtlanticHouses[count]);
}
JPanel AtlanticPos = new JPanel();
AtlanticPos.setLayout(new GridLayout(1, 2));
AtlanticPos.add(posButtonsRed[26]);
AtlanticPos.add(posButtonsBlue[26]);
// Ventnor
JPanel VentnorCard = new JPanel();
VentnorCard.add(pos[27]);
JPanel VentnorHouse = new JPanel();
VentnorHouse.setLayout(new GridLayout(1, 5));
VentnorHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
VentnorHouses[count] = new JButton();
VentnorHouses[count].setPreferredSize(new Dimension(11, 13));
VentnorHouse.add(VentnorHouses[count]);
}
JPanel VentnorPos = new JPanel();
VentnorPos.setLayout(new GridLayout(1, 2));
VentnorPos.add(posButtonsRed[27]);
VentnorPos.add(posButtonsBlue[27]);
// Water Works
JPanel WaterWorkCard = new JPanel();
WaterWorkCard.add(pos[28]);
JPanel WaterWorkPos = new JPanel();
WaterWorkPos.setLayout(new GridLayout(1, 2));
WaterWorkPos.add(posButtonsRed[28]);
WaterWorkPos.add(posButtonsBlue[28]);
// Marvin Gardens
JPanel MarvinCard = new JPanel();
MarvinCard.add(pos[29]);
JPanel MarvinHouse = new JPanel();
MarvinHouse.setLayout(new GridLayout(1, 5));
MarvinHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
MarvinHouses[count] = new JButton();
MarvinHouses[count].setPreferredSize(new Dimension(11, 13));
MarvinHouse.add(MarvinHouses[count]);
}
JPanel MarvinPos = new JPanel();
MarvinPos.setLayout(new GridLayout(1, 2));
MarvinPos.add(posButtonsRed[29]);
MarvinPos.add(posButtonsBlue[29]);
// Go to Jail
JPanel GotoJailCard = new JPanel();
GotoJailCard.add(pos[30]);
JPanel GotoJailCardPos = new JPanel();
GotoJailCardPos.setLayout(new GridLayout(2, 1));
posButtonsRed[30].setPreferredSize(new Dimension(14, 40));
posButtonsBlue[30].setPreferredSize(new Dimension(14, 40));
GotoJailCardPos.add(posButtonsRed[30]);
GotoJailCardPos.add(posButtonsBlue[30]);
// Pacific Avenue
JPanel PacificAvenueCard = new JPanel();
PacificAvenueCard.add(pos[31]);
JPanel PacificAvenueHouse = new JPanel();
PacificAvenueHouse.setLayout(new GridLayout(5, 1));
PacificAvenueHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
PacificAvenueHouses[count] = new JButton();
PacificAvenueHouses[count].setPreferredSize(new Dimension(13, 11));
PacificAvenueHouse.add(PacificAvenueHouses[count]);
}
JPanel PacificAvenuepos = new JPanel();
PacificAvenuepos.setLayout(new GridLayout(2, 1));
PacificAvenuepos.add(posButtonsRed[31]);
PacificAvenuepos.add(posButtonsBlue[31]);
// North Carolina
JPanel NorthCarolinaCard = new JPanel();
NorthCarolinaCard.add(pos[32]);
JPanel NorthCarolinaHouse = new JPanel();
NorthCarolinaHouse.setLayout(new GridLayout(5, 1));
NorthCarolinaHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
NorthCarolinaHouses[count] = new JButton();
NorthCarolinaHouses[count].setPreferredSize(new Dimension(13, 11));
NorthCarolinaHouse.add(NorthCarolinaHouses[count]);
}
JPanel NorthCarolinapos = new JPanel();
NorthCarolinapos.setLayout(new GridLayout(2, 1));
NorthCarolinapos.add(posButtonsRed[32]);
NorthCarolinapos.add(posButtonsBlue[32]);
// Community Chest
JPanel CCCard3 = new JPanel();
CCCard3.add(pos[33]);
JPanel CCCard3pos = new JPanel();
CCCard3pos.setLayout(new GridLayout(2, 1));
CCCard3pos.add(posButtonsRed[33]);
CCCard3pos.add(posButtonsBlue[33]);
// Pennsylvania pos = 34
JPanel PennsylvaniaAveCard = new JPanel();
PennsylvaniaAveCard.add(pos[34]);
JPanel PennsylvaniaAveHouse = new JPanel();
PennsylvaniaAveHouse.setLayout(new GridLayout(5, 1));
PennsylvaniaAveHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
PennsylvaniaAveHouses[count] = new JButton();
PennsylvaniaAveHouses[count].setPreferredSize(new Dimension(13, 11));
PennsylvaniaAveHouse.add(PennsylvaniaAveHouses[count]);
}
JPanel PennsylvaniaAvepos = new JPanel();
PennsylvaniaAvepos.setLayout(new GridLayout(2, 1));
PennsylvaniaAvepos.add(posButtonsRed[34]);
PennsylvaniaAvepos.add(posButtonsBlue[34]);
// Short Line pos = 35
JPanel shortlineRR = new JPanel();
shortlineRR.add(pos[35]);
// Short Line pos = 35
JPanel shortlineRRPos = new JPanel();
shortlineRRPos.setLayout(new GridLayout(2, 1));
shortlineRRPos.add(posButtonsRed[35]);
shortlineRRPos.add(posButtonsBlue[35]);
// Chance- Pos = 36
JPanel ChanceCard3 = new JPanel();
ChanceCard3.add(pos[36]);
JPanel ChanceCard3Pos = new JPanel();
ChanceCard3Pos.setLayout(new GridLayout(2, 1));
ChanceCard3Pos.add(posButtonsRed[36]);
ChanceCard3Pos.add(posButtonsBlue[36]);
// Park Place Card
JPanel parkPlaceCard = new JPanel();
parkPlaceCard.add(pos[37]);
JPanel parkPlaceHouse = new JPanel();
parkPlaceHouse.setLayout(new GridLayout(5, 1));
JButton parkPlaceHouses[] = new JButton[5];
for (int count = 0; count < 5; count++) {
parkPlaceHouses[count] = new JButton();
parkPlaceHouses[count].setPreferredSize(new Dimension(13, 11));
parkPlaceHouse.add(parkPlaceHouses[count]);
}
JPanel parkPlacepos = new JPanel();
parkPlacepos.setLayout(new GridLayout(2, 1));
parkPlacepos.add(posButtonsRed[37]);
parkPlacepos.add(posButtonsBlue[37]);
// luxury tax
JPanel LuxuryTaxCard = new JPanel();
LuxuryTaxCard.add(pos[38]);
// Luxury Tax pos = 38
JPanel LuxuryTaxPos = new JPanel();
LuxuryTaxPos.setLayout(new GridLayout(2, 1));
LuxuryTaxPos.add(posButtonsRed[38]);
LuxuryTaxPos.add(posButtonsBlue[38]);
// boardwalk card
JPanel boardwalkCard = new JPanel();
boardwalkCard.add(pos[39]);
JPanel boardwalkHouse = new JPanel();
boardwalkHouse.setLayout(new GridLayout(5, 1));
boardwalkHouses = new JButton[5];
for (int count = 0; count < 5; count++) {
boardwalkHouses[count] = new JButton();
boardwalkHouses[count].setPreferredSize(new Dimension(13, 11));
boardwalkHouse.add(boardwalkHouses[count]);
}
JPanel boardwalkPos = new JPanel();
boardwalkPos.setLayout(new GridLayout(2, 1));
boardwalkPos.add(posButtonsRed[39]);
boardwalkPos.add(posButtonsBlue[39]);
// Text Areas and Button Panels
JPanel textArea = new JPanel();
// text area panel for ingame commentary
// text area
commentary = new JTextArea(
"Welcome to Monopoly, this is where the in-game commentary will happen\nAny action you perform (Rolling, Upgrading or Buying) must follow with an End Turn.\nThe game has no color sets, as this is the express version.\nNo other actions before rolling on your turn.\nThe orange buttons are for Jail.\nLet the games begin!",
30, 30);
JScrollPane scrollPane = new JScrollPane(commentary); // adding a scroll pane
commentary.setLineWrap(true); // causes the lines to wrap around; word may be split
commentary.setWrapStyleWord(true); //
textArea.add(scrollPane);
commentary.setEditable(false); // making it uneditable
JPanel buttonPanel = new JPanel(); // adding the button panel
buttonPanel.setLayout(new GridLayout(2, 2)); // setting the layout
JButton rollButton = new JButton("ROLL");
JButton upgButton = new JButton("UPGRADE");
JButton buyButton = new JButton("BUY");
JButton EndTurnButton = new JButton("END TURN");
buttonPanel.add(rollButton); // adding buttons to panel
buttonPanel.add(upgButton);
buttonPanel.add(buyButton);
buttonPanel.add(EndTurnButton);
JPanel moneyPanel = new JPanel(); // adding a panel to show P1 and P2 money
moneyPanel.setLayout(new GridLayout(1, 2));
JButton moneyButton = new JButton(p1Money + "");
moneyButton.setBackground(Color.red); // changing coulour to show p1 money and p2 money
JButton money2Button = new JButton(p2Money + "");
money2Button.setBackground(Color.blue);
JPanel p1Props = new JPanel(); // adding text areas for p1 and p2 propeties they buy
p1List = new JTextArea("Properties List For: " + p1Name, 3, 15);
JScrollPane scrollList1 = new JScrollPane(p1List);
p1List.setLineWrap(true); // causes the lines to wrap around; word may be split
p1List.setWrapStyleWord(true);
p1Props.add(scrollList1);
p1List.setEditable(false);
JPanel p2Props = new JPanel();
p2List = new JTextArea("Properties List For: " + p2Name, 3, 15);
JScrollPane scrollList2 = new JScrollPane(p2List);
p2List.setLineWrap(true); // causes the lines to wrap around; word may be split
p2List.setWrapStyleWord(true);
p2Props.add(scrollList2);
p2List.setEditable(false);
JPanel jailButtons = new JPanel(); // special buttons for when either player goes to jail
jailButtons.setLayout(new GridLayout(1, 3));
JButton jRoll = new JButton("JAIL-ROLL");
jRoll.setBackground(Color.orange);
JButton jPay = new JButton("PAY-$50");
jPay.setBackground(Color.orange);
JButton jEndTurn = new JButton("Wait Turn");
jEndTurn.setBackground(Color.orange);
jailButtons.add(jRoll); // adding those buttons to panel
jailButtons.add(jPay);
jailButtons.add(jEndTurn);
moneyPanel.add(moneyButton);
moneyPanel.add(money2Button);
// GO panel, pos = 0
constraints.gridx = 12; // constraints allows us to place certain components in certin spots
constraints.gridy = 20; // started with the pos (12,20), at GO and as we worked inwards changed the x or
// y depending on the space
panel.add(GoPanel, constraints); // adding the GO card to the panel with the gridBag layout
constraints.gridx = 12;
constraints.gridy = 21; // adding the position marker one unit below the GO panel
panel.add(GOPos, constraints); // adding it to the main gridbag panel
// mediterranean player pos = 1
constraints.gridx = 11; // same logic as GO Panel
constraints.gridy = 20;
panel.add(mediterraneanCard, constraints);
constraints.gridx = 11;
constraints.gridy = 21;
panel.add(mediterraneanPos, constraints);
constraints.gridx = 11; // but houses are 2 units underneath the card panel
constraints.gridy = 22;
panel.add(mediterraneanHouse, constraints);
// REPEATED process for all the spaces, if they have no houses, the third
// section is not included
// community chest pos = 2
constraints.gridx = 10;
constraints.gridy = 20;
panel.add(CCCard, constraints);
constraints.gridx = 10;
constraints.gridy = 21;
panel.add(CCPos, constraints);
// baltic card - pos = 3
constraints.gridx = 9;
constraints.gridy = 20;
panel.add(balticCard, constraints);
constraints.gridx = 9;
constraints.gridy = 21;
panel.add(balticPos, constraints);
constraints.gridx = 9;
constraints.gridy = 22;
panel.add(balticHouse, constraints);
// //income tax - pos = 4
constraints.gridx = 8;
constraints.gridy = 20;
panel.add(IncomeTax, constraints);
constraints.gridx = 8;
constraints.gridy = 21;
panel.add(ITPos, constraints);
// reading railroad - pos = 5
constraints.gridx = 7;
constraints.gridy = 20;
panel.add(ReadingRR, constraints);