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