瀏覽代碼

Merge branch 'dev' into HigherCards

Aleena Rose-Mathew 6 年之前
父節點
當前提交
fb528248a4

二進制
.DS_Store 查看文件


二進制
src/.DS_Store 查看文件


二進制
src/main/.DS_Store 查看文件


二進制
src/main/java/.DS_Store 查看文件


二進制
src/main/java/io/.DS_Store 查看文件


二進制
src/main/java/io/zipcoder/.DS_Store 查看文件


+ 10
- 10
src/main/java/io/zipcoder/casino/Leviathan/Console.java 查看文件

41
         return b;
41
         return b;
42
     }
42
     }
43
 
43
 
44
-    public String yesOrNo(String prompt){
44
+    public String yesOrNo(String prompt) {
45
         boolean good = false;
45
         boolean good = false;
46
-        String correct= "";
47
-        while(good == false){
48
-        String answer = getStringInput(prompt);
49
-        if(answer.equalsIgnoreCase("yes") || answer.equalsIgnoreCase("no")){
50
-            good = true;
51
-            correct = answer;
52
-        } else{
53
-            println("what was that? Please say yes or no.");
54
-        }
46
+        String correct = "";
47
+        while (good == false) {
48
+            String answer = getStringInput(prompt);
49
+            if (answer.equalsIgnoreCase("yes") || answer.equalsIgnoreCase("no")) {
50
+                good = true;
51
+                correct = answer;
52
+            } else {
53
+                println("what was that? Please say yes or no.");
54
+            }
55
         }
55
         }
56
         return correct;
56
         return correct;
57
     }
57
     }

+ 213
- 147
src/main/java/io/zipcoder/casino/Leviathan/Games/BlackJack.java 查看文件

1
 package io.zipcoder.casino.Leviathan.Games;
1
 package io.zipcoder.casino.Leviathan.Games;
2
+
2
 import io.zipcoder.casino.Leviathan.Interfaces.*;
3
 import io.zipcoder.casino.Leviathan.Interfaces.*;
3
 import io.zipcoder.casino.Leviathan.*;
4
 import io.zipcoder.casino.Leviathan.*;
4
-import  io.zipcoder.casino.Leviathan.Games.GameUtilities.*;
5
+import io.zipcoder.casino.Leviathan.Games.GameUtilities.*;
6
+
7
+import java.util.ArrayList;
8
+import java.util.List;
5
 
9
 
