|
@@ -1,53 +1,270 @@
|
1
|
1
|
package io.zipcoder.casino;
|
|
2
|
+import java.util.Scanner;
|
2
|
3
|
|
3
|
4
|
public class Stud extends CardGame implements Gamble, Game {
|
|
5
|
+ Scanner scanner = new Scanner(System.in);
|
|
6
|
+ Console console;
|
|
7
|
+ // private int roundCount = 0;
|
|
8
|
+
|
4
|
9
|
public Stud(int minBet, int maxBet, int ante) {
|
5
|
10
|
super(minBet, maxBet, ante);
|
6
|
11
|
}
|
|
12
|
+
|
|
13
|
+ public void playCard(Player player, Card card) {
|
|
14
|
+ card.setVisibility(true); //CARD isVISIBLE
|
|
15
|
+ Printer.showCard(player, card); //PRINT card name to CONSOLE
|
|
16
|
+ }
|
7
|
17
|
|
8
|
|
- public void deal() {
|
|
18
|
+
|
|
19
|
+ public void fold(){
|
9
|
20
|
|
10
|
21
|
}
|
11
|
22
|
|
12
|
|
- public void determineWinner(){
|
|
23
|
+ /**
|
|
24
|
+ * Determine what player wins by looping through player array and then
|
|
25
|
+ * passing each hand to the 'handValue' method
|
|
26
|
+ */
|
|
27
|
+ public CardPlayer determineWinner(){
|
|
28
|
+ int max = 0;
|
|
29
|
+ CardPlayer winner = null;
|
13
|
30
|
|
|
31
|
+ for(int i = 0; i < getPlayers().size(); i ++){
|
|
32
|
+ CardPlayer player = getPlayers().get(i);
|
|
33
|
+ int playerHandValue = handValue(player); // 'handValue' method sets 'max' value of this hand
|
|
34
|
+ if(playerHandValue > max){
|
|
35
|
+ max = playerHandValue;
|
|
36
|
+ winner = player;
|
|
37
|
+ }
|
|
38
|
+ }
|
|
39
|
+ System.out.println("The winner is " + winner.getPlayer().getName());
|
|
40
|
+ System.out.println(winner.getPlayer().getName() + "\'s hand was: " + winner.getHand().get(0).getName() + " - " + winner.getHand().get(1).getName() + " - " + winner.getHand().get(2).getName() );
|
|
41
|
+ return winner;
|
14
|
42
|
}
|
15
|
43
|
|
16
|
|
- public void fold(){
|
|
44
|
+ /**
|
|
45
|
+ * Method will return a int value, larger value means strong hand to determine the winning player
|
|
46
|
+ * @param player
|
|
47
|
+ * @return
|
|
48
|
+ */
|
|
49
|
+ public int handValue(CardPlayer player){
|
|
50
|
+ int handValue = 0;
|
|
51
|
+ int card1 = player.getHand().get(0).getCardValue();
|
|
52
|
+ int card2 = player.getHand().get(1).getCardValue();
|
|
53
|
+ int card3 = player.getHand().get(2).getCardValue();
|
17
|
54
|
|
|
55
|
+ //Three of a Kind
|
|
56
|
+ if (card1 == card2 && card1 == card3){
|
|
57
|
+ handValue = card1 * 1000000;
|
|
58
|
+ //Two pair
|
|
59
|
+ }
|
|
60
|
+ else if (card1 == card2){
|
|
61
|
+ handValue = (card1 * 10000) + card3;
|
|
62
|
+ }
|
|
63
|
+ else if (card1 == card3){
|
|
64
|
+ handValue = (card1 * 10000) + card2;
|
|
65
|
+ }
|
|
66
|
+ else if (card2 == card3){
|
|
67
|
+ handValue = (card2 * 10000) + card1;
|
|
68
|
+ //High Card
|
|
69
|
+ } else {
|
|
70
|
+ // Card1 is Highest
|
|
71
|
+ if (card1 > card2 && card1 > card3 && card2 > card3) {
|
|
72
|
+ handValue = (card1 * 100) + (card2 * 10) + card3;
|
|
73
|
+ }
|
|
74
|
+ else if (card1 > card2 && card1 > card3 && card3 > card2) {
|
|
75
|
+ handValue = (card1 * 100) + (card3 * 10) + card2;
|
|
76
|
+ }
|
|
77
|
+ // Card2 is Highest
|
|
78
|
+ else if (card2 > card1 && card2 > card3 && card1 > card3) {
|
|
79
|
+ handValue = (card2 * 100) + (card1 * 10) + card3;
|
|
80
|
+ }
|
|
81
|
+ else if (card2 > card1 && card2 > card3 && card3 > card1) {
|
|
82
|
+ handValue = (card2 * 100) + (card3 * 10) + card1;
|
|
83
|
+ }
|
|
84
|
+ // Card3 is Highest
|
|
85
|
+ else if (card3 > card1 && card3 > card2 && card1 > card3) {
|
|
86
|
+ handValue = (card3 * 100) + (card1 * 10) + card3;
|
|
87
|
+ }
|
|
88
|
+ else if (card3 > card1 && card3 > card2 && card3 > card1) {
|
|
89
|
+ handValue = (card3 * 100) + (card3 * 10) + card1;
|
|
90
|
+ }
|
|
91
|
+ else {
|
|
92
|
+ handValue = 0;
|
|
93
|
+ }
|
|
94
|
+ }
|
|
95
|
+ return handValue;
|
18
|
96
|
}
|
19
|
97
|
|
20
|
|
- /**
|
21
|
|
- * Below 3 Implemented from Gamble
|
22
|
|
- * @param betAmount
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+ /*
|
|
105
|
+
|
|
106
|
+ create a bet method which asks the first player how much to bet
|
|
107
|
+ loops through other plays to see how they would like to react to this.
|
|
108
|
+
|
|
109
|
+ fold, call, raise, check
|
|
110
|
+
|
23
|
111
|
*/
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
24
|
118
|
public void bet(int betAmount) {
|
|
119
|
+ super.changeTablePot(betAmount);
|
|
120
|
+ //player.changeBalance(betAmount * -1);
|
|
121
|
+ }
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
25
|
125
|
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+ public void payout(){
|
|
139
|
+ if(super.getWinner() != null){
|
|
140
|
+ super.getWinner().changeBalance(super.getTablePot());
|
|
141
|
+ }
|
|
142
|
+ System.out.println(getWinner().getName() + " won: " + super.getTablePot());
|
26
|
143
|
}
|
27
|
144
|
|
28
|
|
- public void payout() {
|
|
145
|
+ public void payAnte() {
|
|
146
|
+ for(int i = 0; i < super.getPlayers().size(); i ++)
|
|
147
|
+ {
|
|
148
|
+ CardPlayer player = super.getPlayers().get(i);
|
|
149
|
+ player.getPlayer().changeBalance(-super.getAnte());
|
|
150
|
+ }
|
|
151
|
+ }
|
29
|
152
|
|
|
153
|
+ public void Quit() {
|
|
154
|
+ System.out.println("Play again? Y : or any key to quit.");
|
|
155
|
+ String answer = scanner.next();
|
|
156
|
+ if (answer.equals("Y")){
|
|
157
|
+ startGame();
|
|
158
|
+ } else {
|
|
159
|
+ console = new Console();
|
|
160
|
+ }
|
30
|
161
|
}
|
31
|
162
|
|
32
|
163
|
|
33
|
|
- public void Ante(int anteAmount) {
|
|
164
|
+ public void startGame() {
|
|
165
|
+ // Deck deck = new Deck(); //CREATE deck for game
|
|
166
|
+ setHandSize(3); //SET Hand Size for game(3)
|
|
167
|
+ payAnte(); //PAY ante (all players)
|
|
168
|
+ deal(); //DEALS cards/ hands to each player
|
|
169
|
+ startRound(); //METHOD called
|
34
|
170
|
|
35
|
171
|
}
|
36
|
172
|
|
37
|
|
-
|
38
|
173
|
/**
|
39
|
|
- * Below 3 Implemented from Game
|
|
174
|
+ * Game played in this method by calling the 'gameRound' methods
|
40
|
175
|
*/
|
|
176
|
+ public void startRound() {
|
|
177
|
+ System.out.println("Welcome to Three Card Stud!");
|
|
178
|
+ //for (int i = 0; i < getHandSize() - 1; i++){ //Each player turns a card in hand to face up
|
|
179
|
+ gameRound1();
|
|
180
|
+ gameRound2();
|
|
181
|
+ //}
|
|
182
|
+ lastGameRound();
|
|
183
|
+ determineWinner();
|
|
184
|
+ // Payout();
|
|
185
|
+ }
|
41
|
186
|
|
42
|
|
- public void quit() {
|
43
|
187
|
|
|
188
|
+ /**
|
|
189
|
+ * Plays through rounds that includes flipping cards face up and then betting or folding
|
|
190
|
+ */
|
|
191
|
+ public void gameRound1(){
|
|
192
|
+ for (int j = 0; j < getPlayers().size(); j++) {
|
|
193
|
+ CardPlayer player = super.getPlayers().get(j); //GET a player
|
|
194
|
+ playCard(player.getPlayer(), player.getHand().get(0)); //SHOW-PRINT players first CARD
|
|
195
|
+ //roundCount++;
|
|
196
|
+ }
|
|
197
|
+ for (int x = 0; x < getPlayers().size(); x++) { //Betting round or fold
|
|
198
|
+ CardPlayer player = super.getPlayers().get(x);
|
|
199
|
+ int bet;
|
|
200
|
+ //ask player to bet and pass amount to Bet(betAmount
|
|
201
|
+ System.out.println("Enter a bet, if 0 is entered you fold");
|
|
202
|
+//TRY- CATCH OR WHILE/IF statement
|
|
203
|
+ bet = Integer.parseInt(scanner.next());
|
|
204
|
+ if (bet == 0){
|
|
205
|
+ System.out.println(player.getPlayer().getName() + " folds.");
|
|
206
|
+ //if fold, player is removed from game
|
|
207
|
+ //if only 1 player game ends
|
|
208
|
+ } else {
|
|
209
|
+ bet(bet);
|
|
210
|
+ System.out.println(player.getPlayer().getName() + " bets: " + bet);
|
|
211
|
+ }
|
|
212
|
+ }
|
44
|
213
|
}
|
45
|
214
|
|
46
|
|
- public void startGame() {
|
|
215
|
+ public void quit() {}
|
47
|
216
|
|
|
217
|
+ /**
|
|
218
|
+ * Plays through rounds that includes flipping cards face up and then betting or folding
|
|
219
|
+ */
|
|
220
|
+ public void gameRound2(){
|
|
221
|
+ for (int j = 0; j < getPlayers().size(); j++) {
|
|
222
|
+ CardPlayer player = super.getPlayers().get(j); //GET a player
|
|
223
|
+ playCard(player.getPlayer(), player.getHand().get(1)); //SHOW-PRINT players first CARD
|
|
224
|
+ //roundCount++;
|
|
225
|
+ }
|
|
226
|
+ for (int x = 0; x < getPlayers().size(); x++) { //Betting round or fold
|
|
227
|
+ CardPlayer player = super.getPlayers().get(x);
|
|
228
|
+ int bet;
|
|
229
|
+ //ask player to bet and pass amount to Bet(betAmount
|
|
230
|
+ System.out.println("Enter a bet, if 0 is entered you fold");
|
|
231
|
+//TRY- CATCH OR WHILE/IF statement
|
|
232
|
+ bet = Integer.parseInt(scanner.next());
|
|
233
|
+ if (bet == 0){
|
|
234
|
+ System.out.println(player.getPlayer().getName() + " folds.");
|
|
235
|
+ //if fold, player is removed from game
|
|
236
|
+ //if only 1 player game ends
|
|
237
|
+ } else {
|
|
238
|
+ bet(bet);
|
|
239
|
+ System.out.println(player.getPlayer().getName() + " bets: " + bet);
|
|
240
|
+ }
|
|
241
|
+ }
|
|
242
|
+ }
|
|
243
|
+
|
|
244
|
+ /**
|
|
245
|
+ * PreCondition: Betting rounds already played
|
|
246
|
+ * Plays through round that include flipping last card face up
|
|
247
|
+ * PostCondtion: tablePot is now at max value
|
|
248
|
+ * DetermineWinner() expected to be called after this method
|
|
249
|
+ */
|
|
250
|
+ public void lastGameRound(){
|
|
251
|
+ for (int j = 0; j < getPlayers().size(); j++) {
|
|
252
|
+ CardPlayer player = super.getPlayers().get(j); //GET a player
|
|
253
|
+ playCard(player.getPlayer(), player.getHand().get(2)); //SHOW-PRINT players first CARD
|
|
254
|
+ }
|
48
|
255
|
}
|
49
|
256
|
|
50
|
|
- public void startRound() {
|
51
|
257
|
|
|
258
|
+ /**
|
|
259
|
+ * Deal each player(and dealer) 3 face down cards in turn
|
|
260
|
+ */
|
|
261
|
+ public void deal() {
|
|
262
|
+ for(int i = 0; i < getHandSize(); i ++){ //OUTER loop - run 3 times as there are 3 cards per hand
|
|
263
|
+ for (int j = 0; j < getPlayers().size(); j++) { //INNER loop through each player
|
|
264
|
+ Card card = super.getDeck().pullCard(); //PULL card from deck (removed from deck)
|
|
265
|
+ CardPlayer player = super.getPlayers().get(j); //GET a player
|
|
266
|
+ player.getHand().add(card); //ADD card to player hand
|
|
267
|
+ }
|
|
268
|
+ }
|
52
|
269
|
}
|
53
|
270
|
}
|