|
@@ -1,21 +1,17 @@
|
1
|
1
|
package io.zipcoder.casino.cardgames;
|
2
|
2
|
|
3
|
|
-import io.zipcoder.casino.cardgames.cards.Card;
|
4
|
|
-import io.zipcoder.casino.cardgames.cards.CardHand;
|
5
|
|
-import io.zipcoder.casino.cardgames.cards.CardValue;
|
6
|
|
-import io.zipcoder.casino.cardgames.cards.Deck;
|
|
3
|
+import io.zipcoder.casino.utilities.Card;
|
|
4
|
+import io.zipcoder.casino.utilities.containers.CardHand;
|
|
5
|
+import io.zipcoder.casino.utilities.containers.Deck;
|
7
|
6
|
import io.zipcoder.casino.utilities.Console;
|
8
|
7
|
import io.zipcoder.casino.utilities.Gamble;
|
9
|
8
|
import io.zipcoder.casino.player.BlackJackPlayer;
|
10
|
9
|
import io.zipcoder.casino.player.Player;
|
11
|
10
|
import io.zipcoder.casino.player.Players;
|
12
|
11
|
|
13
|
|
-import java.sql.SQLOutput;
|
14
|
12
|
import java.util.ArrayList;
|
15
|
|
-import java.util.Vector;
|
16
|
13
|
|
17
|
14
|
public class BlackJack extends CardGame implements Gamble {
|
18
|
|
- long upcardsValue = 0;
|
19
|
15
|
|
20
|
16
|
private Deck deck = new Deck();
|
21
|
17
|
private ArrayList<BlackJackPlayer> blackJackPlayers = new ArrayList<>();
|
|
@@ -25,7 +21,7 @@ public class BlackJack extends CardGame implements Gamble {
|
25
|
21
|
|
26
|
22
|
public BlackJack(){
|
27
|
23
|
readyPlayers();
|
28
|
|
- placeBet();
|
|
24
|
+ dealCards(2);
|
29
|
25
|
run();
|
30
|
26
|
}
|
31
|
27
|
|
|
@@ -42,35 +38,41 @@ public class BlackJack extends CardGame implements Gamble {
|
42
|
38
|
}
|
43
|
39
|
|
44
|
40
|
public boolean play(BlackJackPlayer currentPlayer, long bet) {
|
|
41
|
+ placeBet();
|
|
42
|
+ // this.bet = bet;
|
45
|
43
|
|
46
|
|
- this.bet = bet;
|
|
44
|
+ Console.println("The dealer is dealing cards to the players.");
|
47
|
45
|
|
48
|
|
- dealCards(2);
|
49
|
46
|
dealerHand.add(deck.removeFirst());
|
50
|
47
|
dealerHand.add(deck.removeFirst());
|
51
|
48
|
|
|
49
|
+ Console.println(String.format("%s, you're up!", currentPlayer.getP().getName()));
|
|
50
|
+
|
52
|
51
|
if (getSum(dealerHand) == 21){
|
53
|
52
|
Console.println("Dealer has +," + dealerHand.display());
|
54
|
53
|
Console.println("You have " + currentPlayer.getHand().display());
|
55
|
|
- Console.println("Dealer win.");
|
|
54
|
+ Console.println("Dealer has blackjack. Dealer wins.");
|
56
|
55
|
}
|
57
|
56
|
|
|
57
|
+
|
|
58
|
+ Console.println(String.format("%s, you're up!", currentPlayer.getP().getName()));
|
|
59
|
+
|
58
|
60
|
if (getSum(currentPlayer.getHand()) == 21){
|
59
|
61
|
Console.println("Dealer has " + dealerHand.display());
|
60
|
62
|
Console.println("You have " + currentPlayer.getHand().display());
|
61
|
|
- Console.println("You win.");
|
|
63
|
+ Console.println("You have blackjack. You win.");
|
62
|
64
|
}
|
63
|
|
-
|
|
65
|
+
|
64
|
66
|
while(true) {
|
65
|
67
|
|
66
|
|
- Console.println("You have: " + currentPlayer.getHand().display());
|
67
|
|
- Console.println("Dealer is showing a " + dealerHand.get(0).getCard());
|
|
68
|
+ Console.println("You have: " + currentPlayer.getHand().display() + "\nYour sum is " + getSum(currentPlayer.getHand()));
|
|
69
|
+
|
68
|
70
|
String hitOrStand = Console.getStringInput("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
|
69
|
71
|
|
70
|
72
|
while (getSum(currentPlayer.getHand()) < 21) {
|
71
|
|
- if (hitOrStand.equals("H")) {
|
|
73
|
+ if (hitOrStand.equalsIgnoreCase("H")) {
|
72
|
74
|
dealCard(currentPlayer,1);
|
73
|
|
- } else if (hitOrStand.equals("S")) {
|
|
75
|
+ } else if (hitOrStand.equalsIgnoreCase("S")) {
|
74
|
76
|
break;
|
75
|
77
|
} else {
|
76
|
78
|
hitOrStand = Console.getStringInput("Invalid input. Please enter H for Hit or S for Stand");
|
|
@@ -78,15 +80,24 @@ public class BlackJack extends CardGame implements Gamble {
|
78
|
80
|
}
|
79
|
81
|
|
80
|
82
|
Console.println("You have: " + currentPlayer.getHand().display());
|
|
83
|
+ Console.println("The sum of your cards is " + getSum(currentPlayer.getHand()));
|
|
84
|
+
|
|
85
|
+ if (getSum(currentPlayer.getHand()) > 21){
|
|
86
|
+ Console.println("You busted. House wins.");
|
|
87
|
+ return false;
|
|
88
|
+ }
|
|
89
|
+
|
81
|
90
|
Console.println("Dealer's card are: " + dealerHand.display());
|
|
91
|
+ Console.println("The sum of dealer's cards is " + getSum(dealerHand));
|
82
|
92
|
|
83
|
93
|
while (getSum(dealerHand) < 17) {
|
84
|
|
- dealerHand.add(deck.removeFirst());
|
85
|
94
|
revealCard();
|
86
|
95
|
Console.println("Dealer's sum is " + getSum(dealerHand));
|
87
|
96
|
}
|
|
97
|
+
|
88
|
98
|
if (getSum(dealerHand) > 21) {
|
89
|
99
|
Console.println("Dealer busted. You win.");
|
|
100
|
+ return false;
|
90
|
101
|
}
|
91
|
102
|
|
92
|
103
|
if (getSum(dealerHand) == getSum(currentPlayer.getHand())) {
|
|
@@ -122,7 +133,7 @@ public class BlackJack extends CardGame implements Gamble {
|
122
|
133
|
}
|
123
|
134
|
|
124
|
135
|
public void placeBet() {
|
125
|
|
- bet = Console.getLongInput("Please enter your bet.");
|
|
136
|
+ this.bet = Console.getLongInput("Please enter your bet.");
|
126
|
137
|
}
|
127
|
138
|
|
128
|
139
|
|
|
@@ -138,12 +149,12 @@ public class BlackJack extends CardGame implements Gamble {
|
138
|
149
|
}
|
139
|
150
|
|
140
|
151
|
|
141
|
|
- public int getSum(CardHand cardHands) {
|
|
152
|
+ public int getSum(CardHand cardHand) {
|
142
|
153
|
int cardSum = 0;
|
143
|
154
|
boolean ace = false;
|
144
|
155
|
|
145
|
|
- for (int i = 0; i < cardHands.size(); i++) {
|
146
|
|
- int cardValue = cardHands.get(i).getCardValue().getCardValue();
|
|
156
|
+ for (int i = 0; i < cardHand.size(); i++) {
|
|
157
|
+ int cardValue = cardHand.get(i).getCardValue().getCardValue();
|
147
|
158
|
|
148
|
159
|
if (cardValue > 10) {
|
149
|
160
|
cardValue = 10; // For a Jack, Queen, or King.
|
|
@@ -153,13 +164,12 @@ public class BlackJack extends CardGame implements Gamble {
|
153
|
164
|
}
|
154
|
165
|
cardSum = cardSum + cardValue;
|
155
|
166
|
}
|
156
|
|
- if (ace == true && cardSum + 10 <= 21) {
|
|
167
|
+ if (cardHand.size() == 2 && ace == true && cardSum + 10 == 21) {
|
157
|
168
|
cardSum = cardSum + 10;
|
158
|
169
|
}
|
159
|
170
|
return cardSum;
|
160
|
171
|
}
|
161
|
172
|
|
162
|
|
-
|
163
|
173
|
public void revealCard(){
|
164
|
174
|
Card newCard = drawCard();
|
165
|
175
|
Console.println("Dealer drew a " + newCard.getCardValue() + " of " + newCard.getSuit());
|