6
 public class BlackJack extends CardGame implements Gambling {
10
 public class BlackJack extends CardGame implements Gambling {
7
 
11
 
9
     int wageAmount;
13
     int wageAmount;
10
     int totalChips;
14
     int totalChips;
11
     Player aPlayer;
15
     Player aPlayer;
16
+    boolean playAgain = true;
12
 
17
 
13
-    public BlackJack(Player aPlayer){
18
+    public BlackJack(Player aPlayer) {
14
         this.aPlayer = aPlayer;
19
         this.aPlayer = aPlayer;
15
     }
20
     }
16
 
21
 
17
     int aPlayerScore = Game.playerScore;
22
     int aPlayerScore = Game.playerScore;
18
     int aHouseScore = Game.houseScore;
23
     int aHouseScore = Game.houseScore;
19
 
24
 
20
-    //assuming this to be a random card rank in int
21
-    //Card aCard = new Card(Rank.ACE,Suit.CLUBS);
22
-    //Rank aGetRank = aCard.getRank();
23
-
24
     Deck deck = new Deck();
25
     Deck deck = new Deck();
25
 
26
 
26
-
27
-
28
     String playerDecision;
27
     String playerDecision;
29
 
28
 
29
+    boolean win;
30
 
30
 
31
-    public void playGame() {
32
-        
33
-    }
34
-
35
-    public int drawASingleCard(int cardRank){
36
-
37
-        Card card = deck.draw();
38
-
39
-        Rank rank = card.getRank();
40
-
41
-        int cardInt =rank.getValue();
31
+////////////////////////////////////////////////////////////////////////////////////
42
 
32
 
43
-        return cardInt;
33
+    //draws the initial two cards
34
+    public List<Card> drawNewHand() {
35
+        List<Card> hand = new ArrayList<>();
36
+        hand.add(deck.draw());
37
+        hand.add(deck.draw());
38
+        return hand;
44
     }
39
     }
45
 
40
 
46
-    //Player making the starting bet
47
-    public int wageMoney() {
48
-
49
-        totalChips=aPlayer.getTotalChips();
50
-
51
-        wageAmount = aConsole.getIntInput("Please make your starting bet:");
52
-        if (wageAmount <= totalChips) {
53
-            aConsole.println("Your current bet amount is: " + wageAmount);
54
-            return wageAmount;
41
+    //get the sum int value of the drawn cards
42
+    public int getHandTotal(List<Card> hand) {
43
+        int sum = 0;
44
+        int countAces = 0;
45
+
46
+        for (Card c : hand) {
47
+            Rank rank = c.getRank();
48
+            int value = rank.getValue();
49
+
50
+            if (value <= 10) {
51
+                sum += value;
52
+            }
53
+            if (rank.equals(Rank.JACK) || rank.equals(Rank.QUEEN) || rank.equals(Rank.KING)) {
54
+                sum += 10;
55
+            }
56
+            if (rank.equals(Rank.ACE)) {
57
+                sum += 0;
58
+            }
59
+            if (rank.equals(Rank.ACE)) {
60
+                countAces += 1;
61
+            }
62
+        }
63
+        if (countAces == 0) {
64
+            return sum;
65
+        }
66
+        if ((sum + 11 + (countAces - 1)) <= 21) {
67
+            return sum + 11 + (countAces - 1);
55
         } else {
68
         } else {
56
-            aConsole.println("Insufficient Chips!");
57
-            //Recursion - this runs the method again and asks user to make the starting bet again
58
-            return wageMoney();
69
+            return sum + countAces;
59
         }
70
         }
60
     }
71
     }
61
 
72
 
62
-    //initial player card value
63
-    private int startPlayerHand() {
64
-
65
-//        Card card = deck.draw();
66
-//
67
-//        Rank rank = card.getRank();
68
-//
69
-//        int cardInt =rank.getRank();
70
-
71
-        //aPlayerScore = drawASingleCard();
73
+    //lets the player know of the starting hand
74
+    public String handToString(List<Card> hand) {
75
+        StringBuilder builder = new StringBuilder();
76
+        for (Card c : hand) {
77
+            String cardString = (c.getRank() + " of " + c.getSuit());
78
+            builder.append(cardString).append("\n");
79
+        }
80
+        return builder.toString();
81
+    }
72
 
82
 
83
+    //lets the player know one of house's starting hand
84
+    public String houseHandToString(List<Card> hand, int cardsToShow) {
85
+        StringBuilder builder = new StringBuilder();
86
+        for (int i = 0; i < cardsToShow; i++) {
87
+            builder.append(hand.get(i).getRank() + " of " + hand.get(i).getSuit() + "\n");
88
+        }
89
+        return builder.toString();
90
+    }
73
 
91
 
74
 
92
 
75
-        return aPlayerScore; //= aGetRank + aGetRank;
76
-    }
93
+    //draws a singe card
94
+    public Card drawSingleCard() {
77
 
95
 
78
-    //initial house card value
79
-    public int startHouseHand() {
80
-        return aHouseScore; //= aGetRank + aGetRank;
96
+        return deck.draw();
81
     }
97
     }
82
 
98
 
99
+    //Gets the int value of a single drawn card
100
+    public int getSingleCardValue(List<Card> hand) {
101
+        int cardValue = 0;
83
 
102
 
84
-    //ask for player's next move
85
-    public String blackJack(String playerDecision) {
86
-        if(startPlayerHand() < 21){
87
-            playerDecision = aConsole.getStringInput("Please make a call:\nHit\nStand\nRaise Bet");
103
+        for (Card c : hand) {
104
+            Rank rank = c.getRank();
105
+            int value = rank.getValue();
106
+            cardValue += value;
88
         }
107
         }
89
-        return playerDecision;
108
+        return cardValue;
90
     }
109
     }
91
 
110
 
111
+    public String drawnCardToString(Card card) {
112
+        return card.getRank() + " of " + card.getSuit();
113
+    }
92
 
114
 
115
+////////////////////////////////////////////////////////////////////////////////////
93
 
116
 
94
-    //Hit
95
-    public int hit(int playerHand) {
96
-
117
+    public void playGame() {
97
 
118
 
98
-        return 0;
119
+        while (playAgain == true) {
120
+
121
+            aConsole.println("*** Welcome " + this.aPlayer.getName() +
122
+                    ", let’s play BlackJack! ***\n");
123
+
124
+            int wageAmount = wageMoney();
125
+
126
+            //draw a fresh hand
127
+            List<Card> playerHand = drawNewHand();
128
+
129
+            //get the player's hand total
130
+            int handTotal = getHandTotal(playerHand);
131
+
132
+            //update player score with hand total
133
+            aPlayerScore = handTotal;
134
+
135
+            //show the player their hand
136
+            String handString = handToString(playerHand);
137
+            aConsole.println("\n You have drawn: \n" + handString);
138
+
139
+            //display hand total
140
+            aConsole.println("Your current hand value: " + aPlayerScore + "\n");
141
+
142
+            //draw a fresh hand for house
143
+            List<Card> houseHand = drawNewHand();
144
+
145
+            //get the house hand total
146
+            int houseHandTotal = getHandTotal(houseHand);
147
+
148
+            //update house score with hand total
149
+            aHouseScore = houseHandTotal;
150
+
151
+            //show the player one of house's card
152
+            //I need to figure out how I could only show one card
153
+            String houseHandString = houseHandToString(houseHand, 1);
154
+            aConsole.println("\n The house has drawn: \n" + houseHandString +
155
+                    "And has one card faced down");
156
+
157
+            //Decision
158
+            while (aPlayerScore < 21) {
159
+                //playerDecision = aConsole.getStringInput("Please make a call:\nHit\nStand\nRaise Bet");
160
+                playerDecision = aConsole.getStringInput("Please make a call:\nHit\nStand");
161
+
162
+                //Hit
163
+                if (playerDecision.equalsIgnoreCase("Hit")) {
164
+                    playerHit(playerHand);
165
+                }
166
+                if (playerDecision.equalsIgnoreCase("Stand")) {
167
+
168
+                    //House start drawing cards
169
+                    houseDraws(houseHand);
170
+                    break;
171
+                }
172
+            }
173
+
174
+            //House winning situation
175
+            if (aPlayerScore > 21) {
176
+                aConsole.println("Bust!");
177
+                win = false;
178
+                betChages(bet);
179
+                aConsole.println("Your current available chips: \n" + aPlayer.getTotalChips());
180
+            }else if ((aHouseScore >= aPlayerScore && aHouseScore < 21) || aHouseScore == 21) {
181
+                aConsole.println("You lose\n" + "Your score: " + aPlayerScore +
182
+                        "\nHouse score: " + aHouseScore);
183
+                aConsole.println("\n Dealer's hand: \n" + handToString(houseHand));
184
+                win = false;
185
+                betChages(bet);
186
+                aConsole.println("Your current available chips: \n" + aPlayer.getTotalChips());
187
+            }
188
+
189
+            //Player winning situation
190
+            else if (aHouseScore < 21) {
191
+                aConsole.println("You win!");
192
+                win = true;
193
+                betChages(bet);
194
+                aConsole.println("Your current available chips: \n" + aPlayer.getTotalChips());
195
+            } else {
196
+                //aConsole.println("You win!");
197
+                aConsole.println("You win!\n" + "Your score: " + aPlayerScore +
198
+                        "\nHouse score: " + aHouseScore);
199
+                win = true;
200
+                betChages(bet);
201
+                aConsole.println("Your current available chips: \n" + aPlayer.getTotalChips());
202
+            }
203
+            if ((aPlayer.getTotalChips() == 0) || aConsole.yesOrNo("Would you like to play again?").equalsIgnoreCase("no")) {
204
+                playAgain = false;
205
+            }
206
+        }
99
     }
207
     }
100
 
208
 
209
+    private void playerHit(List<Card> playerHand) {
210
+        //draw a new card
211
+        Card drawSingleCard = drawSingleCard();
212
+        playerHand.add(drawSingleCard);
101
 
213
 
102
-    //Stand
103
-    public int stand(int playerHand) {
214
+        //update player score with card value
215
+        aPlayerScore = getHandTotal(playerHand);
104
 
216
 
217
+        //show the newly drawn card
218
+        String newCardString = drawnCardToString(drawSingleCard);
219
+        aConsole.println("\n You have drawn: \n" + newCardString);
105
 
220
 
106
-        return 0;
221
+        //display updated hand total
222
+        aConsole.println("Your current hand value: " + aPlayerScore + "\n");
107
     }
223
     }
108
 
224
 
109
-    //Raise bet
110
-    public int raiseBet(int wageAmount) {
225
+    private void houseDraws(List<Card> houseHand) {
226
+        while (aPlayerScore > aHouseScore && aHouseScore < 21) {
227
+            //draw a new card
228
+            Card drawSingleCard = drawSingleCard();
229
+            houseHand.add(drawSingleCard);
111
 
230
 
231
+            //update house score with card value
232
+            aHouseScore = getHandTotal(houseHand);
112
 
233
 
113
-        return 0;
234
+            //show the newly drawn card
235
+            String newCardString = drawnCardToString(drawSingleCard);
236
+            aConsole.println("\n House have drawn: \n" + newCardString);
237
+        }
114
     }
238
     }
115
 
239
 
240
+    int bet;
241
+    public int wageMoney() {
242
+        //int bet;
243
+        totalChips = aPlayer.getTotalChips();
244
+        bet = aConsole.getIntInput("Please make your starting bet:\n" +
245
+                "You currently have: " + aPlayer.getTotalChips() + " chips.");
246
+        if (bet > 0 && bet <= totalChips) {
247
+            aConsole.println("Your current bet amount is: " + bet);
248
+            return bet;
249
+        } else if (bet == 0 || bet < 0) {
250
+            aConsole.println("You need to bet at least 1 chip");
251
+            return wageMoney();
252
+        } if(bet > totalChips) {
253
+            aConsole.println("Insufficient Chips!");
116
 
254
 
255
+            //return wageMoney();
256
+            return wageMoney();
257
+        }
258
+        return bet;
259
+    }
117
 
260
 
118
-
119
-
120
-
121
-
261
+    public void betChages(int wageAmount){
262
+        totalChips = aPlayer.getTotalChips();
263
+        if(win == true){
264
+            aPlayer.setTotalChips(totalChips + wageAmount);
265
+        } else{
266
+            aPlayer.setTotalChips(totalChips - wageAmount);
267
+        }
268
+    }
122
 }
269
 }
