Kaynağa Gözat

Merge branch 'dev' into HigherCards

Aleena Rose-Mathew 6 yıl önce
ebeveyn
işleme
c0e5c0722c

+ 8
- 8
src/main/java/io/zipcoder/casino/Leviathan/Casino.java Dosyayı Görüntüle

@@ -6,21 +6,21 @@ public class Casino {
6 6
     Player aPlayer;
7 7
     Table aTable;
8 8
 
9
-    public void setaPlayer(){
10
-        String name= aConsole.getStringInput("What is your name?");
11
-        name = name.substring(0,1).toUpperCase() + name.substring(1);
12
-        int age= aConsole.getIntInput("What is your age?");
9
+    public void setaPlayer() {
10
+        String name = aConsole.getStringInput("What is your name?");
11
+        name = name.substring(0, 1).toUpperCase() + name.substring(1);
12
+        int age = aConsole.getIntInput("What is your age?");
13 13
         int chips = 0;
14
-        if(age>20) {
14
+        if (age > 20) {
15 15
             chips = aConsole.getIntInput("How many chips would you like to purchase?");
16
-        }else {
16
+        } else {
17 17
             aConsole.println("You are not old enough to gamble, so we won't be able to let you purchase any chips.");
18 18
         }
19 19
         aPlayer = new Player(name, chips, age);
20 20
     }
21 21
 
22
-    public void run(){
23
-        aTable= new Table(aPlayer);
22
+    public void run() {
23
+        aTable = new Table(aPlayer);
24 24
         aTable.startGame();
25 25
     }
26 26
 }

+ 22
- 11
src/main/java/io/zipcoder/casino/Leviathan/Console.java Dosyayı Görüntüle

@@ -1,22 +1,23 @@
1 1
 package io.zipcoder.casino.Leviathan;
2
+
2 3
 import java.util.Scanner;
3 4
 
4 5
 public class Console {
5 6
 
6
-    public  void print(String output, Object... args) {
7
+    public void print(String output, Object... args) {
7 8
         System.out.printf(output, args);
8 9
     }
9 10
 
10
-    public  void println(String output, Object... args) {
11
+    public void println(String output, Object... args) {
11 12
         print(output + "\n", args);
12 13
     }
13 14
 
14
-    public  String getStringInput(String prompt) {
15
+    public String getStringInput(String prompt) {
15 16
         Scanner scanner = new Scanner(System.in);
16 17
         println(prompt);
17 18
         String userInput = scanner.nextLine();
18 19
         String userInput2 = userInput.toLowerCase();
19
-        if(userInput2.equals("leave")){
20
+        if (userInput2.equals("leave")) {
20 21
             System.out.print("You abandon your chips and sprint out of the casino.");
21 22
             System.exit(0);
22 23
         }
@@ -24,15 +25,11 @@ public class Console {
24 25
     }
25 26
 
26 27
 
27
-    /*public static Integer getIntegerInput(String prompt) {
28
-    return null;
29
-    }*/
30
-
31
-    public  Integer getIntInput(String prompt) {
28
+    public Integer getIntInput(String prompt) {
32 29
         int b = 0;
33
-        boolean good =false;
30
+        boolean good = false;
34 31
         println(prompt);
35
-        while(good == false) {
32
+        while (good == false) {
36 33
             Scanner scannerB = new Scanner(System.in);
37 34
             if (scannerB.hasNextInt()) {
38 35
                 b = scannerB.nextInt();
@@ -44,6 +41,20 @@ public class Console {
44 41
         return b;
45 42
     }
46 43
 
44
+    public String yesOrNo(String prompt){
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
+        }
55
+        }
56
+        return correct;
57
+    }
47 58
 
48 59
 
49 60
 }

+ 8
- 9
src/main/java/io/zipcoder/casino/Leviathan/Games/GameUtilities/Dice.java Dosyayı Görüntüle

@@ -7,26 +7,25 @@ public class Dice {
7 7
     public Dice(int numberOfDice) {
8 8
 
9 9
 
10
-     dice = new Die[numberOfDice];
11
-     for (int i = 0; i < dice.length; i++){
12
-         dice[i] = new Die();
13
-     }
14
-}
10
+        dice = new Die[numberOfDice];
11
+        for (int i = 0; i < dice.length; i++) {
12
+            dice[i] = new Die();
13
+        }
14
+    }
15 15
 
16
-    public Die[] getDice(){
16
+    public Die[] getDice() {
17 17
         return dice;
18 18
     }
19 19
 
20 20
     public Die[] rollAll() {
21 21
 
22 22
 
23
-        for (int i = 0; i < dice.length; i++){
24
-             dice[i].rollADice();
23
+        for (int i = 0; i < dice.length; i++) {
24
+            dice[i].rollADice();
25 25
 
26 26
         }
27 27
         return dice;
28 28
     }
29 29
 
30 30
 
31
-
32 31
 }

+ 4
- 0
src/main/java/io/zipcoder/casino/Leviathan/Games/GameUtilities/DiceBuilder.java Dosyayı Görüntüle

@@ -0,0 +1,4 @@
1
+package io.zipcoder.casino.Leviathan.Games.GameUtilities;
2
+
3
+public class DiceBuilder {
4
+}

+ 4
- 4
src/main/java/io/zipcoder/casino/Leviathan/Games/GameUtilities/Die.java Dosyayı Görüntüle

@@ -3,16 +3,16 @@ package io.zipcoder.casino.Leviathan.Games.GameUtilities;
3 3
 public class Die {
4 4
     int value;
5 5
 
6
-    public void setValue(){
6
+    public void setValue() {
7 7
     }
8 8
 
9
-    public int getValue(){
9
+    public int getValue() {
10 10
         return value;
11 11
 
12 12
     }
13 13
 
14
-    public  void rollADice() {
15
-        int rolled = (int)(Math.random()* 6)+ 1;
14
+    public void rollADice() {
15
+        int rolled = (int) (Math.random() * 6) + 1;
16 16
         value = rolled;
17 17
     }
18 18
 

+ 2
- 1
src/main/java/io/zipcoder/casino/Leviathan/Games/GameUtilities/YahtzeeField.java Dosyayı Görüntüle

@@ -12,5 +12,6 @@ public enum YahtzeeField {
12 12
     FULLHOUSE,
13 13
     SMSTRAIGHT,
14 14
     LGSTRAIGHT,
15
-    YAHTZEE;
15
+    YAHTZEE,
16
+    CHANCE;
16 17
 }

+ 35
- 26
src/main/java/io/zipcoder/casino/Leviathan/Games/HigherDice.java Dosyayı Görüntüle

@@ -1,7 +1,9 @@
1 1
 package io.zipcoder.casino.Leviathan.Games;
2
+
3
+import io.zipcoder.casino.Leviathan.Console;
2 4
 import io.zipcoder.casino.Leviathan.Games.GameUtilities.Die;
3
-import io.zipcoder.casino.Leviathan.Interfaces.*;
4
-import io.zipcoder.casino.Leviathan.*;
5
+import io.zipcoder.casino.Leviathan.Interfaces.Gambling;
6
+import io.zipcoder.casino.Leviathan.Player;
5 7
 
6 8
 
7 9
 public class HigherDice extends DiceGame implements Gambling {
@@ -20,47 +22,54 @@ public class HigherDice extends DiceGame implements Gambling {
20 22
     public void playGame() {
21 23
         aConsole.print("Welcome to HigherDice!\nWe will both roll a die, and the higher number wins the wager.\nThe House wins on ties\n");
22 24
 
23
-        while(playAgain == true){
24
-
25
-        bet = wageMoney();
26
-        aConsole.getStringInput("Please roll your die");
27
-        aDie.rollADice();
28
-        int player = aDie.getValue();
29
-        aConsole.println("You rolled a " + player);
30
-        aDie.rollADice();
31
-        int croupier = aDie.getValue();
32
-        aConsole.println("The House rolled a " + croupier);
33
-        findWinner(player, croupier, bet);
25
+        while (playAgain == true) {
34 26
 
27
+            bet = wageMoney();
28
+            aConsole.getStringInput("Please roll your die");
29
+            aDie.rollADice();
30
+            int player = aDie.getValue();
31
+            aConsole.println("You rolled a " + player);
32
+            aDie.rollADice();
33
+            int croupier = aDie.getValue();
34
+            aConsole.println("The House rolled a " + croupier);
35
+            findWinner(player, croupier, bet);
36
+            repeat();
37
+        }
38
+    }
35 39
 
36
-        if((aPlayer.getTotalChips() == 0) )
37
-            {
38
-                aConsole.println("You are out of chips. You may no longer play");
39
-                playAgain = false;
40
-            } else if(aConsole.getStringInput("Would you like to play again?").equalsIgnoreCase("no")){
40
+    public void repeat() {
41
+        if ((aPlayer.getTotalChips() == 0)) {
42
+            aConsole.println("You are out of chips. You may no longer play");
43
+            playAgain = false;
44
+        } else if (aConsole.yesOrNo("Would you like to play again?").equalsIgnoreCase("no")) {
41 45
             playAgain = false;
42 46
         }
43
-        }
44
-        }
47
+    }
45 48
 
46
-    public int findWinner(int player, int croupier, int wageAmount) {
49
+    public void findWinner(int player, int croupier, int wageAmount) {
47 50
 
48 51
         if (player > croupier) {
49 52
             aPlayer.setTotalChips(aPlayer.getTotalChips() + wageAmount);
50
-            aConsole.println("You win! Your current chip total is: "+ aPlayer.getTotalChips());
53
+            int[] change = {aPlayer.getTally()[0] + 1, aPlayer.getTally()[1]};
54
+            aPlayer.setTally(change);
55
+            aConsole.println("You win! Your current chip total is: " + aPlayer.getTotalChips());
56
+            aConsole.println("Your current Win/Loss Ratio is " + aPlayer.getTally()[0] + "-" + aPlayer.getTally()[1] + "\n");
51 57
         } else {
52 58
             aPlayer.setTotalChips(aPlayer.getTotalChips() - wageAmount);
53
-            aConsole.println("You lose! Your current chip total is: "+ aPlayer.getTotalChips());
59
+            int[] change = {aPlayer.getTally()[0], aPlayer.getTally()[1] + 1};
60
+            aPlayer.setTally(change);
61
+            aConsole.println("You lose! Your current chip total is: " + aPlayer.getTotalChips());
62
+            aConsole.println("Your current Win/Loss Ratio is " + aPlayer.getTally()[0] + "-" + aPlayer.getTally()[1] + "\n");
63
+
54 64
         }
55
-        return aPlayer.getTotalChips();
56 65
     }
57 66
 
58 67
     public int wageMoney() {
59 68
 
60 69
         do {
61 70
             bet = aConsole.getIntInput("How much would you like to bet? You can only bet what you currently have.\n" +
62
-                    "Current chips= " + aPlayer.getTotalChips()+ "\n");
63
-        }while(bet > aPlayer.getTotalChips() && bet < 0);
71
+                    "Current chips= " + aPlayer.getTotalChips() + "\n");
72
+        } while (bet > aPlayer.getTotalChips() && bet < 0);
64 73
 
65 74
         return bet;
66 75
     }

+ 323
- 44
src/main/java/io/zipcoder/casino/Leviathan/Games/Yahtzee.java Dosyayı Görüntüle

@@ -1,29 +1,25 @@
1 1
 package io.zipcoder.casino.Leviathan.Games;
2
+
2 3
 import io.zipcoder.casino.Leviathan.Games.GameUtilities.*;
3 4
 import io.zipcoder.casino.Leviathan.*;
5
+
4 6
 import java.util.*;
5 7
 
6 8
 
7 9
 public class Yahtzee extends DiceGame {
8 10
 
9 11
     Player aPlayer;
10
-    Dice diceRoller;
11
-    Die[] dice;
12
-    Console console;
13
-    Map<YahtzeeField, Integer> scoreSheet;
12
+    Dice diceRoller = new Dice(5);
13
+    Die[] dice = diceRoller.rollAll();
14
+    int[] diceValueCounts = new int[6];
15
+    Console aConsole = new Console();
16
+    boolean playAgain;
17
+    boolean scoreSheetFull = false;
18
+    Map<YahtzeeField, Integer> scoreSheet = new LinkedHashMap<YahtzeeField, Integer>();
14 19
 
15 20
 
16 21
     public Yahtzee(Player aPlayer) {
17 22
         this.aPlayer = aPlayer;
18
-        diceRoller = new Dice(5);
19
-        scoreSheet = new LinkedHashMap<YahtzeeField, Integer>();
20
-        dice = diceRoller.rollAll();
21
-    }
22
-
23
-    public static void main(String[] args) {
24
-        Player aPlayer = new Player("eric", 20, 18);
25
-        Yahtzee yahtzee = new Yahtzee(aPlayer);
26
-        yahtzee.playGame();
27 23
     }
28 24
 
29 25
     //==================================================================================
@@ -32,19 +28,28 @@ public class Yahtzee extends DiceGame {
32 28
 
33 29
     public void playGame() {
34 30
 
35
-        createBlankScoreSheet();
36
-        printScoreSheet();
31
+        aConsole.println("Welcome to Yahtzee " + aPlayer.getName());
32
+
33
+        boolean playAgain = true;
34
+        while (playAgain) {
37 35
 
38
-        boolean scoreSheetFull = checkScoreSheetForCompletion();
36
+            createBlankScoreSheet();
37
+            printScoreSheet();
39 38
 
40
-        while (!scoreSheetFull) {
41
-            rollDice();
39
+            while (!scoreSheetFull) {
40
+                rollDice();
42 41
 
43
-            rollAgainLoop();
42
+                rollAgainLoop();
44 43
 
45
-            YahtzeeField fieldChoice = chooseYahtzeeField();
46
-            int score = scoreDice(fieldChoice);
47
-            updateScoreSheet(fieldChoice, score);
44
+                YahtzeeField fieldChoice = chooseYahtzeeField();
45
+                int score = scoreDice(fieldChoice);
46
+                updateScoreSheet(fieldChoice, score);
47
+                printScoreSheet();
48
+                scoreSheetFull = checkScoreSheetForCompletion();
49
+            }
50
+
51
+            int totalScore = getTotalScore();
52
+            printEndOfGameMessage(totalScore);
48 53
         }
49 54
 
50 55
     }
@@ -56,8 +61,8 @@ public class Yahtzee extends DiceGame {
56 61
     /*
57 62
     Create blank score sheet
58 63
      */
59
-    public void createBlankScoreSheet(){
60
-        for (YahtzeeField field : YahtzeeField.values()){
64
+    public void createBlankScoreSheet() {
65
+        for (YahtzeeField field : YahtzeeField.values()) {
61 66
             scoreSheet.put(field, null);
62 67
         }
63 68
     }
@@ -65,25 +70,93 @@ public class Yahtzee extends DiceGame {
65 70
     /*
66 71
     Check score sheet for completion
67 72
      */
68
-    public boolean checkScoreSheetForCompletion(){
69
-
70
-        for(Map.Entry<YahtzeeField, Integer> entry : scoreSheet.entrySet()){
73
+    public boolean checkScoreSheetForCompletion() {
74
+        for (Map.Entry<YahtzeeField, Integer> entry : scoreSheet.entrySet()) {
71 75
             Integer value = entry.getValue();
72
-            if (value == null){
76
+            if (value == null) {
73 77
                 return false;
74 78
             }
75 79
         }
76
-
77 80
         return true;
78 81
     }
79 82
 
80 83
     /*
81 84
     Print score sheet
82 85
      */
83
-    public void printScoreSheet(){
84
-        console.println("Scoresheet: " + scoreSheet.toString());
86
+    public void printScoreSheet() {
87
+        aConsole.println("Scoresheet: " + scoreSheet.toString());
88
+    }
89
+
90
+    /*
91
+    Get total score
92
+     */
93
+    public int getTotalScore() {
94
+
95
+        int sumOfUpperSection = getUpperSectionScore();
96
+
97
+        int bonus = 0;
98
+        if (sumOfUpperSection >= 63){
99
+            bonus = 35;
100
+        }
101
+
102
+        int sumOfLowerSection = getLowerSectionScore();
103
+
104
+        return sumOfUpperSection + bonus + sumOfLowerSection;
105
+    }
106
+
107
+    /*
108
+    Get upper section score
109
+     */
110
+    public int getUpperSectionScore(){
111
+        int upperScore = 0;
112
+        Iterator it = scoreSheet.entrySet().iterator();
113
+        while (it.hasNext()){
114
+            Map.Entry scoreEntry = (Map.Entry)it.next();
115
+            if (scoreEntry.getKey() == YahtzeeField.ACES ||
116
+                    scoreEntry.getKey() == YahtzeeField.TWOS ||
117
+                    scoreEntry.getKey() == YahtzeeField.THREES ||
118
+                    scoreEntry.getKey() == YahtzeeField.FOURS ||
119
+                    scoreEntry.getKey() == YahtzeeField.FIVES ||
120
+                    scoreEntry.getKey() == YahtzeeField.SIXES){
121
+                upperScore += (int)(scoreEntry.getValue());
122
+            }
123
+        }
124
+        return upperScore;
125
+    }
126
+
127
+    /*
128
+    Get lower section score
129
+     */
130
+    public int getLowerSectionScore(){
131
+        int lowerScore = 0;
132
+        Iterator it = scoreSheet.entrySet().iterator();
133
+        while (it.hasNext()){
134
+            Map.Entry scoreEntry = (Map.Entry)it.next();
135
+            if (scoreEntry.getKey() == YahtzeeField.THREEOFAKIND ||
136
+                    scoreEntry.getKey() == YahtzeeField.FOUROFAKIND ||
137
+                    scoreEntry.getKey() == YahtzeeField.FULLHOUSE ||
138
+                    scoreEntry.getKey() == YahtzeeField.SMSTRAIGHT ||
139
+                    scoreEntry.getKey() == YahtzeeField.LGSTRAIGHT ||
140
+                    scoreEntry.getKey() == YahtzeeField.YAHTZEE ||
141
+                    scoreEntry.getKey() == YahtzeeField.CHANCE){
142
+                lowerScore += (int)(scoreEntry.getValue());
143
+            }
144
+        }
145
+        return lowerScore;
85 146
     }
86 147
 
148
+     /*
149
+    Print end of game stats
150
+     */
151
+     public void printEndOfGameMessage(int totalScore){
152
+         aConsole.println("Game over!");
153
+         aConsole.println("Your total score is: " + totalScore);
154
+
155
+         if(aConsole.yesOrNo("Would you like to play again?").equalsIgnoreCase("no")){
156
+             playAgain= false;
157
+         }
158
+     }
159
+
87 160
     //==================================================================================
88 161
     // SCORING ROLL METHODS
89 162
     //==================================================================================
@@ -91,20 +164,225 @@ public class Yahtzee extends DiceGame {
91 164
     /*
92 165
     See fields and formula for score
93 166
      */
167
+    public void printRules(){
168
+        aConsole.println("Roll 5 dice up to 3 times and try to get the highest score");
169
+
170
+    }
94 171
 
172
+    /*
173
+    Choose yahtzee field to score
174
+     */
95 175
     public YahtzeeField chooseYahtzeeField() {
96 176
         String userInput = aConsole.getStringInput
97 177
                 ("Which field do you want to score?").toUpperCase();
98
-        return YahtzeeField.ACES;
178
+        return YahtzeeField.valueOf(userInput);
99 179
     }
100 180
 
181
+    /*
182
+    Score dice
183
+    */
101 184
     public int scoreDice(YahtzeeField yahtzeeField) {
102
-        //take in field and dice array and give a score
103
-        return -1;
185
+
186
+        updateDiceValues();
187
+
188
+        int score = 0;
189
+        switch (yahtzeeField) {
190
+            case ACES:
191
+                score = scoreCountFields(1);
192
+                break;
193
+            case TWOS:
194
+                score = scoreCountFields(2);
195
+                break;
196
+            case THREES:
197
+                score = scoreCountFields(3);
198
+                break;
199
+            case FOURS:
200
+                score = scoreCountFields(4);
201
+                break;
202
+            case FIVES:
203
+                score = scoreCountFields(5);
204
+                break;
205
+            case SIXES:
206
+                score = scoreCountFields(6);
207
+                break;
208
+            case THREEOFAKIND:
209
+                score = scoreOfAKind(ofAKindCriteria(3));
210
+                break;
211
+            case FOUROFAKIND:
212
+                score = scoreOfAKind(ofAKindCriteria(4));
213
+                break;
214
+            case FULLHOUSE:
215
+                score = scoreFullHouse(fullHouseCriteria());
216
+                break;
217
+            case SMSTRAIGHT:
218
+                score = scoreSmStraight(smStraighCriteria());
219
+                break;
220
+            case LGSTRAIGHT:
221
+                score = scoreLgStraight(lgStraightCriteria());
222
+                break;
223
+            case YAHTZEE:
224
+                score = scoreYahtzee(ofAKindCriteria(5));
225
+                break;
226
+            case CHANCE:
227
+                score = scoreOfAKind(ofAKindCriteria(1));
228
+                break;
229
+        }
230
+        return score;
104 231
     }
105 232
 
233
+    /*
234
+    Get count of each value in dice
235
+    */
236
+    public void updateDiceValues(){
237
+        resetDiceValues();
238
+        for (Die d : dice){
239
+            diceValueCounts[d.getValue()-1]++;
240
+        }
241
+    }
242
+
243
+    /*
244
+    Reset count of each value in dice
245
+    */
246
+    public void resetDiceValues(){
247
+        for (int i=0; i < diceValueCounts.length; i++){
248
+            diceValueCounts[i] = 0;
249
+        }
250
+    }
251
+
252
+    /*
253
+    Check "of a kind" criteria is met
254
+    */
255
+    public boolean ofAKindCriteria(int ofAKind){
256
+        boolean meetsCriteria = false;
257
+        for (int count : diceValueCounts){
258
+            if (count >= ofAKind){
259
+                meetsCriteria = true;
260
+                return meetsCriteria;
261
+            }
262
+        }
263
+        return meetsCriteria;
264
+    }
265
+
266
+    /*
267
+    Score dice "of a kind" fields: 3 of a kind, 4 of a kind, or chance
268
+    */
269
+    public int scoreOfAKind(boolean meetsOfAKindCriteria) {
270
+        int score = 0;
271
+        if (meetsOfAKindCriteria) {
272
+            for (Die d : dice){
273
+                score += d.getValue();
274
+            }
275
+        }
276
+        return score;
277
+    }
278
+
279
+    /*
280
+    Score yahtzee
281
+     */
282
+    public int scoreYahtzee(boolean meetsOfAKindCriteria){
283
+        int score = 0;
284
+        if (meetsOfAKindCriteria){
285
+            score = 50;
286
+        }
287
+        return score;
288
+    }
289
+
290
+    /*
291
+    Check Full House criteria is met
292
+    */
293
+    public boolean fullHouseCriteria(){
294
+        boolean meetsCriteria = false;
295
+        int i = 0;
296
+        for (int count : diceValueCounts){
297
+            if (count >= 2){
298
+                i++;
299
+            }
300
+        }
301
+        if(i==2){
302
+            meetsCriteria = true;
303
+        }
304
+        return meetsCriteria;
305
+    }
306
+
307
+    /*
308
+    Score Full House
309
+     */
310
+    public int scoreFullHouse(boolean meetsFullHouseCriteria){
311
+        int score = 0;
312
+        if (meetsFullHouseCriteria){
313
+            score = 25;
314
+        }
315
+        return score;
316
+    }
317
+
318
+    /*
319
+    Check Small Straight criteria is met
320
+    */
321
+    public boolean smStraighCriteria(){
322
+        boolean meetsCriteria = false;
323
+        int i = 0;
324
+        for (int count : diceValueCounts){
325
+            if (count > 1){
326
+                i++;
327
+            }
328
+        }
329
+        if(i<=1){
330
+            meetsCriteria = true;
331
+        }
332
+        return meetsCriteria;
333
+    }
334
+
335
+    /*
336
+    Score SM Straight
337
+     */
338
+    public int scoreSmStraight(boolean meetsSmStraightCriteria){
339
+        int score = 0;
340
+        if (meetsSmStraightCriteria){
341
+            score = 30;
342
+        }
343
+        return score;
344
+    }
345
+
346
+    /*
347
+    Check Large Straight criteria is met
348
+    */
349
+    public boolean lgStraightCriteria(){
350
+        boolean meetsCriteria = false;
351
+        int i = 0;
352
+        for (int count : diceValueCounts){
353
+            if (count > 1){
354
+                i++;
355
+            }
356
+        }
357
+        if(i<1){
358
+            meetsCriteria = true;
359
+        }
360
+        return meetsCriteria;
361
+    }
362
+
363
+    /*
364
+    Score LG Straight
365
+     */
366
+    public int scoreLgStraight(boolean meetsLgStraightCriteria){
367
+        int score = 0;
368
+        if (meetsLgStraightCriteria){
369
+            score = 40;
370
+        }
371
+        return score;
372
+    }
373
+
374
+    /*
375
+    Score dice "count" fields: aces, twos, threes, fours, fives, or sixes
376
+    */
377
+    public int scoreCountFields(int countField) {
378
+        return diceValueCounts[countField-1] * countField;
379
+    }
380
+
381
+    /*
382
+    Update score sheet with scored value
383
+    */
106 384
     public void updateScoreSheet(YahtzeeField yahtzeeField, int score) {
107
-        //Take in field and score and update sheet
385
+        scoreSheet.put(yahtzeeField, score);
108 386
     }
109 387
 
110 388
     //==================================================================================
@@ -114,7 +392,7 @@ public class Yahtzee extends DiceGame {
114 392
     /*
115 393
     Roll dice
116 394
      */
117
-    public void rollDice(){
395
+    public void rollDice() {
118 396
         dice = diceRoller.rollAll();
119 397
         printDice();
120 398
     }
@@ -130,20 +408,20 @@ public class Yahtzee extends DiceGame {
130 408
                 currentDice.append(", ");
131 409
             }
132 410
         }
133
-        console.println("current roll: " + currentDice.toString());
411
+        aConsole.println("current roll: " + currentDice.toString());
134 412
     }
135 413
 
136 414
     /*
137 415
     Ask user if they want to roll again
138 416
      */
139 417
     public String userInputRollAgain() {
140
-        return aConsole.getStringInput ("Roll again?").toUpperCase();
418
+        return aConsole.yesOrNo("Roll again?").toUpperCase();
141 419
     }
142 420
 
143 421
     /*
144 422
     Convert user's choice to roll again to boolean
145 423
      */
146
-    public boolean userInputRollAgainBoolean(String userInputString){
424
+    public boolean userInputRollAgainBoolean(String userInputString) {
147 425
         boolean rollAgain;
148 426
         if (userInputString.equals("YES")) {
149 427
             rollAgain = true;
@@ -169,7 +447,9 @@ public class Yahtzee extends DiceGame {
169 447
             rollSelectedDiceAgain(diceToRollAgain);
170 448
             printDice();
171 449
             rollCounter++;
172
-            if (rollCounter >=3){break;}
450
+            if (rollCounter >= 3) {
451
+                break;
452
+            }
173 453
 
174 454
             rollAgainString = userInputRollAgain();
175 455
             rollAgain = userInputRollAgainBoolean(rollAgainString);
@@ -179,8 +459,8 @@ public class Yahtzee extends DiceGame {
179 459
     /*
180 460
     Ask user to select which dice to roll again
181 461
      */
182
-    public Integer[] userInputChooseDice(){
183
-        Integer [] diceToRollAgainArray = null;
462
+    public Integer[] userInputChooseDice() {
463
+        Integer[] diceToRollAgainArray = null;
184 464
         ArrayList<Integer> diceToRollAgainList = new ArrayList<Integer>();
185 465
         boolean stillSelecting = true;
186 466
         while (stillSelecting) {
@@ -200,10 +480,9 @@ public class Yahtzee extends DiceGame {
200 480
      */
201 481
     public void rollSelectedDiceAgain(Integer... diceToRollAgain) {
202 482
         for (int i = 0; i < diceToRollAgain.length; i++) {
203
-            dice[diceToRollAgain[i]-1].rollADice();
483
+            dice[diceToRollAgain[i] - 1].rollADice();
204 484
         }
205 485
     }
206 486
 
207 487
 
208
-
209 488
 }

+ 20
- 11
src/main/java/io/zipcoder/casino/Leviathan/Player.java Dosyayı Görüntüle

@@ -3,38 +3,47 @@ package io.zipcoder.casino.Leviathan;
3 3
 public class Player {
4 4
     String name;
5 5
     Integer totalChips;
6
-    int[] tally = {0,0};
6
+    int[] tally = {0, 0};
7 7
     int age;
8 8
 
9
-    public Player(String name, Integer totalChips, int age){
9
+    public Player(String name, Integer totalChips, int age) {
10 10
         this.name = name;
11 11
         this.totalChips = totalChips;
12 12
         this.age = age;
13 13
 
14 14
     }
15 15
 
16
-    public void setName(String name){
16
+    public String getName() {
17
+        return this.name;
18
+    }
19
+
20
+    public void setName(String name) {
17 21
         this.name = name;
18 22
     }
19 23
 
20
-    public String getName(){
21
-        return this.name;
24
+    public Integer getTotalChips() {
25
+        return this.totalChips;
22 26
     }
23 27
 
24
-    public void setTotalChips(Integer totalChips){
28
+    public void setTotalChips(Integer totalChips) {
25 29
         this.totalChips = totalChips;
26 30
     }
27 31
 
28
-    public Integer getTotalChips(){
29
-        return this.totalChips;
32
+    public Integer getAge() {
33
+        return this.age;
30 34
     }
31 35
 
32
-    public void setAge(Integer age){
36
+    public void setAge(Integer age) {
33 37
         this.age = age;
34 38
     }
35 39
 
36
-    public Integer getAge(){
37
-        return this.age;
40
+    public int[] getTally() {
41
+        return this.tally;
38 42
     }
39 43
 
44
+    public void setTally(int[] tally) {
45
+        this.tally = tally;
46
+    }
47
+
48
+
40 49
 }

+ 28
- 21
src/main/java/io/zipcoder/casino/Leviathan/Table.java Dosyayı Görüntüle

@@ -1,6 +1,10 @@
1 1
 package io.zipcoder.casino.Leviathan;
2
-import io.zipcoder.casino.Leviathan.Interfaces.*;
3
-import io.zipcoder.casino.Leviathan.Games.*;
2
+
3
+import io.zipcoder.casino.Leviathan.Games.BlackJack;
4
+import io.zipcoder.casino.Leviathan.Games.HigherCards;
5
+import io.zipcoder.casino.Leviathan.Games.HigherDice;
6
+import io.zipcoder.casino.Leviathan.Games.Yahtzee;
7
+import io.zipcoder.casino.Leviathan.Interfaces.Game;
4 8
 
5 9
 
6 10
 public class Table {
@@ -16,20 +20,20 @@ public class Table {
16 20
     public void startGame() {
17 21
         boolean play = true;
18 22
         boolean played = false;
19
-        aConsole.println("Welcome to The Leviathan Casino " + aPlayer.getName()+ "!");
23
+        aConsole.println("Welcome to The Leviathan Casino " + aPlayer.getName() + "!");
20 24
 
21
-        while(play == true) {
22
-            if(played == true){
23
-                aConsole.println("Welcome back to the selection table "+ aPlayer.getName());
24
-                aConsole.println("Your current chip total is "+ aPlayer.getTotalChips());
25
+        while (play == true) {
26
+            if (played == true) {
27
+                aConsole.println("Welcome back to the selection table " + aPlayer.getName());
28
+                aConsole.println("Your current chip total is " + aPlayer.getTotalChips());
25 29
             }
26 30
             int choice = 0;
27 31
             aConsole.println("Choose a game to play:");
28
-            if(aPlayer.getTotalChips()>0) {
32
+            if (aPlayer.getTotalChips() > 0) {
29 33
                 aConsole.println("1.Higher Dice\n2.Higher Card\n3.Black Jack\n4.Yahtzee\n5.Buy more Chips\n6.Cash Out\n\n");
30 34
                 choice = aConsole.getIntInput("Enter your choice");
31
-            } else{
32
-                while(choice < 4) {
35
+            } else {
36
+                while (choice < 4) {
33 37
                     aConsole.println("It looks like you don't have any chips. You'll need chips to play any gambling games.");
34 38
                     aConsole.println("4.Yahtzee\n5.Buy more Chips\n6.Cash Out\n\n");
35 39
                     choice = aConsole.getIntInput("Enter your choice");
@@ -50,7 +54,7 @@ public class Table {
50 54
                 aGame = new BlackJack(aPlayer);
51 55
                 aGame.playGame();
52 56
                 played = true;
53
-                aConsole.println("You Lose");
57
+                aConsole.println("You Lose\n");
54 58
             } else if (choice == 4) //Yahtzee
55 59
             {
56 60
                 aGame = new Yahtzee(aPlayer);
@@ -58,17 +62,20 @@ public class Table {
58 62
                 played = true;
59 63
             } else if (choice == 5) // Chips
60 64
             {
61
-                aPlayer.setTotalChips(aPlayer.getTotalChips() + aConsole.getIntInput("How many more chips would you like?"));
62
-                aConsole.println("Great! Here you go! Good Luck!");
63
-            }else if (choice == 6) // Cash Out
64
-                {
65
-                     play = false;
66
-                    aConsole.println("Thank you for coming to the Leviathan Casino "+ aPlayer.getName());
67
-                    aConsole.println("You've cashed out "+ aPlayer.getTotalChips()+ " chips");
68
-                    aConsole.println("Please come again!");
65
+                if (aPlayer.getAge() > 20) {
66
+                    aPlayer.setTotalChips(aPlayer.getTotalChips() + aConsole.getIntInput("How many more chips would you like?"));
67
+                    aConsole.println("Great! Here you go! Good Luck!\n");
68
+                } else {
69
+                    aConsole.println("You are not old enough to gamble, so we won't be able to let you purchase any chips.\n");
69 70
                 }
70
-                else{
71
-                aConsole.println("That is not an option "+ aPlayer.getName()+"... Do better");
71
+            } else if (choice == 6) // Cash Out
72
+            {
73
+                play = false;
74
+                aConsole.println("Thank you for coming to the Leviathan Casino " + aPlayer.getName());
75
+                aConsole.println("You've cashed out " + aPlayer.getTotalChips() + " chips");
76
+                aConsole.println("Please come again!");
77
+            } else {
78
+                aConsole.println("That is not an option " + aPlayer.getName() + "... Do better\n");
72 79
             }
73 80
         }
74 81
 

+ 2
- 2
src/test/java/io/zipcoder/casino/HigherDiceTest.java Dosyayı Görüntüle

@@ -32,10 +32,10 @@ public class HigherDiceTest {
32 32
     @Test
33 33
     public void findWinnerTest(){
34 34
         //Given
35
-
35
+        test.findWinner(10,2,500);
36 36
         //When
37 37
         int expected=2500;
38
-        int actual=test.findWinner(10,2,500);
38
+        int actual=aPlayer.getTotalChips();
39 39
 
40 40
 
41 41
         //Result