Quellcode durchsuchen

Merge branch 'dev' into snarkyTable

merge
Kris Blassingame vor 6 Jahren
Ursprung
Commit
bee038d598

+ 7
- 4
src/main/java/io/zipcoder/casino/Leviathan/Casino.java Datei anzeigen

@@ -2,13 +2,16 @@ package io.zipcoder.casino.Leviathan;
2 2
 
3 3
 
4 4
 public class Casino {
5
-    Console aConsole = new Console();
6
-    Player aPlayer;
7
-    Table aTable;
5
+    private Console aConsole = new Console();
6
+    private Player aPlayer;
8 7
 
9 8
     public void setaPlayer() {
10 9
         String name = aConsole.getStringInput("What is your name?");
11 10
         aPlayer = new Player(name.substring(0, 1).toUpperCase() + name.substring(1),0,aConsole.getIntInput("What is your age?"));
11
+        checkAge();
12
+    }
13
+
14
+    private void checkAge(){
12 15
         if (aPlayer.getAge() > 20) {
13 16
             aPlayer.setTotalChips(aConsole.getIntInput("How many chips would you like to purchase?"));
14 17
         } else {
@@ -17,7 +20,7 @@ public class Casino {
17 20
     }
18 21
 
19 22
     public void run() {
20
-        aTable = new Table(aPlayer);
23
+        Table aTable = new Table(aPlayer);
21 24
         aTable.startGame();
22 25
     }
23 26
 }

+ 0
- 1
src/main/java/io/zipcoder/casino/Leviathan/Games/GameUtilities/Die.java Datei anzeigen

@@ -8,7 +8,6 @@ public class Die {
8 8
 
9 9
     public int getValue() {
10 10
         return value;
11
-
12 11
     }
13 12
 
14 13
     public void rollADice() {

+ 264
- 189
src/main/java/io/zipcoder/casino/Leviathan/Games/Yahtzee.java Datei anzeigen

@@ -8,16 +8,21 @@ import java.util.*;
8 8
 
9 9
 public class Yahtzee extends DiceGame {
10 10
 
11
-    Player aPlayer;
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>();
19
-
11
+    //==================================================================================
12
+    // Fields
13
+    //==================================================================================
14
+    private Console aConsole = new Console();
15
+    private Player aPlayer;
16
+    private Map<YahtzeeField, Integer> scoreSheet = new LinkedHashMap<>();
17
+    private Dice diceRoller = new Dice(5);
18
+    private Die[] dice = diceRoller.rollAll();
19
+    private int[] diceValues = new int[5];
20
+    private int[] diceValueCounts = new int[6];
21
+    private boolean playAgain = true;
20 22
 
23
+    //==================================================================================
24
+    // Constructor
25
+    //==================================================================================
21 26
     public Yahtzee(Player aPlayer) {
22 27
         this.aPlayer = aPlayer;
23 28
     }
@@ -27,32 +32,23 @@ public class Yahtzee extends DiceGame {
27 32
     //==================================================================================
28 33
 
29 34
     public void playGame() {
30
-
31
-        aConsole.println("Welcome to Yahtzee " + aPlayer.getName());
32
-
33
-        boolean playAgain = true;
35
+        printWelcomeMessage();
34 36
         while (playAgain) {
35
-
36 37
             createBlankScoreSheet();
37 38
             printScoreSheet();
38
-
39
+            boolean scoreSheetFull = false;
39 40
             while (!scoreSheetFull) {
40 41
                 rollDice();
41
-                printDice(getDiceValues(this.dice));
42
-
42
+                printDice();
43 43
                 rollAgainLoop();
44
-
45
-                YahtzeeField fieldChoice = chooseYahtzeeField();
46
-                int score = scoreDice(fieldChoice);
47
-                updateScoreSheet(fieldChoice, score);
44
+                scoreRoll();
48 45
                 printScoreSheet();
49 46
                 scoreSheetFull = checkScoreSheetForCompletion();
50 47
             }
51
-
52 48
             int totalScore = getTotalScore();
53 49
             printEndOfGameMessage(totalScore);
50
+            playAgain = userInputYesNoToBoolean(userInputPlayAgain());
54 51
         }
55
-
56 52
     }
57 53
 
58 54
     //==================================================================================
@@ -60,18 +56,9 @@ public class Yahtzee extends DiceGame {
60 56
     //==================================================================================
61 57
 
62 58
     /*
63
-    Create blank score sheet
64
-     */
65
-    public void createBlankScoreSheet() {
66
-        for (YahtzeeField field : YahtzeeField.values()) {
67
-            scoreSheet.put(field, null);
68
-        }
69
-    }
70
-
71
-    /*
72 59
     Check score sheet for completion
73 60
      */
74
-    public boolean checkScoreSheetForCompletion() {
61
+    private boolean checkScoreSheetForCompletion() {
75 62
         for (Map.Entry<YahtzeeField, Integer> entry : scoreSheet.entrySet()) {
76 63
             Integer value = entry.getValue();
77 64
             if (value == null) {
@@ -82,19 +69,12 @@ public class Yahtzee extends DiceGame {
82 69
     }
83 70
 
84 71
     /*
85
-    Print score sheet
86
-     */
87
-    public void printScoreSheet() {
88
-        aConsole.println("Scoresheet: " + scoreSheet.toString());
89
-    }
90
-
91
-    /*
92 72
     Get total score
93 73
      */
94
-    public int getTotalScore() {
74
+    private int getTotalScore() {
95 75
         int sumOfUpperSection = getUpperSectionScore();
96 76
         int bonus = 0;
97
-        if (sumOfUpperSection >= 63){
77
+        if (sumOfUpperSection >= 63) {
98 78
             bonus = 35;
99 79
         }
100 80
         int sumOfLowerSection = getLowerSectionScore();
@@ -104,15 +84,15 @@ public class Yahtzee extends DiceGame {
104 84
     /*
105 85
     Get upper section score
106 86
      */
107
-    public int getUpperSectionScore(){
87
+    private int getUpperSectionScore() {
108 88
         int upperScore = 0;
109 89
         Iterator it = scoreSheet.entrySet().iterator();
110
-        while (it.hasNext()){
111
-            Map.Entry scoreEntry = (Map.Entry)it.next();
90
+        while (it.hasNext()) {
91
+            Map.Entry scoreEntry = (Map.Entry) it.next();
112 92
             if (scoreEntry.getKey() == YahtzeeField.ACES || scoreEntry.getKey() == YahtzeeField.TWOS ||
113 93
                     scoreEntry.getKey() == YahtzeeField.THREES || scoreEntry.getKey() == YahtzeeField.FOURS ||
114
-                    scoreEntry.getKey() == YahtzeeField.FIVES || scoreEntry.getKey() == YahtzeeField.SIXES){
115
-                upperScore += (int)(scoreEntry.getValue());
94
+                    scoreEntry.getKey() == YahtzeeField.FIVES || scoreEntry.getKey() == YahtzeeField.SIXES) {
95
+                upperScore += (int) (scoreEntry.getValue());
116 96
             }
117 97
         }
118 98
         return upperScore;
@@ -121,56 +101,44 @@ public class Yahtzee extends DiceGame {
121 101
     /*
122 102
     Get lower section score
123 103
      */
124
-    public int getLowerSectionScore(){
104
+    private int getLowerSectionScore() {
125 105
         int lowerScore = 0;
126 106
         Iterator it = scoreSheet.entrySet().iterator();
127
-        while (it.hasNext()){
128
-            Map.Entry scoreEntry = (Map.Entry)it.next();
107
+        while (it.hasNext()) {
108
+            Map.Entry scoreEntry = (Map.Entry) it.next();
129 109
             if (scoreEntry.getKey() == YahtzeeField.THREEOFAKIND || scoreEntry.getKey() == YahtzeeField.FOUROFAKIND ||
130 110
                     scoreEntry.getKey() == YahtzeeField.FULLHOUSE || scoreEntry.getKey() == YahtzeeField.SMSTRAIGHT ||
131 111
                     scoreEntry.getKey() == YahtzeeField.LGSTRAIGHT || scoreEntry.getKey() == YahtzeeField.YAHTZEE ||
132
-                    scoreEntry.getKey() == YahtzeeField.CHANCE){
133
-                lowerScore += (int)(scoreEntry.getValue());
112
+                    scoreEntry.getKey() == YahtzeeField.CHANCE) {
113
+                lowerScore += (int) (scoreEntry.getValue());
134 114
             }
135 115
         }
136 116
         return lowerScore;
137 117
     }
138 118
 
139
-     /*
140
-    Print end of game stats
141
-     */
142
-     public void printEndOfGameMessage(int totalScore){
143
-         aConsole.println("Game over!");
144
-         aConsole.println("Your total score is: " + totalScore);
145
-         if(aConsole.yesOrNo("Would you like to play again?").equalsIgnoreCase("no")){
146
-             playAgain= false;
147
-         }
148
-     }
149 119
 
150 120
     //==================================================================================
151 121
     // SCORING ROLL METHODS
152 122
     //==================================================================================
153 123
 
154 124
     /*
155
-    See fields and formula for score
125
+    Score roll
156 126
      */
157
-    public void printRules(){
158
-        aConsole.println("Roll 5 dice up to 3 times and try to get the highest score");
127
+    public void scoreRoll() {
128
+        YahtzeeField fieldChoice = chooseYahtzeeField();
129
+        int score = scoreDice(fieldChoice);
130
+        updateScoreSheet(fieldChoice, score);
159 131
     }
160 132
 
161 133
     /*
162 134
     Choose yahtzee field to score
163 135
      */
164 136
     public YahtzeeField chooseYahtzeeField() {
165
-        String userInput = aConsole.getStringInput("Which field do you want to score?").toUpperCase();
166
-        boolean inputIsValid = isValidYahtzeeField(userInput);
167
-
168
-        while (!inputIsValid){
169
-            aConsole.println("please enter valid & free yahtzee field.");
170
-            userInput = aConsole.getStringInput("Which field do you want to score?").toUpperCase();
171
-            inputIsValid = isValidYahtzeeField(userInput);
137
+        String userInput = userInputFieldToScore();
138
+        while (!isValidYahtzeeField(userInput)) {
139
+            printYahtzeeFieldErrorMessage();
140
+            userInput = userInputFieldToScore();
172 141
         }
173
-
174 142
         return YahtzeeField.valueOf(userInput);
175 143
     }
176 144
 
@@ -180,7 +148,7 @@ public class Yahtzee extends DiceGame {
180 148
     public boolean isValidYahtzeeField(String userInput) {
181 149
         for (YahtzeeField aYahtzeeField : YahtzeeField.values()) {
182 150
             if (aYahtzeeField.toString().equals(userInput)) {
183
-                if(scoreSheet.get(YahtzeeField.valueOf(userInput)) == null){
151
+                if (scoreSheet.get(YahtzeeField.valueOf(userInput)) == null) {
184 152
                     return true;
185 153
                 }
186 154
             }
@@ -191,10 +159,8 @@ public class Yahtzee extends DiceGame {
191 159
     /*
192 160
     Score dice
193 161
     */
194
-    public int scoreDice(YahtzeeField yahtzeeField) {
195
-
196
-        updateDiceValues();
197
-
162
+    private int scoreDice(YahtzeeField yahtzeeField) {
163
+        setDiceValueCounts();
198 164
         int score = 0;
199 165
         switch (yahtzeeField) {
200 166
             case ACES:
@@ -225,7 +191,7 @@ public class Yahtzee extends DiceGame {
225 191
                 score = scoreFullHouse(fullHouseCriteria());
226 192
                 break;
227 193
             case SMSTRAIGHT:
228
-                score = scoreSmStraight(smStraighCriteria());
194
+                score = scoreSmStraight(smStraightCriteria());
229 195
                 break;
230 196
             case LGSTRAIGHT:
231 197
                 score = scoreLgStraight(lgStraightCriteria());
@@ -241,30 +207,18 @@ public class Yahtzee extends DiceGame {
241 207
     }
242 208
 
243 209
     /*
244
-    Get count of each value in dice
245
-    */
246
-    public void updateDiceValues(){
247
-        resetDiceValues();
248
-        for (Die d : dice){
249
-            diceValueCounts[d.getValue()-1]++;
250
-        }
251
-    }
252
-
253
-    /*
254
-    Reset count of each value in dice
210
+    Score dice "count" fields: aces, twos, threes, fours, fives, or sixes
255 211
     */
256
-    public void resetDiceValues(){
257
-        for (int i=0; i < diceValueCounts.length; i++){
258
-            diceValueCounts[i] = 0;
259
-        }
212
+    public int scoreCountFields(int countField) {
213
+        return diceValueCounts[countField - 1] * countField;
260 214
     }
261 215
 
262 216
     /*
263
-    Check "of a kind" criteria is met
217
+    Check "of a kind" criteria is met: 3/4 of a kind, chance, yahtzee
264 218
     */
265
-    public boolean ofAKindCriteria(int ofAKind){
266
-        for (int count : diceValueCounts){
267
-            if (count >= ofAKind){
219
+    public boolean ofAKindCriteria(int ofAKind) {
220
+        for (int count : diceValueCounts) {
221
+            if (count >= ofAKind) {
268 222
                 return true;
269 223
             }
270 224
         }
@@ -272,12 +226,12 @@ public class Yahtzee extends DiceGame {
272 226
     }
273 227
 
274 228
     /*
275
-    Score dice "of a kind" fields: 3 of a kind, 4 of a kind, or chance
229
+    Score dice 3/4 of a kind, or chance
276 230
     */
277 231
     public int scoreOfAKind(boolean meetsOfAKindCriteria) {
278 232
         int score = 0;
279 233
         if (meetsOfAKindCriteria) {
280
-            for (Die d : dice){
234
+            for (Die d : dice) {
281 235
                 score += d.getValue();
282 236
             }
283 237
         }
@@ -287,9 +241,9 @@ public class Yahtzee extends DiceGame {
287 241
     /*
288 242
     Score yahtzee
289 243
      */
290
-    public int scoreYahtzee(boolean meetsOfAKindCriteria){
244
+    private int scoreYahtzee(boolean meetsOfAKindCriteria) {
291 245
         int score = 0;
292
-        if (meetsOfAKindCriteria){
246
+        if (meetsOfAKindCriteria) {
293 247
             score = 50;
294 248
         }
295 249
         return score;
@@ -298,14 +252,14 @@ public class Yahtzee extends DiceGame {
298 252
     /*
299 253
     Check Full House criteria is met
300 254
     */
301
-    public boolean fullHouseCriteria(){
255
+    public boolean fullHouseCriteria() {
302 256
         int i = 0;
303
-        for (int count : diceValueCounts){
304
-            if (count >= 2){
257
+        for (int count : diceValueCounts) {
258
+            if (count >= 2) {
305 259
                 i++;
306 260
             }
307 261
         }
308
-        if(i==2){
262
+        if (i == 2) {
309 263
             return true;
310 264
         }
311 265
         return false;
@@ -314,9 +268,9 @@ public class Yahtzee extends DiceGame {
314 268
     /*
315 269
     Score Full House
316 270
      */
317
-    public int scoreFullHouse(boolean meetsFullHouseCriteria){
271
+    public int scoreFullHouse(boolean meetsFullHouseCriteria) {
318 272
         int score = 0;
319
-        if (meetsFullHouseCriteria){
273
+        if (meetsFullHouseCriteria) {
320 274
             score = 25;
321 275
         }
322 276
         return score;
@@ -325,15 +279,15 @@ public class Yahtzee extends DiceGame {
325 279
     /*
326 280
     Check Small Straight criteria is met
327 281
     */
328
-    public boolean smStraighCriteria(){
282
+    public boolean smStraightCriteria() {
329 283
         boolean meetsCriteria = false;
330 284
         int i = 0;
331
-        for (int count : diceValueCounts){
332
-            if (count > 1){
285
+        for (int count : diceValueCounts) {
286
+            if (count > 1) {
333 287
                 i++;
334 288
             }
335 289
         }
336
-        if(i<=1){
290
+        if (i <= 1) {
337 291
             meetsCriteria = true;
338 292
         }
339 293
         return meetsCriteria;
@@ -342,9 +296,9 @@ public class Yahtzee extends DiceGame {
342 296
     /*
343 297
     Score SM Straight
344 298
      */
345
-    public int scoreSmStraight(boolean meetsSmStraightCriteria){
299
+    private int scoreSmStraight(boolean meetsSmStraightCriteria) {
346 300
         int score = 0;
347
-        if (meetsSmStraightCriteria){
301
+        if (meetsSmStraightCriteria) {
348 302
             score = 30;
349 303
         }
350 304
         return score;
@@ -353,15 +307,15 @@ public class Yahtzee extends DiceGame {
353 307
     /*
354 308
     Check Large Straight criteria is met
355 309
     */
356
-    public boolean lgStraightCriteria(){
310
+    public boolean lgStraightCriteria() {
357 311
         boolean meetsCriteria = false;
358 312
         int i = 0;
359
-        for (int count : diceValueCounts){
360
-            if (count > 1){
313
+        for (int count : diceValueCounts) {
314
+            if (count > 1) {
361 315
                 i++;
362 316
             }
363 317
         }
364
-        if(i<1){
318
+        if (i < 1) {
365 319
             meetsCriteria = true;
366 320
         }
367 321
         return meetsCriteria;
@@ -370,100 +324,60 @@ public class Yahtzee extends DiceGame {
370 324
     /*
371 325
     Score LG Straight
372 326
      */
373
-    public int scoreLgStraight(boolean meetsLgStraightCriteria){
327
+    public int scoreLgStraight(boolean meetsLgStraightCriteria) {
374 328
         int score = 0;
375
-        if (meetsLgStraightCriteria){
329
+        if (meetsLgStraightCriteria) {
376 330
             score = 40;
377 331
         }
378 332
         return score;
379 333
     }
380 334
 
381
-    /*
382
-    Score dice "count" fields: aces, twos, threes, fours, fives, or sixes
383
-    */
384
-    public int scoreCountFields(int countField) {
385
-        return diceValueCounts[countField-1] * countField;
386
-    }
387
-
388
-    /*
389
-    Update score sheet with scored value
390
-    */
391
-    public void updateScoreSheet(YahtzeeField yahtzeeField, int score) {
392
-        scoreSheet.put(yahtzeeField, score);
393
-    }
394
-
395 335
     //==================================================================================
396 336
     // ROLLING DICE METHODS
397 337
     //==================================================================================
398 338
 
399 339
     /*
400
-    Roll dice
401
-     */
402
-    public Die[] rollDice() {
403
-        dice = diceRoller.rollAll();
404
-        return dice;
405
-    }
406
-
407
-    /*
408
-    Ask user if they want to roll again
409
-     */
410
-    public String userInputRollAgain() {
411
-        return aConsole.yesOrNo("Roll again?").toUpperCase();
412
-    }
413
-
414
-    /*
415
-    Convert user's choice to roll again to boolean
416
-     */
417
-    public boolean userInputRollAgainBoolean(String userInputString) {
418
-        if (userInputString.equals("YES")) {
419
-            return true;
420
-        } else {
421
-            return false;
422
-        }
423
-    }
424
-
425
-    /*
426 340
     Allow the user to roll again up to 2 more times
427 341
      */
428 342
     public void rollAgainLoop() {
429
-
430
-        String rollAgainString = userInputRollAgain();
431
-        boolean rollAgain = userInputRollAgainBoolean(rollAgainString);
432
-
343
+        boolean rollAgain = userInputYesNoToBoolean(userInputRollAgain());
433 344
         int rollCounter = 1;
434 345
         while (rollAgain) {
435
-            //select the dice to keep
436
-            List<Integer> diceToRollAgainList = userInputChooseDice();
437
-            Integer[] diceToRollAgain = turnUserInputRollAgainToArray(diceToRollAgainList);
438
-            //roll remaining dice
439
-            rollSelectedDiceAgain(diceToRollAgain);
440
-            printDice(getDiceValues(this.dice));
346
+            rollAgain();
347
+            printDice();
441 348
             rollCounter++;
442 349
             if (rollCounter >= 3) {
443 350
                 break;
444 351
             }
445
-
446
-            rollAgainString = userInputRollAgain();
447
-            rollAgain = userInputRollAgainBoolean(rollAgainString);
352
+            rollAgain = userInputYesNoToBoolean(userInputRollAgain());
448 353
         }
449 354
     }
450 355
 
451 356
     /*
357
+    Roll again
358
+     */
359
+    public void rollAgain() {
360
+        List<Integer> diceToRollAgainList = userInputChooseDice();
361
+        Integer[] diceToRollAgain = turnRollAgainListToArray(diceToRollAgainList);
362
+        rollSelectedDiceAgain(diceToRollAgain);
363
+    }
364
+
365
+    /*
452 366
     Ask user to select which dice to roll again
453 367
      */
454 368
     public List<Integer> userInputChooseDice() {
455 369
         List<Integer> diceToRollAgainList = new ArrayList<Integer>();
456
-        boolean stillSelecting;
370
+        boolean stillSelecting = true;
371
+        String dicePosition;
457 372
         do {
458
-            String positionOfDiceToKeep = aConsole.getStringInput("Enter position of dice to roll again or enter to perform roll");
459
-            if (positionOfDiceToKeep.equals("")) {
373
+            dicePosition = userInputDiceToRollAgain();
374
+            if (dicePosition.equals("1") || dicePosition.equals("2") || dicePosition.equals("3") ||
375
+                    dicePosition.equals("4") || dicePosition.equals("5")){
376
+                diceToRollAgainList.add(Integer.parseInt(dicePosition));
377
+            } else if (dicePosition.equals("")){
460 378
                 stillSelecting = false;
461
-            } else if (Integer.parseInt(positionOfDiceToKeep) > 0 || Integer.parseInt(positionOfDiceToKeep) < 6){
462
-                diceToRollAgainList.add(Integer.parseInt(positionOfDiceToKeep));
463
-                stillSelecting = true;
464
-                aConsole.println("Enter a number between 1 and 5 or enter to roll");
465 379
             } else {
466
-                stillSelecting = false;
380
+                printDicePositionErrorMessage();
467 381
             }
468 382
         } while (stillSelecting);
469 383
         return diceToRollAgainList;
@@ -472,9 +386,9 @@ public class Yahtzee extends DiceGame {
472 386
     /*
473 387
     Turn user input of dice to roll again into an array
474 388
      */
475
-    public Integer[] turnUserInputRollAgainToArray(List<Integer> diceToRollAgainList) {
389
+    public Integer[] turnRollAgainListToArray(List<Integer> diceToRollAgainList) {
476 390
         Integer[] diceToRollAgainArray = null;
477
-        diceToRollAgainArray = diceToRollAgainList.toArray(new Integer[diceToRollAgainList.size()]);
391
+        diceToRollAgainArray = diceToRollAgainList.toArray(new Integer[0]);
478 392
         return diceToRollAgainArray;
479 393
     }
480 394
 
@@ -487,23 +401,184 @@ public class Yahtzee extends DiceGame {
487 401
         }
488 402
     }
489 403
 
404
+    //==================================================================================
405
+    // Get User Input
406
+    //==================================================================================
407
+
408
+    /*
409
+    Ask user if they want to roll again
410
+     */
411
+    public String userInputRollAgain() {
412
+        return aConsole.yesOrNo("Roll again?");
413
+    }
414
+
415
+    /*
416
+    Ask user the position of the dice that they want to roll again
417
+     */
418
+    public String userInputDiceToRollAgain() {
419
+     return aConsole.getStringInput("Enter position of dice to roll again or enter to perform roll");
420
+    }
421
+
422
+    /*
423
+    Ask user which field they want to score
424
+     */
425
+    public String userInputFieldToScore() {
426
+        return aConsole.getStringInput("Which field do you want to score?").toUpperCase();
427
+    }
428
+
429
+    /*
430
+    Ask user if they want to play again
431
+     */
432
+    public String userInputPlayAgain(){
433
+        return aConsole.yesOrNo("Would you like to play again?");
434
+    }
435
+
436
+    /*
437
+    Convert user input to boolean
438
+     */
439
+    public boolean userInputYesNoToBoolean(String userInputString) {
440
+        return (userInputString.toUpperCase().equals("YES"));
441
+    }
442
+
443
+    //==================================================================================
444
+    // Print Output
445
+    //==================================================================================
446
+
490 447
     /*
491 448
     Print dice
492 449
      */
493
-    public void printDice(int[] diceValues) {
450
+    public void printDice() {
494 451
         DrawYahtzeeDice diceDrawer = new DrawYahtzeeDice();
452
+        setDiceValues();
495 453
         aConsole.println(diceDrawer.drawYahtzeeDice(diceValues).toString());
496 454
         aConsole.println("    1           2           3           4           5    ");
497 455
     }
498 456
 
499 457
     /*
500
-    Create dice values array
458
+    Print welcome message
459
+     */
460
+    public void printWelcomeMessage() {
461
+        aConsole.println("Welcome to Yahtzee " + aPlayer.getName());
462
+        printRules();
463
+    }
464
+
465
+    /*
466
+    Print rules
467
+    */
468
+    public void printRules() {
469
+        aConsole.println("Roll 5 dice up to 3 times and try to get the highest score");
470
+    }
471
+
472
+    /*
473
+    Print score sheet
474
+     */
475
+    private void printScoreSheet() {
476
+        aConsole.println("Scoresheet: " + scoreSheet.toString());
477
+    }
478
+
479
+    /*
480
+    Print end of game stats
481
+    */
482
+    public void printEndOfGameMessage(int totalScore) {
483
+        aConsole.println("Game over!");
484
+        aConsole.println("Your total score is: " + totalScore);
485
+    }
486
+
487
+    /*
488
+    Print error when yahtzee field input is invalid or already full
501 489
      */
502
-    public int[] getDiceValues(Die[] dice){
503
-        int[] diceValues = new int[5];
490
+    public void printYahtzeeFieldErrorMessage() {
491
+        aConsole.println("please enter valid & free yahtzee field.");
492
+    }
493
+
494
+    /*
495
+    Print error when user enters dice to roll outside of 1-5 bounds
496
+     */
497
+    public void printDicePositionErrorMessage() {
498
+        aConsole.println("Enter a number between 1 and 5 or enter to roll");
499
+    }
500
+
501
+    //==================================================================================
502
+    // Getters and Setters (and Re-setters)
503
+    //==================================================================================
504
+
505
+    /*
506
+    Set dice (roll all dice)
507
+     */
508
+    public void rollDice() {
509
+        dice = diceRoller.rollAll();
510
+    }
511
+
512
+    /*
513
+    Get dice
514
+     */
515
+    public Die[] getDice(){
516
+        return this.dice;
517
+    }
518
+
519
+
520
+    /*
521
+    Set value count array
522
+    */
523
+    public void setDiceValueCounts() {
524
+        resetDiceValueCounts();
525
+        for (Die d : dice) {
526
+            diceValueCounts[d.getValue() - 1]++;
527
+        }
528
+    }
529
+
530
+    /*
531
+    Reset count of each value in dice
532
+    */
533
+    public void resetDiceValueCounts() {
534
+        for (int i = 0; i < diceValueCounts.length; i++) {
535
+            diceValueCounts[i] = 0;
536
+        }
537
+    }
538
+
539
+    /*
540
+    Get value count array
541
+     */
542
+    public int[] getDiceValueCounts() {
543
+        return this.diceValueCounts;
544
+    }
545
+
546
+    /*
547
+    Set dice values array
548
+     */
549
+    public void setDiceValues() {
504 550
         for (int i = 0; i < dice.length; i++) {
505 551
             diceValues[i] = (dice[i].getValue());
506 552
         }
507
-        return diceValues;
508 553
     }
509
-}
554
+
555
+    /*
556
+    Get dice values array
557
+     */
558
+    public int[] getDiceValues() {
559
+        return this.diceValues;
560
+    }
561
+
562
+    /*
563
+    Set score sheet with scored value
564
+    */
565
+    public void updateScoreSheet(YahtzeeField yahtzeeField, int score) {
566
+        scoreSheet.put(yahtzeeField, score);
567
+    }
568
+
569
+    /*
570
+    Reset score sheet to blank
571
+     */
572
+    public void createBlankScoreSheet() {
573
+        for (YahtzeeField field : YahtzeeField.values()) {
574
+            scoreSheet.put(field, null);
575
+        }
576
+    }
577
+
578
+    /*
579
+    Get score sheet
580
+     */
581
+    public Map<YahtzeeField, Integer> getScoreSheet() {
582
+        return this.scoreSheet;
583
+    }
584
+}

+ 34
- 51
src/test/java/io/zipcoder/casino/YahtzeeTest.java Datei anzeigen

@@ -19,73 +19,60 @@ public class YahtzeeTest {
19 19
     }
20 20
 
21 21
     @Test
22
-    public void printDiceTest(){
23
-        //Given
24
-        int[] diceValuesTest = {1,2,3,4,5};
25
-        //Actual
26
-        yahtzee.printDice(diceValuesTest);
27
-        //Expected
28
-            //Print dice with values from 1-5;
29
-        //Test
30
-            //Check console display for dice values 1-5;
22
+    public void getDiceValuesTest(){
23
+//        //Given
24
+//        Die testDie = new Die();
25
+//        testDie.rollADice();
26
+//        Die[] testDieArray = {testDie, testDie, testDie, testDie, testDie};
27
+//        int testDieValue = testDie.getValue();
28
+//        int[] expectedArray = {testDieValue, testDieValue, testDieValue, testDieValue, testDieValue};
29
+//        //Actual
30
+//        boolean actual = Arrays.equals(actualArray, expectedArray);
31
+//        //Expected
32
+//        boolean expected = true;
33
+//        //Test
34
+//        assertEquals(expected, actual);
31 35
     }
32 36
 
33 37
     @Test
34 38
     public void rollSelectedDiceAgainTest(){
35
-
36 39
         //Given
37
-        yahtzee.rollSelectedDiceAgain(1,3,5);
40
+
41
+        yahtzee.rollSelectedDiceAgain(1,2,3,4,5);
42
+        //Actual
43
+
38 44
     }
39 45
 
40 46
     @Test
41
-    public void turnUserInputRollAgainToArray(){
47
+    public void turnTurnRollAgainListToArray(){
42 48
         //Given
43 49
         List<Integer> testUserInputList = new ArrayList<Integer>();
44 50
         testUserInputList.add(1);
45 51
         testUserInputList.add(2);
46 52
         testUserInputList.add(3);
47 53
         //Actual
48
-        Integer[] actual = yahtzee.turnUserInputRollAgainToArray(testUserInputList);
54
+        Integer[] actual = yahtzee.turnRollAgainListToArray(testUserInputList);
49 55
         //Expected
50 56
         Integer[] expected = {1,2,3};
51 57
         //Test
52 58
         assertEquals(expected,actual);
53
-
54
-    }
55
-
56
-    @Test
57
-    public void userInputChooseDiceTest(){
58
-
59
-    }
60
-
61
-    @Test
62
-    public void rollAgainLoopTest(){
63
-
64 59
     }
65 60
 
66 61
     @Test
67
-    public void userInputRollAgainBooleanTest(){
62
+    public void userInputRollAgainBooleanTestYes(){
68 63
         //Actual
69
-        boolean actual = yahtzee.userInputRollAgainBoolean("YES");
64
+        boolean actual = yahtzee.userInputYesNoToBoolean("YES");
70 65
         //Expected
71 66
         boolean expected = true;
72 67
         assertEquals(expected, actual);
73 68
     }
74 69
 
75 70
     @Test
76
-    public void userInputRollAgainTest(){
77
-
78
-    }
79
-
80
-    @Test
81
-    public void rollDiceTest(){
82
-        //Given
83
-        Die[] dice = yahtzee.rollDice();
71
+    public void userInputRollAgainBooleanTestNo(){
84 72
         //Actual
85
-        boolean actual = dice instanceof Die[];
73
+        boolean actual = yahtzee.userInputYesNoToBoolean("NO");
86 74
         //Expected
87
-        boolean expected = true;
88
-        //Test
75
+        boolean expected = false;
89 76
         assertEquals(expected, actual);
90 77
     }
91 78
 
@@ -93,23 +80,19 @@ public class YahtzeeTest {
93 80
     public void isYahtzeeFieldValidTest(){
94 81
         //Actual
95 82
         boolean actual = yahtzee.isValidYahtzeeField("ACES");
96
-        boolean actual2 = yahtzee.isValidYahtzeeField("ONES");
97
-        boolean actual3 = yahtzee.isValidYahtzeeField("TWOS");
98
-        boolean actual4 = yahtzee.isValidYahtzeeField("SEVENS");
99 83
         //Expected
100 84
         boolean expected = true;
101
-        boolean expected2 = false;
102
-        boolean expected3 = true;
103
-        boolean expected4 = false;
104 85
         //Test
105 86
         assertEquals(actual, expected);
106
-        assertEquals(actual2, expected2);
107
-        assertEquals(actual3, expected3);
108
-        assertEquals(actual4, expected4);
109 87
     }
110 88
 
111
-
112
-
113
-
114
-}
115
-
89
+    @Test
90
+    public void isYahtzeeFieldValidTest2(){
91
+        //Actual
92
+        boolean actual = yahtzee.isValidYahtzeeField("ONES");
93
+        //Expected
94
+        boolean expected = false;
95
+        //Test
96
+        assertEquals(actual, expected);
97
+    }
98
+}