123
 
270
 
124
 
271
 
125
-//    public boolean playGame(Player aPlayer) {
126
-//        return false;
127
-//    }
128
-//
129
-//
130
-//    public int wageMoney() {
131
-//        return 0;
132
-//    }
133
-//
134
-//
135
-//
136
-//    private static final String HOLD_CONSTANT = "hold";
137
-//
138
-//
139
-//    public void blackJack (String[] args){
140
-//
141
-//        //user input for Int
142
-//        int betAmount = 0;
143
-//
144
-//        //user input for String
145
-//        String decision;
146
-//
147
-//
148
-//
149
-//
150
-//
151
-//
152
-//        int aPlayerScore = Game.playerScore;
153
-//
154
-//        int aHouseScore = Game.houseScore;
155
-//
156
-//
157
-//
158
-//
159
-//        //How do I make this work??
160
-//        //Card aCard = new Card();
161
-//        //or
162
-//        //int aCard = Card.getRank;
163
-//
164
-//
165
-//        ////////public int startTheGame(int playerScore, int houseScore, int getRank)
166
-//
167
-//        //playerScore = Card.getRank() + Card.getRank();
168
-//
169
-//        //houseScore = Card.getRank() + Card.getRank();
170
-//
171
-//
172
-//
173
-//
174
-//
175
-//        while(!HOLD_CONSTANT.equals(decision) || playerScore < 21) {
176
-//
177
-//            //IF statement that asks for userInput after each loop(?)
178
-//            //add sum values of two cards to playerScore hand
179
-//            //add sum values of two cards to houseScore hand
180
-//
181
-//           decision = aConsole.getStringInput("Please make a call:\nHit\nStand");
182
-//
183
-//
184
-//            If(decision.equals("Hit")) {
185
-//
186
-//                If(decision.equals("Ace") && playerScore > 10) {
187
-//                    playerScore + 1;
188
-//                }
189
-//                else{
190
-//                    playerScore + 11;
191
-//                }
192
-//            }
193
-//            else if(aConsole.getStringInput().equals("Stand"))
194
-//
195
-//
196
-//
197
-//    }
198
-//
199
-//    If(playerScore > 21){
200
-//
201
-//        }
202
-//
203
-//
204
-//    }
205
-
206
 
