|
@@ -4,11 +4,19 @@ import java.util.ArrayList;
|
4
|
4
|
|
5
|
5
|
public class Stud extends CardGame implements Game {
|
6
|
6
|
Console console = new Console();
|
|
7
|
+ private boolean isDealt = false;
|
|
8
|
+ private boolean isCardFlipped = false;
|
|
9
|
+ private int countRound = 0;
|
7
|
10
|
|
8
|
11
|
public Stud(int ante) {
|
9
|
12
|
super(ante);
|
10
|
13
|
}
|
11
|
14
|
|
|
15
|
+
|
|
16
|
+ public boolean getIsDealt(){
|
|
17
|
+ return isDealt;
|
|
18
|
+ }
|
|
19
|
+
|
12
|
20
|
public void playCard(Player player, Card card) {
|
13
|
21
|
card.setVisibility(true); //CARD isVISIBLE
|
14
|
22
|
Printer.showCard(player, card); //PRINT card name to CONSOLE
|
|
@@ -23,11 +31,10 @@ public class Stud extends CardGame implements Game {
|
23
|
31
|
CardPlayer winner = null;
|
24
|
32
|
|
25
|
33
|
for(int i = 0; i < players.size(); i ++){
|
26
|
|
- CardPlayer player = players.get(i);
|
27
|
|
- int playerHandValue = handValue(player); // 'handValue' method sets 'max' value of this hand
|
|
34
|
+ int playerHandValue = handValue(players.get(i)); // 'handValue' method sets 'max' value of this hand
|
28
|
35
|
if(playerHandValue > max){
|
29
|
36
|
max = playerHandValue;
|
30
|
|
- winner = player;
|
|
37
|
+ winner = players.get(i);
|
31
|
38
|
}
|
32
|
39
|
}
|
33
|
40
|
System.out.println("The winner is " + winner.getPlayer().getName());
|
|
@@ -127,18 +134,17 @@ public class Stud extends CardGame implements Game {
|
127
|
134
|
return handValue;
|
128
|
135
|
}
|
129
|
136
|
|
130
|
|
- public void payAnte() {
|
|
137
|
+ public void payAnte(ArrayList<CardPlayer> players) {
|
131
|
138
|
for(int i = 0; i < super.getPlayers().size(); i ++)
|
132
|
139
|
{
|
133
|
|
- CardPlayer player = super.getPlayers().get(i);
|
134
|
|
- player.getPlayer().changeBalance(-super.getAnte());
|
|
140
|
+ players.get(i).getPlayer().changeBalance(-super.getAnte());
|
135
|
141
|
}
|
136
|
142
|
}
|
137
|
143
|
|
138
|
144
|
public void startGame() {
|
139
|
145
|
setHandSize(3); //SET Hand Size for game(3)
|
140
|
|
- payAnte(); //PAY ante (all players)
|
141
|
|
- deal(); //DEALS cards/ hands to each player
|
|
146
|
+ payAnte(this.getPlayers()); //PAY ante (all players)
|
|
147
|
+ deal(this.getPlayers()); //DEALS cards/ hands to each player
|
142
|
148
|
startRound(); //METHOD called
|
143
|
149
|
|
144
|
150
|
}
|
|
@@ -149,81 +155,50 @@ public class Stud extends CardGame implements Game {
|
149
|
155
|
public void startRound() {
|
150
|
156
|
System.out.println("Welcome to Three Card Stud! Cards are dealt!");
|
151
|
157
|
flipCard();
|
152
|
|
- gameRound1();
|
|
158
|
+ gameRound(this.getPlayers(), countRound);
|
|
159
|
+ countRound++;
|
153
|
160
|
flipCard();
|
154
|
|
- gameRound2();
|
|
161
|
+ gameRound(this.getPlayers(), countRound);
|
|
162
|
+ countRound++;
|
155
|
163
|
flipCard();
|
156
|
|
- lastGameRound();
|
|
164
|
+ gameRound(this.getPlayers(), countRound);
|
157
|
165
|
determineWinner(this.getPlayers()); //TEST ADDED ARGUMENT
|
158
|
166
|
}
|
159
|
167
|
|
160
|
|
-
|
161
|
168
|
/**
|
162
|
169
|
* Plays through rounds that includes flipping cards face up and then betting or folding
|
163
|
170
|
*/
|
164
|
|
- public void gameRound1(){
|
165
|
|
- playersPlayCard1();
|
166
|
|
- }
|
167
|
|
-
|
168
|
|
- private void playersPlayCard1(){
|
169
|
|
- for (int j = 0; j < getPlayers().size(); j++) {
|
170
|
|
- CardPlayer player = super.getPlayers().get(j); //GET a player
|
171
|
|
- playCard(player.getPlayer(), player.getHand().get(0)); //SHOW-PRINT players first CARD
|
172
|
|
- }
|
173
|
|
- }
|
174
|
|
-
|
175
|
|
- /**
|
176
|
|
- * Plays through rounds that includes flipping cards face up and then betting or folding
|
177
|
|
- */
|
178
|
|
- public void gameRound2(){
|
179
|
|
- playersPlayCard2();
|
180
|
|
- }
|
181
|
|
-
|
182
|
|
- private void playersPlayCard2(){
|
183
|
|
- for (int j = 0; j < getPlayers().size(); j++) {
|
184
|
|
- CardPlayer player = super.getPlayers().get(j); //GET a player
|
185
|
|
- playCard(player.getPlayer(), player.getHand().get(1)); //SHOW-PRINT players first CARD
|
186
|
|
- }
|
187
|
|
- }
|
188
|
|
-
|
189
|
|
- /**
|
190
|
|
- * PreCondition: Betting rounds already played
|
191
|
|
- * Plays through round that include flipping last card face up
|
192
|
|
- * PostCondtion: tablePot is now at max value
|
193
|
|
- * DetermineWinner() expected to be called after this method
|
194
|
|
- */
|
195
|
|
- public void lastGameRound(){
|
196
|
|
- for (int j = 0; j < getPlayers().size(); j++) {
|
197
|
|
- CardPlayer player = super.getPlayers().get(j); //GET a player
|
198
|
|
- playCard(player.getPlayer(), player.getHand().get(2)); //SHOW-PRINT players first CARD
|
|
171
|
+ public void gameRound(ArrayList<CardPlayer> players, int countRound){
|
|
172
|
+ for (int j = 0; j < players.size(); j++) {
|
|
173
|
+ playCard(players.get(j).getPlayer(), players.get(j).getHand().get(countRound)); //SHOW-PRINT players first CARD
|
199
|
174
|
}
|
200
|
175
|
}
|
201
|
176
|
|
202
|
177
|
/**
|
203
|
178
|
* Deal each player(and dealer) 3 face down cards in turn
|
204
|
179
|
*/
|
205
|
|
- public void deal() {
|
|
180
|
+ public void deal(ArrayList<CardPlayer> players) {
|
206
|
181
|
for(int i = 0; i < getHandSize(); i ++){ //OUTER loop - run 3 times as there are 3 cards per hand
|
207
|
|
- for (int j = 0; j < getPlayers().size(); j++) { //INNER loop through each player
|
208
|
|
- Card card = super.getDeck().pullCard(); //PULL card from deck (removed from deck)
|
209
|
|
- CardPlayer player = super.getPlayers().get(j); //GET a player
|
210
|
|
- player.getHand().add(card); //ADD card to player hand
|
|
182
|
+ for (int j = 0; j < players.size(); j++) { //INNER loop through each player
|
|
183
|
+ players.get(j).getHand().add(getDeck().pullCard()); //ADD card to player hand
|
211
|
184
|
}
|
212
|
185
|
}
|
|
186
|
+ isDealt = true;
|
213
|
187
|
}
|
214
|
188
|
|
215
|
|
- public void flipCard()
|
|
189
|
+ public boolean flipCard()
|
216
|
190
|
{
|
217
|
|
- boolean flipnextCard = false;
|
218
|
|
- while(!flipnextCard) {
|
|
191
|
+ isCardFlipped = false;
|
|
192
|
+ while(!isCardFlipped) {
|
219
|
193
|
String input = "";
|
220
|
194
|
input = console.getCMDFromUser("Type 'FLIP' to play the cards at the top of your pile");
|
221
|
195
|
if (input.equals("flip")) {
|
222
|
|
- break;
|
|
196
|
+ isCardFlipped = true;
|
223
|
197
|
} else {
|
224
|
198
|
System.out.println("Sorry, I don't understand that command.");
|
225
|
199
|
}
|
226
|
200
|
}
|
|
201
|
+ return isCardFlipped;
|
227
|
202
|
}
|
228
|
203
|
|
229
|
204
|
public void quit() {}
|