|
@@ -3,53 +3,62 @@ package io.zipcoder.casino.CardGame.BlackJack;
|
3
|
3
|
import io.zipcoder.casino.CardGame.Card;
|
4
|
4
|
import io.zipcoder.casino.CardGame.CardGame;
|
5
|
5
|
import io.zipcoder.casino.CardGame.Deck;
|
|
6
|
+import io.zipcoder.casino.CardGame.Face;
|
6
|
7
|
import io.zipcoder.casino.Interfaces.Gamble;
|
7
|
8
|
import io.zipcoder.casino.Player;
|
8
|
9
|
|
9
|
10
|
import java.util.ArrayList;
|
|
11
|
+import java.util.Scanner;
|
10
|
12
|
|
11
|
13
|
public class BlackJack extends CardGame implements Gamble {
|
12
|
14
|
|
13
|
|
- private ArrayList<BlackJackPlayer> blackJackPlayers;
|
14
|
|
- private int minBet;
|
15
|
|
- private ArrayList<Card> wastepile;
|
16
|
|
- private ArrayList<Card> dealerHand;
|
17
|
|
- private Deck deck;
|
18
|
|
- private boolean justDealt;
|
19
|
|
- private int numOfTurns;
|
|
15
|
+ private ArrayList<BlackJackPlayer> blackJackPlayers = new ArrayList<>();
|
|
16
|
+ private final int minBet = 50;
|
|
17
|
+ private ArrayList<Card> wastepile = new ArrayList<>();
|
|
18
|
+ private Deck deck = new Deck();
|
|
19
|
+ private boolean justDealt = false;
|
|
20
|
+ private int numOfTurns = 0;
|
|
21
|
+ private BlackJackPlayer dealer = new BlackJackPlayer(new Dealer());
|
|
22
|
+
|
20
|
23
|
|
21
|
24
|
public BlackJack(Player player) {
|
22
|
25
|
BlackJackPlayer blackJackPlayer = new BlackJackPlayer(player);
|
23
|
|
- this.blackJackPlayers = new ArrayList<BlackJackPlayer>();
|
|
26
|
+ blackJackPlayers.add(dealer);
|
24
|
27
|
this.blackJackPlayers.add(blackJackPlayer);
|
25
|
|
- this.minBet = 100;
|
26
|
|
- this.wastepile = new ArrayList<Card>();
|
27
|
|
- this.dealerHand = new ArrayList<Card>();
|
28
|
|
- this.deck = new Deck();
|
29
|
|
- this.justDealt = false;
|
30
|
|
- this.numOfTurns = 0;
|
31
|
28
|
}
|
32
|
29
|
|
33
|
|
-// public BlackJack(){
|
34
|
|
-// this.blackJackPlayers = new ArrayList<BlackJackPlayer>();
|
35
|
|
-// }
|
|
30
|
+ public void hit(BlackJackPlayer player) {
|
|
31
|
+ setJustDealt(false);
|
|
32
|
+ Card card = deck.draw();
|
|
33
|
+ player.addToHand(card);
|
36
|
34
|
|
37
|
|
-// public BlackJack(Player player) {
|
38
|
|
-// BlackJackPlayer blackJackPlayer = new BlackJackPlayer(player);
|
39
|
|
-// this.blackJackPlayers.add(blackJackPlayer);
|
|
35
|
+ if (countPlayerHand(player).get(0) > 21 || (countPlayerHand(player).size() == 2 && countPlayerHand(player).get(1) > 21)) {
|
|
36
|
+ System.out.println("Your Current Hand: \n" + formatHand(player.getPlayerHand()) + "\nHand Value: " + formatHandValue(countPlayerHand(player)) + "\nToo high, you lose!");
|
|
37
|
+ } else {
|
|
38
|
+ System.out.println("Your Current Hand: \n" + formatHand(player.getPlayerHand()) + "\nHand Value: " + formatHandValue(countPlayerHand(player)));
|
|
39
|
+ }
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+// public void flip() {
|
|
43
|
+// // shoulder technically be card.setCovered(false); or something like that
|
|
44
|
+// boolean covered = false;
|
40
|
45
|
// }
|
41
|
46
|
|
42
|
|
- // basically draw
|
43
|
|
- public Card hit() {
|
44
|
|
- return null;
|
45
|
|
- }
|
|
47
|
+ public void split(BlackJackPlayer player) {
|
46
|
48
|
|
47
|
|
- public void flip() {
|
48
|
|
- // shoulder technically be card.setCovered(false); or something like that
|
49
|
|
- boolean covered = false;
|
50
|
|
- }
|
|
49
|
+ System.out.println(player.getPlayerHand() + "\n");
|
|
50
|
+
|
|
51
|
+ Card movingCard = player.getPlayerHand().get(1);
|
|
52
|
+
|
|
53
|
+ if (justDealt && player.getPlayerHand().get(0).getFace() == player.getPlayerHand().get(1).getFace()) {
|
|
54
|
+ ArrayList<Card> newHand = player.createNewHand();
|
|
55
|
+ newHand.add(movingCard);
|
|
56
|
+ player.getPlayerHand().remove(movingCard);
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ System.out.println(player.getPlayerHand() + " " + player.getSecondHand());
|
|
60
|
+ setJustDealt(false);
|
51
|
61
|
|
52
|
|
- public void split() {
|
53
|
62
|
// must be the same card value
|
54
|
63
|
}
|
55
|
64
|
|
|
@@ -57,6 +66,8 @@ public class BlackJack extends CardGame implements Gamble {
|
57
|
66
|
if (getJustDealt() == true) {
|
58
|
67
|
blackJackPlayer.addToBetPot(blackJackPlayer.getInitialBet());
|
59
|
68
|
}
|
|
69
|
+
|
|
70
|
+ setJustDealt(false);
|
60
|
71
|
// must be right after deal, and you can only get one more card
|
61
|
72
|
}
|
62
|
73
|
|
|
@@ -65,30 +76,73 @@ public class BlackJack extends CardGame implements Gamble {
|
65
|
76
|
// (end turn?) what does "take a turn" actually initiate
|
66
|
77
|
}
|
67
|
78
|
|
68
|
|
- public int countHand(BlackJackPlayer blackJackPlayer) {
|
69
|
|
- int handSum = 0;
|
|
79
|
+ public int calculate_AceIsOne(BlackJackPlayer player) {
|
|
80
|
+ ArrayList<Card> playerHand = player.getPlayerHand();
|
|
81
|
+ int aceIsOne = 0;
|
|
82
|
+
|
|
83
|
+ for (int i = 0; i < player.getPlayerHand().size(); i++) {
|
|
84
|
+ if (playerHand.get(i).getFace() == Face.ACE) {
|
|
85
|
+ aceIsOne += playerHand.get(i).getFace().getPrimaryValue();
|
|
86
|
+ } else {
|
|
87
|
+ aceIsOne += playerHand.get(i).getFace().getSecondaryValue();
|
|
88
|
+ }
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ return aceIsOne;
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ public int calculate_Standard(BlackJackPlayer player) {
|
|
95
|
+ ArrayList<Card> playerHand = player.getPlayerHand();
|
|
96
|
+ int aceIsEleven = 0;
|
70
|
97
|
|
71
|
|
- for (int i = 0; i < blackJackPlayer.getPlayerHand().size(); i++) {
|
72
|
|
- handSum += (blackJackPlayer.getPlayerHand().get(i).getFace().getSecondaryValue());
|
|
98
|
+ for (int i = 0; i < player.getPlayerHand().size(); i++) {
|
|
99
|
+ aceIsEleven += playerHand.get(i).getFace().getSecondaryValue();
|
73
|
100
|
}
|
74
|
|
- return handSum;
|
|
101
|
+
|
|
102
|
+ return aceIsEleven;
|
75
|
103
|
}
|
76
|
104
|
|
77
|
|
- public void deal(BlackJackPlayer blackJackPlayer) {
|
78
|
|
- // BlackJackPlayer player1 = blackJackPlayers.get(playerIndex);
|
79
|
|
- blackJackPlayers.add(blackJackPlayer);
|
80
|
|
- // should we move this to start instead? we would also need to deal for each player if multiple
|
81
|
|
- Card playerCard1 = deck.draw();
|
82
|
|
- blackJackPlayer.addToHand(playerCard1);
|
|
105
|
+ public ArrayList<Integer> countPlayerHand(BlackJackPlayer player) {
|
|
106
|
+ ArrayList<Integer> handSum = new ArrayList<>();
|
|
107
|
+ Integer aceIsOne;
|
|
108
|
+ Integer aceIsEleven;
|
|
109
|
+ Integer noAce;
|
|
110
|
+
|
|
111
|
+ if (player.hasAce() && calculate_Standard(player) > 21) {
|
|
112
|
+ player.setHandValue(calculate_AceIsOne(player));
|
|
113
|
+ aceIsOne = player.getHandValue();
|
|
114
|
+ handSum.add(aceIsOne);
|
|
115
|
+
|
|
116
|
+ } else if (player.hasAce() && calculate_Standard(player) < 21) {
|
|
117
|
+ player.setHandValue(calculate_AceIsOne(player));
|
|
118
|
+ aceIsOne = player.getHandValue();
|
|
119
|
+ handSum.add(aceIsOne);
|
|
120
|
+
|
|
121
|
+ player.setHandValue(calculate_Standard(player));
|
|
122
|
+ aceIsEleven = player.getHandValue();
|
|
123
|
+ handSum.add(aceIsEleven);
|
|
124
|
+
|
|
125
|
+ } else {
|
|
126
|
+ player.setHandValue(calculate_Standard(player));
|
|
127
|
+ noAce = player.getHandValue();
|
|
128
|
+ handSum.add(noAce);
|
|
129
|
+ }
|
|
130
|
+
|
|
131
|
+ return handSum;
|
|
132
|
+ }
|
83
|
133
|
|
84
|
|
- Card dealerCard1 = deck.draw();
|
85
|
|
- dealerHand.add(dealerCard1);
|
|
134
|
+ public void deal() {
|
|
135
|
+ deck.shuffle();
|
86
|
136
|
|
87
|
|
- Card playerCard2 = deck.draw();
|
88
|
|
- blackJackPlayer.addToHand(playerCard2);
|
|
137
|
+ for (int i = 0; i < 2; i++) {
|
|
138
|
+ for (BlackJackPlayer player : this.blackJackPlayers) {
|
|
139
|
+ Card card = deck.draw();
|
|
140
|
+ player.addToHand(card);
|
|
141
|
+ }
|
|
142
|
+ }
|
89
|
143
|
|
90
|
|
- Card dealerCard2 = deck.draw();
|
91
|
|
- dealerHand.add(dealerCard2);
|
|
144
|
+ System.out.println("Your Current Hand: \n" + formatHand(this.blackJackPlayers.get(1).getPlayerHand()) + "\nHand Value: " + formatHandValue(countPlayerHand(this.blackJackPlayers.get(1))) + "\n");
|
|
145
|
+ System.out.println("Dealer's Current Hand: \nMYSTERY-CARD || " + formatHand(dealer.getDealerHand()) + "\nHand Value: ??" + "\n");
|
92
|
146
|
|
93
|
147
|
setJustDealt(true);
|
94
|
148
|
}
|
|
@@ -97,9 +151,26 @@ public class BlackJack extends CardGame implements Gamble {
|
97
|
151
|
return blackJackPlayers.get(index);
|
98
|
152
|
}
|
99
|
153
|
|
|
154
|
+ public BlackJackPlayer getDealer() {
|
|
155
|
+ return dealer;
|
|
156
|
+ }
|
|
157
|
+
|
100
|
158
|
public void start() {
|
|
159
|
+ Scanner reader = new Scanner(System.in);
|
|
160
|
+ System.out.println("Enter an initial bet: ");
|
|
161
|
+ int initialBet = reader.nextInt();
|
|
162
|
+
|
|
163
|
+ start(initialBet);
|
|
164
|
+ }
|
|
165
|
+
|
|
166
|
+ public void start(int initialBet) {
|
101
|
167
|
// upon starting a new game, every player places a bet? make a loop???
|
102
|
|
- betAmount(50, blackJackPlayers.get(0));
|
|
168
|
+ BlackJackPlayer blackJackPlayer = blackJackPlayers.get(0);
|
|
169
|
+ if (initialBet < minBet) {
|
|
170
|
+ System.out.println("TOo low");
|
|
171
|
+ } else {
|
|
172
|
+ blackJackPlayer.setInitialBet(betAmount(initialBet, blackJackPlayers.get(0)));
|
|
173
|
+ }
|
103
|
174
|
}
|
104
|
175
|
|
105
|
176
|
public void end() {
|
|
@@ -126,7 +197,6 @@ public class BlackJack extends CardGame implements Gamble {
|
126
|
197
|
break;
|
127
|
198
|
}
|
128
|
199
|
}
|
129
|
|
-
|
130
|
200
|
}
|
131
|
201
|
|
132
|
202
|
public int betAmount(int amount, BlackJackPlayer blackJackPlayer) {
|
|
@@ -149,4 +219,37 @@ public class BlackJack extends CardGame implements Gamble {
|
149
|
219
|
public void setJustDealt(boolean justDealt) {
|
150
|
220
|
this.justDealt = justDealt;
|
151
|
221
|
}
|
|
222
|
+
|
|
223
|
+ public String formatHand(ArrayList<Card> array) {
|
|
224
|
+ String stringHand = "";
|
|
225
|
+
|
|
226
|
+ String uglyArray = array.toString();
|
|
227
|
+
|
|
228
|
+ for (int i = 0; i < uglyArray.length(); i++) {
|
|
229
|
+ if (uglyArray.charAt(i) != ' ' && uglyArray.charAt(i) != '[' && uglyArray.charAt(i) != ']' && uglyArray.charAt(i) != ',') {
|
|
230
|
+ stringHand += uglyArray.charAt(i);
|
|
231
|
+ } else if (uglyArray.charAt(i) == ' ') {
|
|
232
|
+ stringHand += " || ";
|
|
233
|
+ }
|
|
234
|
+ }
|
|
235
|
+
|
|
236
|
+ return stringHand;
|
|
237
|
+ }
|
|
238
|
+
|
|
239
|
+ public String formatHandValue(ArrayList<Integer> array) {
|
|
240
|
+ String stringHandValue = "";
|
|
241
|
+
|
|
242
|
+ String uglyArray = array.toString();
|
|
243
|
+
|
|
244
|
+ for (int i = 0; i < uglyArray.length(); i++) {
|
|
245
|
+ if (uglyArray.charAt(i) != ' ' && uglyArray.charAt(i) != '[' && uglyArray.charAt(i) != ']' && uglyArray.charAt(i) != ',') {
|
|
246
|
+ stringHandValue += uglyArray.charAt(i);
|
|
247
|
+ } else if (uglyArray.charAt(i) == ' ') {
|
|
248
|
+ stringHandValue += " or ";
|
|
249
|
+ }
|
|
250
|
+ }
|
|
251
|
+
|
|
252
|
+ return stringHandValue;
|
|
253
|
+ }
|
|
254
|
+
|
152
|
255
|
}
|