272
 
207
 
273
 
208
 
274
 

+ 5
- 5
src/main/java/io/zipcoder/casino/Leviathan/Games/DiceGame.java 查看文件

1
 package io.zipcoder.casino.Leviathan.Games;
1
 package io.zipcoder.casino.Leviathan.Games;
2
-import io.zipcoder.casino.Leviathan.Interfaces.*;
3
-import io.zipcoder.casino.Leviathan.*;
4
-import io.zipcoder.casino.Leviathan.Games.GameUtilities.*;
5
 
2
 
6
-public abstract class DiceGame implements Game{
7
-    Dice aDice ;
3
+import io.zipcoder.casino.Leviathan.Games.GameUtilities.Dice;
4
+import io.zipcoder.casino.Leviathan.Interfaces.Game;
5
+
6
+public abstract class DiceGame implements Game {
7
+    Dice aDice;
8
 
8
 
9
 }
9
 }

+ 7
- 0
src/main/java/io/zipcoder/casino/Leviathan/Games/GameUtilities/Dice.java 查看文件

27
         return dice;
27
         return dice;
28
     }
28
     }
29
 
29
 
30
+    public int sumAllDice() {
31
+        int sum = 0;
32
+        for (int i = 0; i < dice.length; i++) {
33
+            sum += dice[i].getValue();
34
+        }
35
+        return sum;
36
+    }
30
 
37
 
31
 }
38
 }

+ 52
- 52
src/main/java/io/zipcoder/casino/Leviathan/Games/GameUtilities/DiceBuilder.java 查看文件

1
 package io.zipcoder.casino.Leviathan.Games.GameUtilities;
1
 package io.zipcoder.casino.Leviathan.Games.GameUtilities;
2
+
2
 import java.util.Arrays;
3
 import java.util.Arrays;
3
 import java.util.Iterator;
4
 import java.util.Iterator;
4
-import java.util.List;
5
 
5
 
