-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardCountingSimulatorGame.java
More file actions
153 lines (112 loc) · 3.68 KB
/
CardCountingSimulatorGame.java
File metadata and controls
153 lines (112 loc) · 3.68 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
import javax.swing.*;
import java.util.*;
import java.awt.Font;
import java.awt.event.*;
import java.io.FileInputStream;
import java.io.*;
public class CardCountingSimulatorGame {
public boolean faceDown;
private static Deck deck;
private static int pool;
private static Player dealer;
private static Player user;
public boolean over;
JFrame mainFrame;
private static int balance1 = 1000;
CardCountingSimulatorGUI creatorComp;
CardCountingSimulatorGUI cardComp;
JButton btnHit;
JButton btnStand;
JButton btnExit;
/**
* loads freeplay game
* @param frame1 jframe
*/
public CardCountingSimulatorGame(JFrame frame1) {
mainFrame = frame1;
deck = new Deck();
deck.shuffle(); //we randomize the deck.
user = new Player("player1");
dealer = new Player("dealer1");
faceDown = true;
over = false;
}
/**
* find the balance
* @return balance
*/
public int getBal1(){
return creatorComp.getBal();
}
/**
* forms the game
*/
public void formGame() {
mainFrame.setTitle("Deckster - Card Counting Simulator");
mainFrame.setSize(1280, 720);
mainFrame.setLocationRelativeTo(null);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setResizable(false);
btnHit = new JButton("Hit");
btnHit.setBounds(1000, 540, 150, 50);
btnHit.setFont(new Font("Tahoma", Font.BOLD, 16));
btnStand = new JButton("Stand");
btnStand.setBounds(1000, 620, 150, 50);
btnStand.setFont(new Font("Tahoma", Font.BOLD, 16));
btnExit = new JButton("Exit");
btnExit.setBounds(75, 5, 100, 50);
btnExit.setFont(new Font("Tahoma", Font.BOLD, 16));
mainFrame.add(btnHit);
mainFrame.add(btnStand);
mainFrame.add(btnExit);
btnExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
);
creatorComp = new CardCountingSimulatorGUI(dealer, user);
creatorComp.setBounds(0, 0, 1280, 720);
mainFrame.add(creatorComp);
mainFrame.setVisible(true);
}
/**
* starts the game
*/
public void startGame() {
CardCountingSimulator loader = new CardCountingSimulator(dealer, user, pool, deck);
cardComp = new CardCountingSimulatorGUI(loader.getDealer(), loader.getPlayer());
loader.setPool(cardComp.getBet());
cardComp.setBounds(0, 0, 1280, 720);
mainFrame.add(cardComp);
mainFrame.setVisible(true);
btnHit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cardComp.repaint();
faceDown = true;
int returner = loader.hit();
if (returner == -1){
cardComp.repaint();
JOptionPane.showMessageDialog(mainFrame, "You have busted. Dealer Wins.");
}
}
});
btnStand.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cardComp.repaint();
creatorComp.faceDown = false;
cardComp.faceDown = false;
cardComp.repaint();
int returner = loader.stand();
if (returner == -1){
cardComp.repaint();
JOptionPane.showMessageDialog(mainFrame, "Dealer has higher card value. Dealer Wins.");
}
else if (returner ==1){
cardComp.repaint();
JOptionPane.showMessageDialog(mainFrame, "Dealer has lower card value or has busted. Player Wins.");
}
}
});
}
}