|
@@ -1,11 +1,10 @@
|
1
|
1
|
package io.zipcoder.casino;
|
|
2
|
+
|
2
|
3
|
import java.util.ArrayList;
|
3
|
4
|
import java.util.Arrays;
|
4
|
|
-import java.util.Scanner;
|
5
|
|
-
|
6
|
5
|
|
7
|
6
|
|
8
|
|
-public class BlackJack1 {
|
|
7
|
+public class BlackJack {
|
9
|
8
|
|
10
|
9
|
|
11
|
10
|
private ArrayList<Card> playerHand = new ArrayList<Card>();
|
|
@@ -75,12 +74,13 @@ public class BlackJack1 {
|
75
|
74
|
this.playerHand = new ArrayList<Card>();
|
76
|
75
|
this.dealerHand = new ArrayList<Card>();
|
77
|
76
|
}
|
|
77
|
+
|
78
|
78
|
private void startHands() {
|
79
|
79
|
this.deck = new CardDeck();
|
80
|
80
|
this.deck.shuffle();
|
81
|
81
|
resetHands();
|
82
|
82
|
dealToPlayerHand(2);
|
83
|
|
- dealToDealerHand(2);
|
|
83
|
+ dealToDealerHand(1);
|
84
|
84
|
}
|
85
|
85
|
|
86
|
86
|
private void startNextHand() {
|
|
@@ -92,9 +92,9 @@ public class BlackJack1 {
|
92
|
92
|
private int getCardValue(Card card) {
|
93
|
93
|
Rank rank = card.getRank();
|
94
|
94
|
int calcValue = 0;
|
95
|
|
- switch(rank) {
|
|
95
|
+ switch (rank) {
|
96
|
96
|
case ACE:
|
97
|
|
- calcValue = 1;
|
|
97
|
+ calcValue = 11;
|
98
|
98
|
break;
|
99
|
99
|
case TWO:
|
100
|
100
|
calcValue = 2;
|
|
@@ -159,83 +159,68 @@ public class BlackJack1 {
|
159
|
159
|
setCurrentBet(bet);
|
160
|
160
|
startHands();
|
161
|
161
|
|
162
|
|
- Console.output(getPlayerHand());
|
163
|
|
-
|
164
|
|
- if (calcHand(dealerHand) == 21) {
|
165
|
|
- Console.output("Dealer has BlackJack! You lose!");
|
166
|
|
- player.subtractFromBankroll(currentBet);
|
167
|
|
- startNextHand();
|
168
|
|
- } else if (calcHand(playerHand) == 21) {
|
169
|
|
- Console.output("You have BlackJack! You win!");
|
170
|
|
- player.addToBankroll((currentBet * 3) / 2);
|
171
|
|
- startNextHand();
|
172
|
|
- }
|
173
|
|
-
|
174
|
|
- int stay = 0;
|
175
|
|
- while ((calcHand(playerHand) <= 21 && calcHand(dealerHand) <= 21) && stay < 2) {
|
176
|
|
- stay = 0;
|
|
162
|
+ Console.output("You have: " + getPlayerHand() + " for a total of " + calcHand(playerHand));
|
|
163
|
+ Console.output("Dealer is showing: " + getDealerHand());
|
|
164
|
+ boolean dStay = true;
|
|
165
|
+ boolean pStay = false;
|
|
166
|
+ while ((calcHand(playerHand) < 21 && calcHand(dealerHand) < 21) && pStay == false) {
|
177
|
167
|
String action = Console.askForInput("Hit or Stay? (H/S)");
|
178
|
|
-
|
179
|
168
|
if (action.equals("h")) {
|
180
|
169
|
dealToPlayerHand(1);
|
|
170
|
+ Console.output("You now have:\n" + getPlayerHand() + " for a total of " + calcHand(playerHand));
|
|
171
|
+ if (calcHand(playerHand) > 21) {
|
|
172
|
+ Console.output("Dealer wins! You bust.");
|
|
173
|
+ pStay = true;
|
|
174
|
+ startNextHand();
|
|
175
|
+ }
|
181
|
176
|
}
|
182
|
|
-
|
183
|
177
|
if (action.equals("s")) {
|
184
|
|
- stay++;
|
|
178
|
+ dealToDealerHand(1);
|
|
179
|
+ pStay = true;
|
|
180
|
+ dStay = false;
|
|
181
|
+ }
|
|
182
|
+ }
|
|
183
|
+ Console.output("Dealer has: " + getDealerHand() + " for a total of " + calcHand(dealerHand));
|
|
184
|
+ while (dStay == false) {
|
|
185
|
+ if (calcHand(dealerHand) > 21) {
|
|
186
|
+ Console.output("Dealer busts! You win");
|
|
187
|
+ startNextHand();
|
|
188
|
+ dStay = true;
|
185
|
189
|
}
|
186
|
|
-
|
187
|
190
|
if (calcHand(dealerHand) < 17) {
|
188
|
191
|
dealToDealerHand(1);
|
189
|
|
- } else {
|
190
|
|
- stay++;
|
191
|
|
- }
|
|
192
|
+ Console.output("Dealer hits.");
|
|
193
|
+ Console.output("Dealer has: " + getDealerHand() + " for a total of " + calcHand(dealerHand));
|
192
|
194
|
|
193
|
|
- Console.output("Player Hand: " + getPlayerHand());
|
194
|
|
- Console.output("Dealer Hand: " + showDealerHand());
|
|
195
|
+ } else if (calcHand(dealerHand) >= 17 && calcHand(dealerHand) <= 21) {
|
|
196
|
+ Console.output("Dealer stays.");
|
|
197
|
+ dStay = true;
|
|
198
|
+ }
|
195
|
199
|
}
|
196
|
|
-
|
197
|
|
- if (calcHand(playerHand) == calcHand(dealerHand)) {
|
198
|
|
- Console.output("It's a tie!");
|
199
|
|
- Console.output("Player Hand: " + getPlayerHand() + ", " + calcHand(playerHand));
|
200
|
|
- startNextHand();
|
201
|
|
- } else if (calcHand(playerHand) > 21) {
|
202
|
|
- Console.output("Dealer wins! You bust.");
|
203
|
|
- Console.output("Player Hand: " + getPlayerHand() + ", " + calcHand(playerHand));
|
204
|
|
- startNextHand();
|
205
|
|
- } else if (calcHand(dealerHand) > 21) {
|
206
|
|
- Console.output("You win! Dealer bust.");
|
207
|
|
- Console.output("Dealer Hand: " + getDealerHand() + ", " + calcHand(dealerHand));
|
|
200
|
+ if (calcHand(dealerHand) == 21) {
|
|
201
|
+ Console.output("Dealer has BlackJack! You lose!");
|
|
202
|
+ player.subtractFromBankroll(currentBet);
|
208
|
203
|
startNextHand();
|
209
|
|
- } else if (calcHand(playerHand) > calcHand(dealerHand)) {
|
210
|
|
- Console.output("Player has higher hand.");
|
211
|
|
- Console.output("Player Hand: " + getPlayerHand() + ", " + calcHand(playerHand));
|
|
204
|
+ } else if (calcHand(playerHand) == 21) {
|
|
205
|
+ Console.output("You have BlackJack! You win!");
|
|
206
|
+ player.addToBankroll((currentBet * 3) / 2);
|
212
|
207
|
startNextHand();
|
213
|
|
- } else if (calcHand(dealerHand) > calcHand(playerHand)) {
|
214
|
|
- Console.output("Dealer has higher hand.");
|
215
|
|
- Console.output("Player Hand: " + getDealerHand() + ", " + calcHand(playerHand));
|
|
208
|
+ } else if (calcHand(playerHand) == calcHand(dealerHand)) {
|
|
209
|
+ Console.output("It's a tie!");
|
216
|
210
|
startNextHand();
|
|
211
|
+ } else if ((calcHand(playerHand) < 22) && (calcHand(playerHand) > calcHand(dealerHand))) {
|
|
212
|
+ Console.output("You win!");
|
|
213
|
+ } else if ((calcHand(dealerHand) < 22) && (calcHand(dealerHand) > calcHand(playerHand))) {
|
|
214
|
+ Console.output("You lose!");
|
217
|
215
|
}
|
|
216
|
+ startNextHand();
|
|
217
|
+
|
218
|
218
|
}
|
219
|
219
|
}
|
220
|
220
|
}
|
|
221
|
+}
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
221
|
225
|
|
222
|
|
- public static void main(String[] args) {
|
223
|
|
- System.out.println("Welcome to Eugene's Casino, where your money is OUR money!");
|
224
|
|
- System.out.println("What's your name?");
|
225
|
|
- Scanner scan = new Scanner(System.in);
|
226
|
|
- Player play = new Player(name);
|
227
|
|
- // player.setName(name);
|
228
|
|
- System.out.println("Welcome " + name + "! Which game would you like to play?");
|
229
|
|
- System.out.println("1: BlackJack");
|
230
|
|
- System.out.println("2: Baccarat");
|
231
|
|
- System.out.println("3: Craps");
|
232
|
|
- choice = scan.nextLine();
|
233
|
|
- if (choice.equalsIgnoreCase("1")) {
|
234
|
|
- BlackJack bj = new BlackJack();
|
235
|
|
- bj.startGame();
|
236
|
|
- } else {
|
237
|
|
- System.out.println("This game is not available. Please choose again");
|
238
|
|
- }
|
239
|
226
|
|
240
|
|
- }
|
241
|
|
-}
|