-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChanceCard.java
More file actions
145 lines (140 loc) · 6.42 KB
/
ChanceCard.java
File metadata and controls
145 lines (140 loc) · 6.42 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
import java.awt.*;
import java.util.ArrayList;
import javax.swing.*;
public class ChanceCard {
//St. Charles Place movement card does not allow for buy action (also potentially other movement cards don't function correctly)
int index;
Player player;
String message;
ArrayList<Player> otherPlayers;
MonopolyBoard ref;
public ChanceCard(String message, int index, Player player, ArrayList<Player> otherPlayers, MonopolyBoard ref){
this.ref=ref;
this.index=index;
this.player=player;
this.otherPlayers=otherPlayers;
new UIManager().put("OptionPane.background", Color.ORANGE);
new UIManager().put("Panel.background", Color.ORANGE);
}
public boolean generateChanceCard(String messageInput){
if(index==0){
//Advance to Go
player.setPositionIndex(0);
player.setTotalMoney(player.getTotalMoney()+200);
}
else if(index==1){
//Advance to Illinois Avenue
player.setPositionIndex(24);
player.setTotalMoney((player.getPositionIndex()>24)?player.getTotalMoney()+200:player.getTotalMoney());
SpecialOptionPane sop = new SpecialOptionPane(ref.banner, messageInput,"Chance",Color.ORANGE,1);
return true;
}
else if(index==2){
//Advance to St. Charles Place Avenue
player.setPositionIndex(11);
player.setTotalMoney((player.getPositionIndex()>11)?player.getTotalMoney()+200:player.getTotalMoney());
SpecialOptionPane sop = new SpecialOptionPane(ref.banner, messageInput,"Chance",Color.ORANGE,1);
return true;
}
else if(index==3){
//Advance to Nearest Utility
player.setPositionIndex((player.getPositionIndex()>12 && player.getPositionIndex()<28)?28:12);
player.setTotalMoney((player.getPositionIndex()>12 && player.getPositionIndex()<28)?player.getTotalMoney():(player.getPositionIndex()<=39 && player.getPositionIndex()>28)?player.getTotalMoney()+200:player.getTotalMoney());
SpecialOptionPane sop = new SpecialOptionPane(ref.banner, messageInput,"Chance",Color.ORANGE,1);
return true;
}
else if(index==4 || index==5){
//Advance to the Nearest Railroad
String addedMessage = "";
if(player.getPositionIndex() >35 && player.getPositionIndex() < 5){
addedMessage = "The Reading Railroad";
player.setPositionIndex(5);
player.setTotalMoney(player.getTotalMoney()+200);
}
else if(player.getPositionIndex()>5 && player.getPositionIndex()<15){
addedMessage = "Pennsylvania Railroad";
player.setPositionIndex(15);
}
else if(player.getPositionIndex()>15 && player.getPositionIndex()<25){
addedMessage = "B & O Railroad";
player.setPositionIndex(25);
}
else if(player.getPositionIndex()>25 && player.getPositionIndex()<35){
addedMessage = "The Short Line Railroad";
player.setPositionIndex(35);
}
SpecialOptionPane sop = new SpecialOptionPane(ref.banner,"Advance to the nearest railroad, "+addedMessage,"Chance",Color.ORANGE,1);
return true;
}
else if(index==6){
//Bank pays you dividend of $50
player.addMoney(50);
}
else if(index==7){
//Get Out of Jail Free Card
player.hasGetOutOfJailFreeCard=true;
}
else if(index==8){
//Move back 3 spaces
player.setPositionIndex(player.getPositionIndex()-3);
SpecialOptionPane sop = new SpecialOptionPane(ref.banner, messageInput,"Chance",Color.ORANGE,1);
return true;
}
else if(index==9){
//Go to jail
player.setPositionIndex(10);
player.setInJail(true);
player.setDoublesCount(0);
player.setCurrentRollDoubles(false);
}
else if(index==10){
//You are assessed general repairs; pay $25 per house you own, plus an additional $100 for each hotel
ArrayList<Property> playerProperties = new ArrayList<Property>();
int subtractedValue = 0;
playerProperties= player.getProperties();
for(int x=0; x<playerProperties.size(); x++)
subtractedValue+=(playerProperties.get(x).numHouses==4 && playerProperties.get(x).numHotels==1)? 100:25*playerProperties.get(x).numHouses;
player.subtractMoney(subtractedValue);
if(ref.playingWithFreeParking)
ref.freeParking+=subtractedValue;
}
else if(index==11){
//You pay a poor tax; pay $50
player.subtractMoney(50);
if(ref.playingWithFreeParking)
ref.freeParking+=50;
}
else if(index==12){
//Advance to Reading Railroad
player.setPositionIndex(5);
player.setTotalMoney((player.getPositionIndex()>5)?player.getTotalMoney()+200:player.getTotalMoney());
SpecialOptionPane sop = new SpecialOptionPane(ref.banner, messageInput,"Chance",Color.ORANGE,1);
return true;
}
else if(index==13){
//Go to Boardwalk
player.setPositionIndex(39);
SpecialOptionPane sop = new SpecialOptionPane(ref.banner, messageInput,"Chance",Color.ORANGE,1);
return true;
}
else if(index==14){
//You are a chairman of the board; pay each other player $50
for(int x=0; x<otherPlayers.size(); x++){
player.subtractMoney(50);
otherPlayers.get(x).addMoney(50);
}
}
else if(index==15){
//Your building and loan matures. Collect $150
player.addMoney(150);
}
else if(index==16){
//You won a crossword competition. As a true cruciverbalist, you are awarded $100 lol
player.addMoney(100);
}
else
JOptionPane.showMessageDialog(ref.banner, "There are no chance cards left.","No Chance",3);
SpecialOptionPane sop = new SpecialOptionPane(ref.banner,messageInput,"Chance",Color.ORANGE,1);
return false;
}
}