6
 public class DiceBuilder implements Iterable<String> {
6
 public class DiceBuilder implements Iterable<String> {
7
-private static final String[][] lines = {
8
-        {
9
-        "+-------+",
10
-        "|       |",
11
-        "|   o   |",
12
-        "|       |",
13
-        "+-------+",
14
-        },
15
-        {
16
-        "+-------+",
17
-        "| o     |",
18
-        "|       |",
19
-        "|     o |",
20
-        "+-------+",
21
-        },
22
-        {
23
-        "+-------+",
24
-        "| o     |",
25
-        "|   o   |",
26
-        "|     o |",
27
-        "+-------+",
28
-        },
29
-        {
30
-        "+-------+",
31
-        "| o   o |",
32
-        "|       |",
33
-        "| o   o |",
34
-        "+-------+",
35
-        },
36
-        {
37
-        "+-------+",
38
-        "| o   o |",
39
-        "|   o   |",
40
-        "| o   o |",
41
-        "+-------+",
42
-        },
43
-        {
44
-        "+-------+",
45
-        "| o   o |",
46
-        "| o   o |",
47
-        "| o   o |",
48
-        "+-------+",
49
-        }
50
-        };
7
+    private static final String[][] lines = {
8
+            {
9
+                    "+-------+",
10
+                    "|       |",
11
+                    "|   o   |",
12
+                    "|       |",
13
+                    "+-------+",
14
+            },
15
+            {
16
+                    "+-------+",
17
+                    "| o     |",
18
+                    "|       |",
19
+                    "|     o |",
20
+                    "+-------+",
21
+            },
22
+            {
23
+                    "+-------+",
24
+                    "| o     |",
25
+                    "|   o   |",
26
+                    "|     o |",
27
+                    "+-------+",
28
+            },
29
+            {
30
+                    "+-------+",
31
+                    "| o   o |",
32
+                    "|       |",
33
+                    "| o   o |",
34
+                    "+-------+",
35
+            },
36
+            {
37
+                    "+-------+",
38
+                    "| o   o |",
39
+                    "|   o   |",
40
+                    "| o   o |",
41
+                    "+-------+",
42
+            },
43
+            {
44
+                    "+-------+",
45
+                    "| o   o |",
46
+                    "| o   o |",
47
+                    "| o   o |",
48
+                    "+-------+",
49
+            }
50
+    };
51
 
51
 
52
-private int value;
52
+    private int value;
53
 
53
 
54
-public DiceBuilder(int value) {
54
+    public DiceBuilder(int value) {
55
         if (value < 0 || value >= 7) {
55
         if (value < 0 || value >= 7) {
56
-        throw new IllegalArgumentException("Illegal die value");
56
+            throw new IllegalArgumentException("Illegal die value");
57
         }
57
         }
58
         this.value = value;
58
         this.value = value;
59
-        }
59
+    }
60
 
60
 
61
-public Iterator<String> iterator() {
61
+    public Iterator<String> iterator() {
62
         return Arrays.asList(lines[value]).iterator();
62
         return Arrays.asList(lines[value]).iterator();
63
-        }
64
-        }
63
+    }
64
+}
65
 
65
 

+ 16
- 16
src/main/java/io/zipcoder/casino/Leviathan/Games/GameUtilities/DrawSingleDie.java 查看文件

6
 
6
 
7
 public class DrawSingleDie {
7
 public class DrawSingleDie {
8
 
8
 
9
-    public StringBuilder drawSingleDie(int x){
10
-            DiceBuilder die1 = new DiceBuilder(x-1);
9
+    public StringBuilder drawSingleDie(int x) {
10
+        DiceBuilder die1 = new DiceBuilder(x - 1);
11
 
11
 
12
-            List<Iterator<String>> dice = Arrays.asList(
13
-                    die1.iterator());
14
-            StringBuilder sb = new StringBuilder();
12
+        List<Iterator<String>> dice = Arrays.asList(
13
+                die1.iterator());
14
+        StringBuilder sb = new StringBuilder();
15
 
15
 
16
-            outer:
17
-            while (true) {
18
-                for (Iterator<String> iter : dice) {
19
-                    if (!iter.hasNext()) {
20
-                        break outer;
21
-                    }
16
+        outer:
17
+        while (true) {
18
+            for (Iterator<String> iter : dice) {
19
+                if (!iter.hasNext()) {
20
+                    break outer;
22
                 }
21
                 }
22
+            }
23
 
23
 
24
-                for (Iterator<String> iter : dice) {
25
-                    sb.append(iter.next()).append("   ");
26
-                }
27
-                sb.append("\r\n");
24
+            for (Iterator<String> iter : dice) {
25
+                sb.append(iter.next()).append("   ");
28
             }
26
             }
29
-            return sb;
27
+            sb.append("\r\n");
30
         }
28
         }
29
+        return sb;
31
     }
30
     }
31
+}
32
 
32
 

+ 7
- 7
src/main/java/io/zipcoder/casino/Leviathan/Games/GameUtilities/DrawYahtzeeDice.java 查看文件

