|
@@ -40,82 +40,113 @@ public class BlackJack extends CardGame implements Gamble {
|
40
|
40
|
}
|
41
|
41
|
|
42
|
42
|
public boolean play(BlackJackPlayer currentPlayer, long bet) {
|
43
|
|
- placeBet();
|
44
|
43
|
// this.bet = bet;
|
45
|
44
|
|
46
|
45
|
Console.println("The dealer is dealing cards to the players.");
|
47
|
46
|
|
|
47
|
+ for (BlackJackPlayer p: this.blackJackPlayers){ //gets bet from each player
|
|
48
|
+ placeBet();
|
|
49
|
+ }
|
|
50
|
+
|
48
|
51
|
dealerHand.add(deck.removeFirst());
|
49
|
52
|
dealerHand.add(deck.removeFirst());
|
50
|
53
|
|
51
|
|
- Console.println(String.format("%s, you're up!", currentPlayer.getP().getName()));
|
|
54
|
+ Console.println("Dealer is showing a " + dealerHand.get(0).getCard()); // dealer reveals upcard
|
|
55
|
+
|
52
|
56
|
|
53
|
57
|
if (getSum(dealerHand) == 21){
|
54
|
58
|
Console.println("Dealer has +," + dealerHand.display());
|
55
|
59
|
Console.println("You have " + currentPlayer.getHand().display());
|
56
|
60
|
Console.println("Dealer has blackjack. Dealer wins.");
|
|
61
|
+ for (BlackJackPlayer p: this.blackJackPlayers){ // collects bet from all players
|
|
62
|
+ evaluateBet(p.getP(), bet);
|
|
63
|
+ }
|
57
|
64
|
}
|
|
65
|
+ evalBlackjack();
|
58
|
66
|
|
|
67
|
+ playersTurn();
|
59
|
68
|
|
60
|
|
- Console.println(String.format("%s, you're up!", currentPlayer.getP().getName()));
|
61
|
69
|
|
62
|
|
- if (getSum(currentPlayer.getHand()) == 21){
|
63
|
|
- Console.println("Dealer has " + dealerHand.display());
|
64
|
|
- Console.println("You have " + currentPlayer.getHand().display());
|
65
|
|
- Console.println("You have blackjack. You win.");
|
|
70
|
+ if (dealersTurn()) return false;
|
|
71
|
+
|
|
72
|
+ return evalWinner(currentPlayer, bet);
|
|
73
|
+
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ public boolean evalWinner(BlackJackPlayer currentPlayer, long bet) {
|
|
77
|
+ if (getSum(dealerHand) == getSum(currentPlayer.getHand())) {
|
|
78
|
+ Console.println("Dealer wins on a tie.");
|
|
79
|
+ evaluateBet(currentPlayer.getP(), -bet);
|
|
80
|
+ return false;
|
|
81
|
+ } else if (getSum(dealerHand) <=21 && getSum(dealerHand) > getSum(currentPlayer.getHand())) {
|
|
82
|
+ Console.println("Dealer wins.");
|
|
83
|
+ evaluateBet(currentPlayer.getP(), -bet);
|
|
84
|
+ return false;
|
|
85
|
+ } else {
|
|
86
|
+ Console.println("You win!");
|
|
87
|
+ evaluateBet(currentPlayer.getP(), bet);
|
|
88
|
+ return false;
|
66
|
89
|
}
|
67
|
|
-
|
68
|
|
- while(true) {
|
|
90
|
+ }
|
69
|
91
|
|
70
|
|
- Console.println("You have: " + currentPlayer.getHand().display() + "\nYour sum is " + getSum(currentPlayer.getHand()));
|
|
92
|
+ public boolean dealersTurn() {
|
|
93
|
+ Console.println("Dealer's card are: " + dealerHand.display());
|
|
94
|
+ Console.println("The sum of dealer's cards is " + getSum(dealerHand));
|
71
|
95
|
|
72
|
|
- String hitOrStand = Console.getStringInput("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
|
|
96
|
+ while (getSum(dealerHand) < 17) {
|
|
97
|
+ revealCard();
|
|
98
|
+ Console.println("Dealer's sum is " + getSum(dealerHand));
|
|
99
|
+ }
|
73
|
100
|
|
74
|
|
- while (getSum(currentPlayer.getHand()) < 21) {
|
75
|
|
- if (hitOrStand.equalsIgnoreCase("H")) {
|
76
|
|
- dealCards(currentPlayer,1);
|
77
|
|
- } else if (hitOrStand.equalsIgnoreCase("S")) {
|
78
|
|
- break;
|
79
|
|
- } else {
|
80
|
|
- hitOrStand = Console.getStringInput("Invalid input. Please enter H for Hit or S for Stand");
|
81
|
|
- }
|
82
|
|
- }
|
|
101
|
+ if (getSum(dealerHand) > 21) {
|
|
102
|
+ Console.println("Dealer busted. You win.");
|
|
103
|
+ return true;
|
|
104
|
+ }
|
|
105
|
+ return false;
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ public void playersTurn() {
|
|
109
|
+
|
|
110
|
+ for (BlackJackPlayer currentPlayer : this.blackJackPlayers) {
|
|
111
|
+
|
|
112
|
+ Console.println(String.format("%s, you're up!", currentPlayer.getP().getName()));
|
|
113
|
+
|
|
114
|
+ Console.println("You have: " + currentPlayer.getHand().display() + "\nYour sum is " + getSum(currentPlayer.getHand()));
|
|
115
|
+
|
|
116
|
+ hitOrStand(currentPlayer);
|
83
|
117
|
|
84
|
118
|
Console.println("You have: " + currentPlayer.getHand().display());
|
85
|
119
|
Console.println("The sum of your cards is " + getSum(currentPlayer.getHand()));
|
86
|
120
|
|
87
|
121
|
if (getSum(currentPlayer.getHand()) > 21){
|
88
|
122
|
Console.println("You busted. House wins.");
|
89
|
|
- return false;
|
90
|
|
- }
|
91
|
|
-
|
92
|
|
- Console.println("Dealer's card are: " + dealerHand.display());
|
93
|
|
- Console.println("The sum of dealer's cards is " + getSum(dealerHand));
|
94
|
|
-
|
95
|
|
- while (getSum(dealerHand) < 17) {
|
96
|
|
- revealCard();
|
97
|
|
- Console.println("Dealer's sum is " + getSum(dealerHand));
|
98
|
123
|
}
|
|
124
|
+ }
|
|
125
|
+ }
|
99
|
126
|
|
100
|
|
- if (getSum(dealerHand) > 21) {
|
101
|
|
- Console.println("Dealer busted. You win.");
|
102
|
|
- return false;
|
103
|
|
- }
|
|
127
|
+ public void hitOrStand(BlackJackPlayer currentPlayer) {
|
|
128
|
+ String hitOrStand = Console.getStringInput("Do you want to Hit or Stand? \n Enter H for Hit or S for Stand");
|
104
|
129
|
|
105
|
|
- if (getSum(dealerHand) == getSum(currentPlayer.getHand())) {
|
106
|
|
- Console.println("It's a tie. You lose.");
|
107
|
|
- return false;
|
108
|
|
- } else if (getSum(dealerHand) <=21 && getSum(dealerHand) > getSum(currentPlayer.getHand())) {
|
109
|
|
- Console.println("Dealer wins.");
|
110
|
|
- return false;
|
|
130
|
+ while (getSum(currentPlayer.getHand()) < 21) {
|
|
131
|
+ if (hitOrStand.equalsIgnoreCase("H")) {
|
|
132
|
+ dealCards(currentPlayer, 1);
|
|
133
|
+ } else if (hitOrStand.equalsIgnoreCase("S")) {
|
|
134
|
+ break;
|
111
|
135
|
} else {
|
112
|
|
- Console.println("You win!");
|
113
|
|
- return false;
|
|
136
|
+ hitOrStand = Console.getStringInput("Invalid input. Please enter H for Hit or S for Stand");
|
114
|
137
|
}
|
|
138
|
+ }
|
|
139
|
+ }
|
115
|
140
|
|
|
141
|
+ public void evalBlackjack() {
|
|
142
|
+ for (BlackJackPlayer p: this.blackJackPlayers)
|
|
143
|
+ if (getSum(p.getHand()) == 21){
|
|
144
|
+ Console.println("Dealer has " + dealerHand.display());
|
|
145
|
+ Console.println("You have " + p.getHand().display());
|
|
146
|
+ Console.println("You have blackjack. You win.");
|
116
|
147
|
}
|
|
148
|
+ }
|
117
|
149
|
|
118
|
|
-}
|
119
|
150
|
@Override
|
120
|
151
|
public void dealCards(int numberOfCards) {
|
121
|
152
|
|
|
@@ -142,7 +173,7 @@ public class BlackJack extends CardGame implements Gamble {
|
142
|
173
|
|
143
|
174
|
|
144
|
175
|
public void evaluateBet(Player player, long payout) {
|
145
|
|
-
|
|
176
|
+ player.setChipBalance(player.getChipBalance()+payout);
|
146
|
177
|
}
|
147
|
178
|
|
148
|
179
|
|
|
@@ -183,5 +214,4 @@ public class BlackJack extends CardGame implements Gamble {
|
183
|
214
|
@Override
|
184
|
215
|
public void promptContinue(){};
|
185
|
216
|
|
186
|
|
-
|
187
|
217
|
}
|