-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiceBet.java
More file actions
274 lines (192 loc) · 6.61 KB
/
Copy pathDiceBet.java
File metadata and controls
274 lines (192 loc) · 6.61 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
/**
* Dice Betting
*
* @author Jacob Schnettler
* @period 2
* @date 10/20/2022
*/
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import java.util.Random;
public class DiceBet extends Applet implements ActionListener {
Boolean gameStarted = false;
Boolean increasingBet = true;
Button startGameBTN = new Button();
Button oddBetToggleBTN = new Button();
Button evenBetToggleBTN = new Button();
Button toggleBetTypeBTN = new Button();
Button confirmBetBTN = new Button("Confirm Bet");
Button betButton1 = new Button();
Button betButton5 = new Button();
Button betButton25 = new Button();
Button allInBet = new Button();
Random rand = new Random();
Font title = new Font("Ariel", 1, 25);
Font sub = new Font("Ariel", 1, 20);
int balance = 1000;
int currentBet = 0;
int firstDye;
int secondDye;
int diceTotal;
Boolean betPlaced = false;
Boolean betWon = false;
Boolean cashoutShown = false;
public void toggleDisplay(Boolean bool)
{
gameStarted = bool;
betButton1.setVisible(bool);
betButton5.setVisible(bool);
betButton25.setVisible(bool);
allInBet.setVisible(bool);
confirmBetBTN.setVisible(bool);
toggleBetTypeBTN.setVisible(bool);
}
public void setBTNLabel(Button btn, int amount, boolean allIn)
{
if (allIn) {
if (increasingBet) {
btn.setLabel("All In");
} else {
btn.setLabel("Reset Bet");
}
} else {
if (increasingBet) {
btn.setLabel("Increase Bet By " + amount + " Chips");
} else {
btn.setLabel("Decrease Bet By " + amount + " Chips");
}
}
}
public void rollDice()
{
if (currentBet != 0 && currentBet <= balance)
{
betPlaced = true;
firstDye = rand.nextInt(6) + 1;
secondDye = rand.nextInt(6) + 1;
diceTotal = firstDye + secondDye;
if (diceTotal % 2 == 1) {
// 1.5x bet
balance = balance + (currentBet * 3/2);
betWon = true;
} else {
balance = balance - currentBet;
betWon = false;
}
}
}
public void mapButton(Button btn, int position, int amount)
{
btn.addActionListener(this);
btn.setBounds(950, 100 + (50 * position), 250, 40);
this.add(btn);
setBTNLabel(btn, amount, position == 4 || false);
}
public void init()
{
this.setLayout(null);
startGameBTN.addActionListener(this);
startGameBTN.setBounds(100, 150, 150, 40);
this.add(startGameBTN);
toggleBetTypeBTN.addActionListener(this);
toggleBetTypeBTN.setBounds(100, 200, 150, 40);
this.add(toggleBetTypeBTN);
confirmBetBTN.addActionListener(this);
confirmBetBTN.setBounds(100, 250, 150, 40);
this.add(confirmBetBTN);
mapButton(betButton1, 1, 1);
mapButton(betButton5, 2, 5);
mapButton(betButton25, 3, 25);
mapButton(allInBet, 4, balance);
toggleDisplay(false);
}
public void manageBet(int amount, boolean allIn)
{
if (increasingBet) {
if (allIn)
currentBet = amount;
else if (balance >= currentBet + amount)
currentBet = currentBet + amount;
} else {
if (allIn)
currentBet = 0;
else if (0 <= currentBet - amount)
currentBet = currentBet - amount;
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == confirmBetBTN)
rollDice();
if (e.getSource() == startGameBTN)
{
if (cashoutShown) {
gameStarted = true;
increasingBet = true;
balance = 1000;
currentBet = 0;
betPlaced = false;
betWon = false;
cashoutShown = false;
toggleDisplay(true);
} else if (betPlaced) {
cashoutShown = true;
toggleDisplay(false);
} else
toggleDisplay(!gameStarted);
}
if (e.getSource() == toggleBetTypeBTN)
increasingBet = !increasingBet;
if (e.getSource() == betButton1)
manageBet(1, false);
if (e.getSource() == betButton5)
manageBet(5, false);
if (e.getSource() == betButton25)
manageBet(25, false);
if (e.getSource() == allInBet)
manageBet(balance, true);
if (balance == 0)
{
toggleDisplay(false);
cashoutShown = true;
}
repaint();
}
public void paint(Graphics g)
{
g.setFont(title);
if (cashoutShown) {
startGameBTN.setLabel("Enter the gambling pit");
if (balance != 0)
g.drawString("Cashing out " + balance + " Chips", 100, 100);
else
g.drawString("You lost all your money!", 100, 100);
} else if (!gameStarted) {
startGameBTN.setLabel("Enter the gambling pit");
g.drawString("Are you ready for Casino Royale?", 100, 100);
g.drawString("Rules", 100, 400);
g.drawString("You begin with 1000 chips, you select your bet a dice gets rolled. ", 100, 450);
g.drawString("If the dice total is odd, one and a half of the bet is paid. if the dice total is even, the bet is lost.", 100, 500);
g.setFont(sub);
} else {
g.drawString("Balance: " + balance + " Chips", 100, 100);
if (betPlaced)
if (betWon)
g.drawString("Bet Won! You won " + currentBet + " Chips", 300, 250);
else
g.drawString("Bet Lost! You lost " + currentBet + " Chips", 300, 250);
startGameBTN.setLabel("Cashout from Casino");
setBTNLabel(betButton1, 1, false);
setBTNLabel(betButton5, 5, false);
setBTNLabel(betButton25, 25, false);
setBTNLabel(allInBet, balance, true);
if (increasingBet)
toggleBetTypeBTN.setLabel("Decrease Bet");
else
toggleBetTypeBTN.setLabel("Increase Bet");
g.setFont(sub);
g.drawString("Current Bet: " + currentBet + " Chips", 300, 200);
}
}
}