|
@@ -3,6 +3,7 @@ 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
|
|
|
@@ -11,41 +12,53 @@ import java.util.Scanner;
|
11
|
12
|
|
12
|
13
|
public class BlackJack extends CardGame implements Gamble {
|
13
|
14
|
|
14
|
|
- private ArrayList<BlackJackPlayer> blackJackPlayers;
|
15
|
|
- private int minBet;
|
16
|
|
- private ArrayList<Card> wastepile;
|
17
|
|
- private ArrayList<Card> dealerHand;
|
18
|
|
- private Deck deck;
|
19
|
|
- private boolean justDealt;
|
20
|
|
- 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
|
+
|
21
|
23
|
|
22
|
24
|
public BlackJack(Player player) {
|
23
|
25
|
BlackJackPlayer blackJackPlayer = new BlackJackPlayer(player);
|
24
|
|
- this.blackJackPlayers = new ArrayList<BlackJackPlayer>();
|
|
26
|
+ blackJackPlayers.add(dealer);
|
25
|
27
|
this.blackJackPlayers.add(blackJackPlayer);
|
26
|
|
- this.minBet = 100;
|
27
|
|
- this.wastepile = new ArrayList<Card>();
|
28
|
|
- this.dealerHand = new ArrayList<Card>();
|
29
|
|
- this.deck = new Deck();
|
30
|
|
- this.justDealt = false;
|
31
|
|
- this.numOfTurns = 0;
|
32
|
28
|
}
|
33
|
29
|
|
34
|
|
- // basically draw testestestetstsetsetstest
|
35
|
|
- public void hit(BlackJackPlayer blackJackPlayer) {
|
|
30
|
+ public void hit(BlackJackPlayer player) {
|
36
|
31
|
setJustDealt(false);
|
37
|
|
- Card playerCard1 = deck.draw();
|
38
|
|
- blackJackPlayer.addToHand(playerCard1);
|
39
|
|
- System.out.println(blackJackPlayer.getPlayerHand().toString());
|
40
|
|
- }
|
|
32
|
+ Card card = deck.draw();
|
|
33
|
+ player.addToHand(card);
|
41
|
34
|
|
42
|
|
- public void flip() {
|
43
|
|
- // shoulder technically be card.setCovered(false); or something like that
|
44
|
|
- boolean covered = false;
|
|
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
|
+ }
|
45
|
40
|
}
|
46
|
41
|
|
47
|
|
- public void split() {
|
|
42
|
+// public void flip() {
|
|
43
|
+// // shoulder technically be card.setCovered(false); or something like that
|
|
44
|
+// boolean covered = false;
|
|
45
|
+// }
|
|
46
|
+
|
|
47
|
+ public void split(BlackJackPlayer player) {
|
|
48
|
+
|
|
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());
|
48
|
60
|
setJustDealt(false);
|
|
61
|
+
|
49
|
62
|
// must be the same card value
|
50
|
63
|
}
|
51
|
64
|
|
|
@@ -63,33 +76,73 @@ public class BlackJack extends CardGame implements Gamble {
|
63
|
76
|
// (end turn?) what does "take a turn" actually initiate
|
64
|
77
|
}
|
65
|
78
|
|
66
|
|
- public int countHand(BlackJackPlayer blackJackPlayer) {
|
67
|
|
- 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;
|
68
|
97
|
|
69
|
|
- for (int i = 0; i < blackJackPlayer.getPlayerHand().size(); i++) {
|
70
|
|
- handSum += (blackJackPlayer.getPlayerHand().get(i).getFace().getSecondaryValue());
|
|
98
|
+ for (int i = 0; i < player.getPlayerHand().size(); i++) {
|
|
99
|
+ aceIsEleven += playerHand.get(i).getFace().getSecondaryValue();
|
71
|
100
|
}
|
|
101
|
+
|
|
102
|
+ return aceIsEleven;
|
|
103
|
+ }
|
|
104
|
+
|
|
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
|
+
|
72
|
131
|
return handSum;
|
73
|
132
|
}
|
74
|
133
|
|
75
|
|
- public void deal(BlackJackPlayer blackJackPlayer) {
|
76
|
|
- // BlackJackPlayer player1 = blackJackPlayers.get(playerIndex);
|
77
|
|
- // blackJackPlayers.add(blackJackPlayer);
|
78
|
|
- // should we move this to start instead? we would also need to deal for each player if multiple
|
|
134
|
+ public void deal() {
|
79
|
135
|
deck.shuffle();
|
80
|
|
- Card playerCard1 = deck.draw();
|
81
|
|
- blackJackPlayer.addToHand(playerCard1);
|
82
|
136
|
|
83
|
|
- Card dealerCard1 = deck.draw();
|
84
|
|
- dealerHand.add(dealerCard1);
|
85
|
|
- System.out.println("Mystery Card");
|
86
|
|
-
|
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);
|
92
|
|
- System.out.println(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");
|
93
|
146
|
|
94
|
147
|
setJustDealt(true);
|
95
|
148
|
}
|
|
@@ -98,6 +151,10 @@ public class BlackJack extends CardGame implements Gamble {
|
98
|
151
|
return blackJackPlayers.get(index);
|
99
|
152
|
}
|
100
|
153
|
|
|
154
|
+ public BlackJackPlayer getDealer() {
|
|
155
|
+ return dealer;
|
|
156
|
+ }
|
|
157
|
+
|
101
|
158
|
public void start() {
|
102
|
159
|
Scanner reader = new Scanner(System.in);
|
103
|
160
|
System.out.println("Enter an initial bet: ");
|
|
@@ -162,4 +219,37 @@ public class BlackJack extends CardGame implements Gamble {
|
162
|
219
|
public void setJustDealt(boolean justDealt) {
|
163
|
220
|
this.justDealt = justDealt;
|
164
|
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
|
+
|
165
|
255
|
}
|