6
 
6
 
7
 public class DrawYahtzeeDice {
7
 public class DrawYahtzeeDice {
8
 
8
 
9
-    public StringBuilder drawYahtzeeDice(int x, int y, int z, int a, int b){
10
-        DiceBuilder die1 = new DiceBuilder(x-1);
11
-        DiceBuilder die2 = new DiceBuilder(y-1);
12
-        DiceBuilder die3 = new DiceBuilder(z-1);
13
-        DiceBuilder die4 = new DiceBuilder(a-1);
14
-        DiceBuilder die5 = new DiceBuilder(b-1);
9
+    public StringBuilder drawYahtzeeDice(int... ints) {
10
+        DiceBuilder die1 = new DiceBuilder(ints[0] - 1);
11
+        DiceBuilder die2 = new DiceBuilder(ints[1] - 1);
12
+        DiceBuilder die3 = new DiceBuilder(ints[2] - 1);
13
+        DiceBuilder die4 = new DiceBuilder(ints[3] - 1);
14
+        DiceBuilder die5 = new DiceBuilder(ints[4] - 1);
15
 
15
 
16
         List<Iterator<String>> dice = Arrays.asList(
16
         List<Iterator<String>> dice = Arrays.asList(
17
                 die1.iterator(),
17
                 die1.iterator(),
35
             sb.append("\r\n");
35
             sb.append("\r\n");
36
         }
36
         }
37
 
37
 
38
-        return(sb);
38
+        return (sb);
39
     }
39
     }
40
 }
40
 }

+ 2
- 2
src/main/java/io/zipcoder/casino/Leviathan/Games/HigherDice.java 查看文件

30
             aConsole.getStringInput("Please roll your die");
30
             aConsole.getStringInput("Please roll your die");
31
             aDie.rollADice();
31
             aDie.rollADice();
32
             int player = aDie.getValue();
32
             int player = aDie.getValue();
33
-            aConsole.println("Your Roll:\n"+draw.drawSingleDie(player).toString());
33
+            aConsole.println("Your Roll:\n" + draw.drawSingleDie(player).toString());
34
             aDie.rollADice();
34
             aDie.rollADice();
35
             int croupier = aDie.getValue();
35
             int croupier = aDie.getValue();
36
-            aConsole.println("House Roll:\n"+draw.drawSingleDie(croupier).toString());
36
+            aConsole.println("House Roll:\n" + draw.drawSingleDie(croupier).toString());
37
             findWinner(player, croupier, bet);
37
             findWinner(player, croupier, bet);
38
             repeat();
38
             repeat();
39
         }
39
         }

+ 29
- 28
src/main/java/io/zipcoder/casino/Leviathan/Games/Yahtzee.java 查看文件

161
     Choose yahtzee field to score
161
     Choose yahtzee field to score
162
      */
162
      */
163
     public YahtzeeField chooseYahtzeeField() {
163
     public YahtzeeField chooseYahtzeeField() {
164
-        boolean inputValid;
165
-        boolean inputIsFree = false;
166
-        String userInput;
167
-        do {
164
+        String userInput = aConsole.getStringInput("Which field do you want to score?").toUpperCase();
165
+        boolean inputIsValid = isValidYahtzeeField(userInput);
166
+
167
+        while (!inputIsValid){
168
+            aConsole.println("please enter valid & free yahtzee field.");
168
             userInput = aConsole.getStringInput("Which field do you want to score?").toUpperCase();
169
             userInput = aConsole.getStringInput("Which field do you want to score?").toUpperCase();
169
-            inputValid = isYahtzeeField(userInput);
170
-            if (inputValid){
171
-                inputIsFree = isYahtzeeFieldFree(userInput);
172
-            }
173
-        } while(!inputValid && !inputIsFree);
170
+            inputIsValid = isValidYahtzeeField(userInput);
171
+        }
172
+
174
         return YahtzeeField.valueOf(userInput);
173
         return YahtzeeField.valueOf(userInput);
175
     }
174
     }
176
 
175
 
177
     /*
176
     /*
178
-    Check if yahtzee field is valid
177
+    Check if yahtzee field is valid and free
179
      */
178
      */
180
-    public boolean isYahtzeeField(String userInput) {
179
+    public boolean isValidYahtzeeField(String userInput) {
181
         for (YahtzeeField aYahtzeeField : YahtzeeField.values()) {
180
         for (YahtzeeField aYahtzeeField : YahtzeeField.values()) {
182
             if (aYahtzeeField.toString().equals(userInput)) {
181
             if (aYahtzeeField.toString().equals(userInput)) {
183
-                return true;
182
+                if(scoreSheet.get(YahtzeeField.valueOf(userInput)) == null){
183
+                    return true;
184
+                }
184
             }
185
             }
185
         }
186
         }
186
         return false;
187
         return false;
187
     }
188
     }
