-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFreeplayGUI.java
More file actions
190 lines (163 loc) · 4.4 KB
/
FreeplayGUI.java
File metadata and controls
190 lines (163 loc) · 4.4 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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
public class FreeplayGUI extends JPanel implements MouseListener {
public BufferedImage backgroundImage;
public BufferedImage chipImage;
Player playerHand;
Player dealerHand;
public static int bet;
public boolean faceDown = true;
public static boolean betMade = false;
private int bal;
public static int cBet;
/**
* constructor to load the GUI for freeplay
* @param dealer of the game
* @param player of the game
*/
public FreeplayGUI(Player dealer, Player player) {
dealerHand = dealer;
playerHand = player;
bal = 1000;
addMouseListener(this);
}
/**
* adds winLose to bal
* @param winLose to be added to bal
*/
public void setBal(int winLose){
bal += winLose;
}
/**
* gets the balance
* @return balance
*/
public int getBal(){
return bal;
}
/**
* gets current bet
* @return current bet
*/
public int getBet(){
return bet;
}
/**
* paint the freeplay menu
* @param g graphics object
*/
public void paintComponent(Graphics g) {
Graphics2D g1d = (Graphics2D) g;
try {
backgroundImage = ImageIO.read(new File("images/casinoBackground.png"));
chipImage = ImageIO.read(new File("images/chip.png"));
} catch (IOException e) {
}
g1d.drawImage(backgroundImage, 0, 0, null);
g1d.drawImage(chipImage, 45, 475, null);
g1d.setColor(Color.WHITE);
g1d.setFont(new Font("Tahoma", Font.BOLD, 20));
g1d.drawString("Balance: " + playerHand.getChips(), 55, 650);
try {
int counter1 = 0;
for (Card card : dealerHand.hand()) {
System.out.println("yay:" + counter1 + " " + faceDown);
if (counter1 == 0) {
System.out.println("after if");
if (faceDown) {
System.out.println("WOW1");
card.cardPrinter(g1d, true, true, counter1, card);
} else {
System.out.println("WOW2");
card.cardPrinter(g1d, true, false, counter1, card);
}
} else {
card.cardPrinter(g1d, true, false, counter1, card);
System.out.println("WOW3");
}
counter1++;
}
} catch (IOException e) {
}
try {
int counter2 = 0;
for (Card card : playerHand.hand()) {
System.out.println("uwu:" + counter2);
System.out.println(playerHand.hand());
card.cardPrinter(g1d, false, false, counter2, card);
System.out.println("WOW4");
counter2++;
}
} catch (IOException e) {
}
}
/**
* refreshes the GUI
* @param bal of the game
* @param faceDown whether or not card is face up or face down
*/
public void refresher(int bal, boolean faceDown) {
this.bal = bal;
this.faceDown = faceDown;
this.repaint();
}
/**
* repaint cards
*/
public void repainter(){
this.repaint();
}
/**
* detects a mouse press, and checks if it falls into the region of the chip to place bet
* @param e mouse click event
*/
public void mousePressed(MouseEvent e) {
int mouseX = e.getX();
int mouseY = e.getY();
if (mouseX >= 45 && mouseX <= 195 && mouseY >= 475 && mouseY <= 625) {
betMade = true;
String[] options = new String[] { "200", "150", "100", "50", "20" };
int response = JOptionPane.showOptionDialog(null, "Please select your betting amount", "Bets",
JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
if (response == 0) {
bet = 200;
bal -= 200;
playerHand.placeBet(200);
} else if (response == 1) {
bet = 150;
bal -= 150;
playerHand.placeBet(150);
} else if (response == 2) {
bet = 100;
bal -= 100;
playerHand.placeBet(100);
} else if (response == 3) {
bet = 50;
bal -= 50;
playerHand.placeBet(50);
} else if (response == 4) {
bet = 20;
bal -= 20;
playerHand.placeBet(20);
}
// else {
// bet = 20;
// balance -= 20;
// }
Main.newGame.startGame();
}
}
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
}