188
 
189
 
189
     /*
190
     /*
190
-    Check if yahtzee field is free
191
-     */
192
-    public boolean isYahtzeeFieldFree(String userInput) {
193
-        if(scoreSheet.get(YahtzeeField.valueOf(userInput)) != null){
194
-            return false;
195
-        }
196
-        return true;
197
-    }
198
-
199
-    /*
200
     Score dice
191
     Score dice
201
     */
192
     */
202
     public int scoreDice(YahtzeeField yahtzeeField) {
193
     public int scoreDice(YahtzeeField yahtzeeField) {
416
     Display dice
407
     Display dice
417
      */
408
      */
418
     public void printDice() {
409
     public void printDice() {
419
-        StringBuilder currentDice = new StringBuilder();
410
+//        StringBuilder currentDice = new StringBuilder();
411
+//        for (int i = 0; i < dice.length; i++) {
412
+//            currentDice.append(dice[i].getValue());
413
+//            if (i < dice.length - 1) {
414
+//                currentDice.append(", ");
415
+//            }
416
+//        }
417
+//        String currentDiceString = currentDice.toString();
418
+//        aConsole.println(currentDiceString);
419
+
420
+        int[] diceValues = new int[5];
420
         for (int i = 0; i < dice.length; i++) {
421
         for (int i = 0; i < dice.length; i++) {
421
-            currentDice.append(dice[i].getValue());
422
-            if (i < dice.length - 1) {
423
-                currentDice.append(", ");
424
-            }
422
+            diceValues[i] = (dice[i].getValue());
425
         }
423
         }
426
-        aConsole.println("current roll: " + currentDice.toString());
424
+
425
+        DrawYahtzeeDice diceDrawer = new DrawYahtzeeDice();
426
+        aConsole.println(diceDrawer.drawYahtzeeDice(diceValues).toString());
427
+        aConsole.println("    1           2           3           4           5    ");
427
     }
428
     }
428
 
429
 
429
     /*
430
     /*

+ 0
- 1
src/main/java/io/zipcoder/casino/Leviathan/Table.java 查看文件

54
                 aGame = new BlackJack(aPlayer);
54
                 aGame = new BlackJack(aPlayer);
55
                 aGame.playGame();
55
                 aGame.playGame();
56
                 played = true;
56
                 played = true;
57
-                aConsole.println("You Lose\n");
58
             } else if (choice == 4) //Yahtzee
57
             } else if (choice == 4) //Yahtzee
59
             {
58
             {
60
                 aGame = new Yahtzee(aPlayer);
59
                 aGame = new Yahtzee(aPlayer);

+ 63
- 4
src/test/java/io/zipcoder/casino/BlackJackTest.java 查看文件

1
 package io.zipcoder.casino;
1
 package io.zipcoder.casino;
2
 
2
 
3
+import io.zipcoder.casino.Leviathan.Games.BlackJack;
4
+import io.zipcoder.casino.Leviathan.Games.GameUtilities.Card;
5
+import io.zipcoder.casino.Leviathan.Games.GameUtilities.Rank;
6
+import io.zipcoder.casino.Leviathan.Games.GameUtilities.Suit;
7
+import io.zipcoder.casino.Leviathan.Player;
3
 import org.junit.Before;
8
 import org.junit.Before;
4
 import org.junit.Test;
9
 import org.junit.Test;
10
+
11
+import java.util.ArrayList;
12
+import java.util.List;
13
+
5
 import static org.junit.Assert.assertEquals;
14
 import static org.junit.Assert.assertEquals;
6
 
15
 
7
 public class BlackJackTest {
16
 public class BlackJackTest {
8
 
17
 
18
+    private BlackJack testBlackJack;
19
+
9
     @Before
20
     @Before
10
-    public void setUp()
11
-    {
21
+    public void setUp() {
22
+        Player p = new Player("name", 25, 25);
23
+        this.testBlackJack = new BlackJack(p);
12
     }
24
     }
13
 
25
 
14
     @Test
26
     @Test
15
-    public void testStartPlayerScore(){
27
+    public void testStartPlayerScore() {
16
         //Given
28
         //Given
17
 
29
 
18
         //When
30
         //When
23
     }
35
     }
24
 
36
 
25
     @Test
37
     @Test
26
-    public void testStartHouseScore(){
38
+    public void testStartHouseScore() {
27
         //Given
39
         //Given
28
 
40
 
29
         //When
41
         //When
33
         assertEquals(actual, expected);
45
         assertEquals(actual, expected);
34
     }
46
     }
35
 
47
 
48
+    @Test
49
+    public void testDrawNewHandHasTwoCards() {
50
+        int expected = 2;
51
+        int actual = testBlackJack.drawNewHand().size();
52
+
53
+        assertEquals(expected, actual);
54
+    }
55
+
56
+
57
+
58
+
59
+    @Test
60
+    public void testGetHandTotal() {
61
+        Card c1 = new Card(Rank.FOUR, Suit.CLUBS);
62
+        Card c2 = new Card(Rank.EIGHT, Suit.CLUBS);
63
+        Card c3 = new Card(Rank.TWO, Suit.CLUBS);
36
 
64
 
65
+        List<Card> hand = new ArrayList<>();
66
+        hand.add(c1);
67
+        hand.add(c2);
68
+        hand.add(c3);
37
 
69
 
70
+        int expected = 14;
71
+        int actual = testBlackJack.getHandTotal(hand);
72
+
73
+        assertEquals(expected, actual);
74
+    }
75
+
76
+
77
+    @Test
78
+    public void testHandToString() {
79
+        Card c1 = new Card(Rank.FOUR, Suit.CLUBS);
80
+        Card c2 = new Card(Rank.EIGHT, Suit.CLUBS);
81
+        Card c3 = new Card(Rank.TWO, Suit.CLUBS);
82
+
83
+        List<Card> hand = new ArrayList<>();
84
+        hand.add(c1);
85
+        hand.add(c2);
86
+        hand.add(c3);
87
+
88
+        String expected = "FOUR of CLUBS\n" +
89
+                "EIGHT of CLUBS\n" +
90
+                "TWO of CLUBS\n";
91
+        String actual = testBlackJack.handToString(hand);
92
+
93
+        System.out.println(actual);
94
+
95
+        assertEquals(expected, actual);
96
+    }
38
 }
97
 }

+ 15
- 5
src/test/java/io/zipcoder/casino/DiceTest.java 查看文件

34
         public void rollAllTest(){
34
         public void rollAllTest(){
35
             //Given
35
             //Given
36
             test.rollAll();
36
             test.rollAll();
37
-            int sum = 0;
38
 
37
 
39
-            for(int i = 0; i< test.getDice().length; i++){
40
-                sum+= test.getDice()[i].getValue();
41
-            }
42
             //When
38
             //When
39
+            int actual = test.getDice()[0].getValue();
40
+            int expected = 3;
43
 
41
 
44
-            int actual = sum;
42
+            //Result
43
+            assertEquals(actual, expected, 3);
44
+
45
+        }
46
+
47
+        @Test
48
+        public void sumAllTest(){
49
+            //Given
50
+            test.rollAll();
51
+
52
+            //When
53
+            int actual = test.sumAllDice();
45
             int expected = 17;
54
             int expected = 17;
55
+
46
             //Result
56
             //Result
47
             assertEquals(actual, expected, 13);
57
             assertEquals(actual, expected, 13);
48
 
58
 

+ 12
- 10
src/test/java/io/zipcoder/casino/YahtzeeTest.java 查看文件

11
 
11
 
12
     Yahtzee yahtzee;
12
     Yahtzee yahtzee;
13
     Player aPlayer;
13
     Player aPlayer;
14
-    Dice diceRoller;
15
-    Die[] dice;
16
-    Console console = new Console();
17
 
14
 
18
     public YahtzeeTest(){
15
     public YahtzeeTest(){
19
-        this.aPlayer = new Player("eric", 20, 18);
20
-        this.yahtzee = new Yahtzee(aPlayer);
16
+        aPlayer = new Player("eric", 20, 18);
17
+        yahtzee = new Yahtzee(aPlayer);
21
     }
18
     }
22
 
19
 
23
     @Test
20
     @Test
37
     }
34
     }
38
 
35
 
39
     @Test
36
     @Test
40
-    public void isYahtzeeFieldTest(){
37
+    public void isYahtzeeFieldValidTest(){
41
         //Actual
38
         //Actual
42
-        boolean actual = yahtzee.isYahtzeeField("ACES");
43
-        boolean actual2 = yahtzee.isYahtzeeField("ONES");
44
-        boolean actual3 = yahtzee.isYahtzeeField("TWOS");
45
-        boolean actual4 = yahtzee.isYahtzeeField("SEVENS");
39
+        boolean actual = yahtzee.isValidYahtzeeField("ACES");
40
+        boolean actual2 = yahtzee.isValidYahtzeeField("ONES");
41
+        boolean actual3 = yahtzee.isValidYahtzeeField("TWOS");
42
+        boolean actual4 = yahtzee.isValidYahtzeeField("SEVENS");
46
         //Expected
43
         //Expected
47
         boolean expected = true;
44
         boolean expected = true;
48
         boolean expected2 = false;
45
         boolean expected2 = false;
55
         assertEquals(actual4, expected4);
52
         assertEquals(actual4, expected4);
56
     }
53
     }
57
 
54
 
55
+    @Test
56
+    public void printDiceTest(){
57
+        yahtzee.printDice();
58
+    }
59
+
58
 
60
 
59
 
61
 
60
 
62