Browse Source

Merge branch 'master' of laurengreen/ZCW-OOP-Casino into working

jonathan-hinds 6 years ago
parent
commit
729c8cb79c

+ 1
- 1
.gitignore View File

@@ -10,7 +10,7 @@ local.properties
10 10
 .loadpath
11 11
 .recommenders
12 12
 .DS_Store
13
-
13
+ f4be1dfe4483806d9dd9cf3b6546e184f84a5f1a
14 14
 
15 15
 # External tool builders
16 16
 .externalToolBuilders/

+ 1
- 0
src/main/java/io/zipcoder/casino/CardGame.java View File

@@ -47,6 +47,7 @@ public abstract class CardGame {
47 47
         }
48 48
     }
49 49
 
50
+
50 51
     public int getAnte(){
51 52
         return ante;
52 53
     }

+ 8
- 1
src/main/java/io/zipcoder/casino/Casino.java View File

@@ -72,7 +72,14 @@ public class Casino {
72 72
 
73 73
                 case 1:
74 74
                     Game yahtzee = new Yahtzee(player);
75
-                    yahtzee.startGame();
75
+                    ((Yahtzee) yahtzee).startGame();
76
+                    int betAmount = console.getIntFromUser("How much would you like to bet on this game?");
77
+                    ((Yahtzee) yahtzee).setBid(betAmount);
78
+                    ((Yahtzee) yahtzee).bet(betAmount);
79
+                    yahtzee.startRound();
80
+                    Printer.printMessage("You scored " + ((Yahtzee) yahtzee).getDicePlayer().getScoreSheet().getTotalScore() + " points.");
81
+                    ((Yahtzee) yahtzee).payout();
82
+                    Printer.printMessage(((Yahtzee) yahtzee).getDicePlayer().balanceAtEnd() + "\n");
76 83
                     break;
77 84
 
78 85
                 case 5:

+ 8
- 5
src/main/java/io/zipcoder/casino/DicePlayer.java View File

@@ -19,19 +19,22 @@ public class DicePlayer {
19 19
         return cup;
20 20
     }
21 21
 
22
-    public void printCup() {
22
+    public String cupToString() {
23
+
24
+        String cupString = "";
25
+
23 26
         for(Dice d : cup) {
24
-            System.out.print(d.getValue() + " ");
27
+            cupString += (d.getValue() + " ");
25 28
         }
26
-        System.out.println();
29
+        return cupString;
27 30
     }
28 31
 
29 32
     public Player getPlayer() {
30 33
         return player;
31 34
     }
32 35
 
33
-    public void printBalanceAtEnd() {
34
-        System.out.println("Your total balance is now: $" + getPlayer().getCurrentBalance());
36
+    public String balanceAtEnd() {
37
+        return "Your total balance is now: $" + getPlayer().getCurrentBalance();
35 38
     }
36 39
 }
37 40
 

+ 65
- 117
src/main/java/io/zipcoder/casino/ScoreSheet.java View File

@@ -2,6 +2,8 @@
2 2
 
3 3
 package io.zipcoder.casino;
4 4
 
5
+import com.sun.tools.javac.code.Attribute;
6
+
5 7
 import java.util.*;
6 8
 
7 9
 public class ScoreSheet {
@@ -19,96 +21,52 @@ public class ScoreSheet {
19 21
     public int getTotalScore() {
20 22
 
21 23
         int totalScore = 0;
22
-        totalScore = (totalScore + getScore(ScoreSheet.ROW.ACES) + getScore(ScoreSheet.ROW.TWOS) + getScore(ScoreSheet.ROW.THREES) + getScore(ScoreSheet.ROW.FOURS) + getScore(ScoreSheet.ROW.FIVES) + getScore(ScoreSheet.ROW.SIXES));
23
-        if (totalScore >= 63) {
24
+        int upperScore = 0;
25
+        int lowerScore = 0;
26
+        try {
27
+            upperScore = getScore(ScoreSheet.ROW.ACES) + getScore(ScoreSheet.ROW.TWOS) + getScore(ScoreSheet.ROW.THREES) + getScore(ScoreSheet.ROW.FOURS) + getScore(ScoreSheet.ROW.FIVES) + getScore(ScoreSheet.ROW.SIXES);
28
+        } catch (NullPointerException e){
29
+            upperScore = 0;
30
+        }
31
+        try {
32
+            lowerScore = getScore(ScoreSheet.ROW.THREEOFAKIND) + getScore(ScoreSheet.ROW.FOUROFAKIND) + getScore(ScoreSheet.ROW.FULLHOUSE) + getScore(ScoreSheet.ROW.SMALLSTRAIGHT) + getScore(ScoreSheet.ROW.LARGESTRAIGHT) + getScore(ScoreSheet.ROW.YAHTZEE) + getScore(ScoreSheet.ROW.CHANCE);
33
+        } catch (NullPointerException e){
34
+            lowerScore = 0;
35
+        }
36
+        if (upperScore >= 63) {
24 37
             totalScore += 35;
25 38
         }
26
-        totalScore = (totalScore + getScore(ScoreSheet.ROW.THREEOFAKIND) + getScore(ScoreSheet.ROW.FOUROFAKIND) + getScore(ScoreSheet.ROW.FULLHOUSE) + getScore(ScoreSheet.ROW.SMALLSTRAIGHT) + getScore(ScoreSheet.ROW.LARGESTRAIGHT) + getScore(ScoreSheet.ROW.YAHTZEE) + getScore(ScoreSheet.ROW.CHANCE));
27
-
39
+        totalScore = totalScore + upperScore + lowerScore;
28 40
         return totalScore;
29 41
     }
30 42
 
31
-
32
-    public void printScoreCard(){
33
-        System.out.print(String.format("%-35s","1. Aces: Totals all Ones"));
34
-        if(getScore(ScoreSheet.ROW.ACES) != null) {
35
-            System.out.println("** " + getScore(ScoreSheet.ROW.ACES) + " **");
36
-        } else {
37
-            System.out.println("** open **");
38
-        }
39
-        System.out.print(String.format("%-35s","2. Twos: Totals all Twos"));
40
-        if(getScore(ScoreSheet.ROW.TWOS) != null) {
41
-            System.out.println("** " + getScore(ScoreSheet.ROW.TWOS) + " **");
42
-        } else {
43
-            System.out.println("** open **");
44
-        }
45
-        System.out.print(String.format("%-35s", "3. Threes: Totals all Threes"));
46
-        if(getScore(ScoreSheet.ROW.THREES) != null) {
47
-            System.out.println("** " + getScore(ScoreSheet.ROW.THREES) + " **");
48
-        } else {
49
-            System.out.println("** open **");
50
-        }
51
-        System.out.print(String.format("%-35s", "4. Fours: Totals all Fours"));
52
-        if(getScore(ScoreSheet.ROW.FOURS) != null) {
53
-            System.out.println("** " + getScore(ScoreSheet.ROW.FOURS) + " **");
43
+    public String rowToString(ROW row, String description) {
44
+        String rowInfo = String.format("%-35s",description);
45
+        if(getScore(row) != null) {
46
+            rowInfo += "** " + getScore(row) + " **\n";
54 47
         } else {
55
-            System.out.println("** open **");
48
+            rowInfo += "** open **\n";
56 49
         }
57
-        System.out.print(String.format("%-35s", "5. Fives: Totals all Fives"));
58
-        if(getScore(ScoreSheet.ROW.FIVES) != null) {
59
-            System.out.println("** " + getScore(ScoreSheet.ROW.FIVES) + " **");
60
-        } else {
61
-            System.out.println("** open **");
62
-        }
63
-        System.out.print(String.format("%-35s", "6. Sixes: Totals all Sixes"));
64
-        if(getScore(ScoreSheet.ROW.SIXES) != null) {
65
-            System.out.println("** " + getScore(ScoreSheet.ROW.SIXES) + " **");
66
-        } else {
67
-            System.out.println("** open **");
68
-        }
69
-        System.out.print(String.format("%-35s", "7. 3 of a Kind"));
70
-        if(getScore(ScoreSheet.ROW.THREEOFAKIND) != null) {
71
-            System.out.println("** " + getScore(ScoreSheet.ROW.THREEOFAKIND) + " **");
72
-        } else {
73
-            System.out.println("** open **");
74
-        }
75
-        System.out.print(String.format("%-35s", "8. 4 of a Kind"));
76
-        if(getScore(ScoreSheet.ROW.FOUROFAKIND) != null) {
77
-            System.out.println("** " + getScore(ScoreSheet.ROW.FOUROFAKIND) + " **");
78
-        } else {
79
-            System.out.println("** open **");
80
-        }
81
-        System.out.print(String.format("%-35s", "9. Full House"));
82
-        if(getScore(ScoreSheet.ROW.FULLHOUSE) != null) {
83
-            System.out.println("** " + getScore(ScoreSheet.ROW.FULLHOUSE) + " **");
84
-        } else {
85
-            System.out.println("** open **");
86
-        }
87
-        System.out.print(String.format("%-35s","10. Small Straight: Sequence of 4"));
88
-        if(getScore(ScoreSheet.ROW.SMALLSTRAIGHT) != null) {
89
-            System.out.println("** " + getScore(ScoreSheet.ROW.SMALLSTRAIGHT) + " **");
90
-        } else {
91
-            System.out.println("** open **");
92
-        }
93
-        System.out.print(String.format("%-35s","11. Large Striaght: Sequence of 5"));
94
-        if(getScore(ScoreSheet.ROW.LARGESTRAIGHT) != null) {
95
-            System.out.println("** " + getScore(ScoreSheet.ROW.LARGESTRAIGHT) + " **");
96
-        } else {
97
-            System.out.println("** open **");
98
-        }
99
-        System.out.print(String.format("%-35s","12. Yahtzee: 5 of a Kind "));
100
-        if(getScore(ScoreSheet.ROW.YAHTZEE) != null) {
101
-            System.out.println("** " + getScore(ScoreSheet.ROW.YAHTZEE) + " **");
102
-        } else {
103
-            System.out.println("** open **");
104
-        }
105
-        System.out.print(String.format("%-35s", "13. Chance: Sum of Dice"));
106
-        if(getScore(ScoreSheet.ROW.CHANCE) != null) {
107
-            System.out.println("** " + getScore(ScoreSheet.ROW.CHANCE) + " **");
108
-        } else {
109
-            System.out.println("** open **");
110
-        }
111
-        System.out.println();
50
+        return rowInfo;
51
+    }
52
+
53
+    public String scoreCardToString(){
54
+        String scoreCard = rowToString(ScoreSheet.ROW.ACES, "1. Aces: Totals all Ones") +
55
+        rowToString(ScoreSheet.ROW.TWOS, "2. Twos: Totals all Twos") +
56
+        rowToString(ScoreSheet.ROW.THREES, "3. Threes: Totals all Threes") +
57
+        rowToString(ScoreSheet.ROW.FOURS, "4. Fours: Totals all Fours") +
58
+        rowToString(ScoreSheet.ROW.FIVES, "5. Fives: Totals all Fives") +
59
+        rowToString(ScoreSheet.ROW.SIXES, "6. Sixes: Totals all Sixes") +
60
+        rowToString(ScoreSheet.ROW.THREEOFAKIND, "7. 3 of a Kind") +
61
+        rowToString(ScoreSheet.ROW.FOUROFAKIND, "8. 4 of a Kind") +
62
+        rowToString(ScoreSheet.ROW.FULLHOUSE, "9. Full House") +
63
+        rowToString(ScoreSheet.ROW.SMALLSTRAIGHT, "10. Small Straight: Sequence of 4") +
64
+        rowToString(ScoreSheet.ROW.LARGESTRAIGHT, "11. Large Striaght: Sequence of 5") +
65
+        rowToString(ScoreSheet.ROW.YAHTZEE, "12. Yahtzee: 5 of a Kind") +
66
+        rowToString(ScoreSheet.ROW.CHANCE,  "13. Chance: Sum of Dice");
67
+
68
+        return scoreCard;
69
+
112 70
     }
113 71
 
114 72
     public void setRow(ROW row, Dice[] cup){
@@ -139,46 +97,22 @@ public class ScoreSheet {
139 97
                     scores.put(ROW.SIXES, scoreNumbers(numbers, 6));
140 98
                     break;
141 99
                 case THREEOFAKIND:
142
-                    if (checkOfaKind(numbers, 3)) {
143
-                        scores.put(ROW.THREEOFAKIND, scoreTotalDice(numbers));
144
-                    } else {
145
-                        scores.put(ROW.THREEOFAKIND, 0);
146
-                    }
100
+                    scoreRow(checkOfaKind(numbers,3), ROW.THREEOFAKIND, scoreTotalDice(numbers));
147 101
                     break;
148 102
                 case FOUROFAKIND:
149
-                    if (checkOfaKind(numbers, 4)) {
150
-                        scores.put(ROW.FOUROFAKIND, scoreTotalDice(numbers));
151
-                    } else {
152
-                        scores.put(ROW.FOUROFAKIND, 0);
153
-                    }
103
+                    scoreRow(checkOfaKind(numbers, 4), ROW.FOUROFAKIND, scoreTotalDice(numbers));
154 104
                     break;
155 105
                 case FULLHOUSE:
156
-                    if (checkOfaKind(numbers, 5) || checkFullHouse(numbers)) {
157
-                        scores.put(ROW.FULLHOUSE, 25);
158
-                    } else {
159
-                        scores.put(ROW.FULLHOUSE, 0);
160
-                    }
106
+                    scoreRow(checkOfaKind(numbers, 5), ROW.FULLHOUSE, 25);
161 107
                     break;
162 108
                 case SMALLSTRAIGHT:
163
-                    if (checkSmallStraight(numbers)) {
164
-                        scores.put(ROW.SMALLSTRAIGHT, 30);
165
-                    } else {
166
-                        scores.put(ROW.SMALLSTRAIGHT, 0);
167
-                    }
109
+                    scoreRow(checkSmallStraight(numbers), ROW.SMALLSTRAIGHT, 30);
168 110
                     break;
169 111
                 case LARGESTRAIGHT:
170
-                    if (checkLargeStraight(numbers)) {
171
-                        scores.put(ROW.LARGESTRAIGHT, 40);
172
-                    } else {
173
-                        scores.put(ROW.LARGESTRAIGHT, 0);
174
-                    }
112
+                    scoreRow(checkLargeStraight(numbers), ROW.LARGESTRAIGHT, 40);
175 113
                     break;
176 114
                 case YAHTZEE:
177
-                    if (checkOfaKind(numbers, 5)) {
178
-                        scores.put(ROW.YAHTZEE, 50);
179
-                    } else {
180
-                        scores.put(ROW.YAHTZEE, 0);
181
-                    }
115
+                    scoreRow(checkOfaKind(numbers, 5), ROW.YAHTZEE, 50);
182 116
                     break;
183 117
                 case CHANCE:
184 118
                     scores.put(ROW.CHANCE, scoreTotalDice(numbers));
@@ -186,14 +120,28 @@ public class ScoreSheet {
186 120
             }
187 121
         }
188 122
 
123
+        public void scoreRow(boolean check, ROW row, int score) {
124
+            if (check) {
125
+                scores.put(row, score);
126
+            } else {
127
+                scores.put(row, 0);
128
+            }
129
+        }
189 130
 
190 131
 
191 132
     public boolean checkFullHouse(ArrayList<Integer> numbers) {
192 133
 
193
-        boolean check2 = checkOfaKind(numbers, 2);
194
-        boolean check3 = checkOfaKind(numbers, 3);
134
+        boolean fullHouse = false;
135
+        boolean checkYahtzee = checkOfaKind(numbers, 5);
136
+        if(checkYahtzee) {
137
+            return true;
138
+        } else {
139
+            boolean check2 = checkOfaKind(numbers, 2);
140
+            boolean check3 = checkOfaKind(numbers, 3);
141
+            fullHouse = (check2 && check3);
142
+        }
195 143
 
196
-        return (check2 && check3);
144
+        return fullHouse;
197 145
     }
198 146
 
199 147
     public boolean checkSmallStraight(ArrayList<Integer> numbers) {
@@ -275,6 +223,6 @@ public class ScoreSheet {
275 223
     }
276 224
 
277 225
     public Integer getScore(ROW row) {
278
-        return this.scores.get(row);
226
+        return scores.get(row);
279 227
     }
280 228
 }

+ 0
- 5
src/main/java/io/zipcoder/casino/SlotMachine.java View File

@@ -25,11 +25,6 @@ public class SlotMachine implements Game, Gamble {
25 25
     }
26 26
 
27 27
     @Override
28
-    public void quit() {
29
-
30
-    }
31
-
32
-    @Override
33 28
     public void startGame() {
34 29
         Printer.printMessage("You are all set to play a new slot game..zrrr..! \n");
35 30
         try {

+ 0
- 1
src/main/java/io/zipcoder/casino/War.java View File

@@ -114,7 +114,6 @@ public class War extends CardGame implements Gamble, Game {
114 114
         }
115 115
     }
116 116
 
117
-    public void startGame() {
118 117
         Printer.welcomeTo("War");
119 118
         super.chooseStatingPlayer();
120 119
         payAnte();

+ 52
- 79
src/main/java/io/zipcoder/casino/Yahtzee.java View File

@@ -6,11 +6,13 @@ import java.util.Scanner;
6 6
 public class Yahtzee extends DiceGame implements Game, Gamble {
7 7
 
8 8
     DicePlayer dicePlayer;
9
-    private Scanner scanner = new Scanner(System.in);
9
+    Console console = new Console();
10 10
     int betAmount = 0;
11
+    int totalScore = 0;
11 12
 
12 13
     public Yahtzee(Player player) {
13 14
         this.dicePlayer = new DicePlayer(player);
15
+        this.totalScore = this.dicePlayer.getScoreSheet().getTotalScore();
14 16
     }
15 17
 
16 18
     public int getBid() {
@@ -21,7 +23,7 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
21 23
         this.betAmount = bid;
22 24
     }
23 25
 
24
-    public void createGame() {
26
+    public void startGame() {
25 27
         Dice dice1 = new Dice();
26 28
         Dice dice2 = new Dice();
27 29
         Dice dice3 = new Dice();
@@ -33,72 +35,55 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
33 35
         dicePlayer.getCup()[2] = dice3;
34 36
         dicePlayer.getCup()[3] = dice4;
35 37
         dicePlayer.getCup()[4] = dice5;
36
-    }
37
-
38
-    public void startGame() {
39
-        createGame();
40
-
41
-        System.out.println("How much would you like to bet on this game?");
42
-        int betAmount = scanner.nextInt();
43
-        setBid(betAmount);
44
-        bet(betAmount);
45
-
46
-        startRound();
47
-        System.out.println("You scored " + dicePlayer.getScoreSheet().getTotalScore() + " points.");
48
-        payout();
49
-        dicePlayer.printBalanceAtEnd();
50
-        System.out.println();
51 38
 
52 39
     }
53 40
 
41
+    @Override
54 42
     public void startRound() {
55
-
56 43
         for (int i = 0; i < ScoreSheet.getSize(); i++) {
57
-            for (Dice d : dicePlayer.getCup()) {
58
-                d.roll();
59
-            }
60
-            System.out.println("\nYou rolled:");
61
-            dicePlayer.printCup();
62
-            System.out.println();
44
+            rollAll();
45
+            for(int j = 0; j < 2; j++) {
46
+                int rollChoice = console.getIntFromUser("Would you like to:\n1. Roll all dice again.\n2. Roll some dice again.\n3. Stop rolling and score.\nNumber of Selection: ");
47
+                String diceToRoll = "";
48
+                if(rollChoice == 2) {
49
+                    diceToRoll = console.getLineFromUser("Which numbers would you like to reroll? List the numbers separated by spaces.");
50
+                }
51
+                rollOptions(rollChoice, diceToRoll); }
63 52
 
64
-            roundRoutine();
65
-            recordingScore();
66
-        }
53
+            boolean validEntry = false;
54
+            ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
55
+            while (!validEntry) {
56
+                Printer.printMessage(dicePlayer.getScoreSheet().scoreCardToString());
67 57
 
68
-    }
58
+                int rowChoice = console.getIntFromUser("Which row would you like to apply your turn to on the scoresheet?.\n" +
59
+                        "Remember you can only use each row once!");
69 60
 
70
-    public void roundRoutine() {
61
+                row = selectingRow(rowChoice);
62
+                validEntry = checkEmptyRow(row);
63
+            }
64
+            dicePlayer.getScoreSheet().setRow(row, dicePlayer.getCup());
65
+            Printer.printMessage("\n" + dicePlayer.getScoreSheet().scoreCardToString());
66
+        }
71 67
 
72
-        giveOptions();
73
-        giveOptions();
68
+    }
74 69
 
70
+    public void rollAll() {
71
+        for (Dice d : dicePlayer.getCup()) {
72
+            d.roll();
73
+        }
74
+        Printer.printMessage("\nYou rolled:\n" + dicePlayer.cupToString() + "\n");
75 75
     }
76 76
 
77
-    public void giveOptions() {
78
-        int choice = 0;
79
-        System.out.print("Would you like to:\n1. Roll all dice again.\n2. Roll some dice again.\n3. Stop rolling and score.\nNumber of Selection: ");
80 77
 
81
-        Scanner in = new Scanner(System.in);
82
-        choice = in.nextInt();
78
+    public void rollOptions(int choice, String diceToRoll) {
83 79
 
84 80
         switch (choice) {
85 81
             case 1:
86
-                for (Dice d : dicePlayer.getCup()) {
87
-                    d.roll();
88
-                }
89
-                System.out.println("\nYou rolled:");
90
-                dicePlayer.printCup();
91
-                System.out.println();
82
+                rollAll();
92 83
                 break;
93 84
 
94 85
             case 2:
95
-                System.out.println("Which numbers would you like to reroll? List the numbers separated by spaces.");
96
-                Scanner in2 = new Scanner(System.in);
97
-                String diceToRoll = in2.nextLine();
98 86
                 reRoll(diceToRoll);
99
-                System.out.println("\nYou rolled:");
100
-                dicePlayer.printCup();
101
-                System.out.println();
102 87
                 break;
103 88
 
104 89
             case 3:
@@ -122,24 +107,14 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
122 107
                 }
123 108
             }
124 109
         }
110
+        Printer.printMessage("\nYou rolled:\n" + dicePlayer.cupToString() + "\n");
111
+
125 112
     }
126 113
 
127
-    public void recordingScore() {
114
+    public ScoreSheet.ROW selectingRow(int choice) {
128 115
 
129
-        boolean validEntry = true;
130
-        int choice = 13;
131 116
         ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
132 117
 
133
-        while (validEntry) {
134
-            dicePlayer.getScoreSheet().printScoreCard();
135
-            System.out.println();
136
-            System.out.println("Which row would you like to apply your turn to on the scoresheet?.\n" +
137
-                    "Remember you can only use each row once!");
138
-            System.out.print("Row:");
139
-
140
-            Scanner scanner2 = new Scanner(System.in);
141
-            choice = scanner2.nextInt();
142
-
143 118
             switch (choice) {
144 119
                 case 1:
145 120
                     row = ScoreSheet.ROW.ACES;
@@ -181,17 +156,21 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
181 156
                     row = ScoreSheet.ROW.CHANCE;
182 157
                     break;
183 158
             }
159
+
160
+            return row;
161
+
162
+        }
163
+
164
+        public boolean checkEmptyRow(ScoreSheet.ROW row) {
184 165
             if (dicePlayer.getScoreSheet().getScore(row) == null) {
185
-                validEntry = false;
166
+                return true;
186 167
             } else {
187
-                System.out.println("Error, you have already filled that row");
168
+                Printer.printMessage("Error, you have already filled that row");
169
+                return false;
188 170
             }
189 171
         }
190 172
 
191
-        dicePlayer.getScoreSheet().setRow(row, dicePlayer.getCup());
192
-        System.out.println();
193
-        dicePlayer.getScoreSheet().printScoreCard();
194
-    }
173
+
195 174
 
196 175
     @Override
197 176
     public void bet(int betAmount) {
@@ -200,33 +179,27 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
200 179
 
201 180
     @Override
202 181
     public void payout() {
203
-        int score = dicePlayer.getScoreSheet().getTotalScore();
182
+        int score = getTotalScore();
204 183
         int payOut = 0;
205 184
         if (score == 1575) {
206 185
             payOut = getBid() * 100;
207
-        } else if (score > 1000) {
208
-            payOut = getBid() * 20;
209 186
         } else if (score > 500) {
210 187
             payOut = getBid() * 10;
211
-        } else if (score > 400) {
212
-            payOut = getBid() * 5;
213
-        } else if (score > 300) {
214
-            payOut = getBid() * 3;
215 188
         } else if (score > 200) {
216 189
             payOut = getBid() * 2;
217 190
         } else {
218 191
             payOut = 0;
219 192
         }
220 193
         dicePlayer.getPlayer().changeBalance(payOut);
221
-        System.out.println("You won $" + payOut);
194
+        Printer.printMessage("You won $" + payOut);
222 195
     }
223 196
 
224
-    @Override
225
-    public void quit() {
226
-
227
-    }
228 197
 
229 198
     public DicePlayer getDicePlayer() {
230 199
         return dicePlayer;
231 200
     }
201
+
202
+    public int getTotalScore() {
203
+        return totalScore;
204
+    }
232 205
 }

+ 0
- 5
src/main/java/io/zipcoder/casino/test.java View File

@@ -1,5 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-public class test {
4
-
5
-}

+ 5
- 0
src/test/java/io/zipcoder/casino/CasinoTest.java View File

@@ -1,5 +1,10 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 
4
+import org.junit.Assert;
5
+import org.junit.Test;
6
+
4 7
 public class CasinoTest {
8
+
9
+
5 10
 }

+ 31
- 0
src/test/java/io/zipcoder/casino/PlayerTest.java View File

@@ -0,0 +1,31 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PlayerTest {
7
+
8
+    @Test
9
+    public void testInitialBalance() {
10
+        //When
11
+        Player player = new Player("Bob", 500);
12
+        int expected = 500;
13
+        int actual = player.getInitialBalance();
14
+
15
+        //Then
16
+        Assert.assertEquals(expected, actual);
17
+
18
+    }
19
+
20
+    @Test
21
+    public void testGetName() {
22
+        //When
23
+        Player player = new Player("Bob", 500);
24
+        String expected = "Bob";
25
+        String actual = player.getName();
26
+
27
+        //Then
28
+        Assert.assertEquals(expected, actual);
29
+
30
+    }
31
+}

+ 259
- 317
src/test/java/io/zipcoder/casino/ScoreSheetTest.java View File

@@ -9,10 +9,18 @@ import java.util.Collections;
9 9
 
10 10
 public class ScoreSheetTest {
11 11
 
12
+    ScoreSheet scoreSheet = new ScoreSheet();
13
+    Dice dice1 = new Dice();
14
+    Dice dice2 = new Dice();
15
+    Dice dice3 = new Dice();
16
+    Dice dice4 = new Dice();
17
+    Dice dice5 = new Dice();
18
+    Dice[] cup = new Dice[5];
19
+
20
+
12 21
     @Test
13 22
     public void testCheckThreeOfAKindFalse() {
14 23
         //Given
15
-        ScoreSheet scoreSheet = new ScoreSheet();
16 24
         ArrayList<Integer> test = new ArrayList<>();
17 25
         test.add(5);
18 26
         test.add(3);
@@ -28,7 +36,6 @@ public class ScoreSheetTest {
28 36
     @Test
29 37
     public void testCheckThreeOfAKindTrue() {
30 38
         //Given
31
-        ScoreSheet scoreSheet = new ScoreSheet();
32 39
         ArrayList<Integer> test = new ArrayList<>();
33 40
         test.add(2);
34 41
         test.add(3);
@@ -44,7 +51,6 @@ public class ScoreSheetTest {
44 51
     @Test
45 52
     public void testCheckFourOfAKindFalse() {
46 53
         //Given
47
-        ScoreSheet scoreSheet = new ScoreSheet();
48 54
         ArrayList<Integer> test = new ArrayList<>();
49 55
         test.add(5);
50 56
         test.add(3);
@@ -60,7 +66,6 @@ public class ScoreSheetTest {
60 66
     @Test
61 67
     public void testCheckFourOfAKindTrue() {
62 68
         //Given
63
-        ScoreSheet scoreSheet = new ScoreSheet();
64 69
         ArrayList<Integer> test = new ArrayList<>();
65 70
         test.add(2);
66 71
         test.add(3);
@@ -76,7 +81,6 @@ public class ScoreSheetTest {
76 81
     @Test
77 82
     public void testCheckYahtzeeFalse() {
78 83
         //Given
79
-        ScoreSheet scoreSheet = new ScoreSheet();
80 84
         ArrayList<Integer> test = new ArrayList<>();
81 85
         test.add(5);
82 86
         test.add(3);
@@ -92,7 +96,6 @@ public class ScoreSheetTest {
92 96
     @Test
93 97
     public void testCheckYahtzeeTrue() {
94 98
         //Given
95
-        ScoreSheet scoreSheet = new ScoreSheet();
96 99
         ArrayList<Integer> test = new ArrayList<>();
97 100
         test.add(2);
98 101
         test.add(2);
@@ -108,7 +111,6 @@ public class ScoreSheetTest {
108 111
     @Test
109 112
     public void testCheckFullHouseFalse() {
110 113
         //Given
111
-        ScoreSheet scoreSheet = new ScoreSheet();
112 114
         ArrayList<Integer> test = new ArrayList<>();
113 115
         test.add(5);
114 116
         test.add(3);
@@ -124,7 +126,6 @@ public class ScoreSheetTest {
124 126
     @Test
125 127
     public void testCheckFullHouseTrue() {
126 128
         //Given
127
-        ScoreSheet scoreSheet = new ScoreSheet();
128 129
         ArrayList<Integer> test = new ArrayList<>();
129 130
         test.add(2);
130 131
         test.add(3);
@@ -140,7 +141,6 @@ public class ScoreSheetTest {
140 141
     @Test
141 142
     public void testCheckLargeStraightFalse() {
142 143
         //Given
143
-        ScoreSheet scoreSheet = new ScoreSheet();
144 144
         ArrayList<Integer> test = new ArrayList<>();
145 145
         test.add(5);
146 146
         test.add(3);
@@ -157,7 +157,6 @@ public class ScoreSheetTest {
157 157
     @Test
158 158
     public void testCheckLargeStraightTrue() {
159 159
         //Given
160
-        ScoreSheet scoreSheet = new ScoreSheet();
161 160
         ArrayList<Integer> test = new ArrayList<>();
162 161
         test.add(2);
163 162
         test.add(3);
@@ -174,7 +173,6 @@ public class ScoreSheetTest {
174 173
     @Test
175 174
     public void testCheckSmallStraightFalse() {
176 175
         //Given
177
-        ScoreSheet scoreSheet = new ScoreSheet();
178 176
         ArrayList<Integer> test = new ArrayList<>();
179 177
         test.add(5);
180 178
         test.add(3);
@@ -191,7 +189,6 @@ public class ScoreSheetTest {
191 189
     @Test
192 190
     public void testCheckSmallStraightTrue1() {
193 191
         //Given
194
-        ScoreSheet scoreSheet = new ScoreSheet();
195 192
         ArrayList<Integer> test = new ArrayList<>();
196 193
         test.add(5);
197 194
         test.add(3);
@@ -208,7 +205,6 @@ public class ScoreSheetTest {
208 205
     @Test
209 206
     public void testCheckSmallStraightTrue2() {
210 207
         //Given
211
-        ScoreSheet scoreSheet = new ScoreSheet();
212 208
         ArrayList<Integer> test = new ArrayList<>();
213 209
         test.add(1);
214 210
         test.add(3);
@@ -225,7 +221,6 @@ public class ScoreSheetTest {
225 221
     @Test
226 222
     public void testCheckSmallStraightTrue3() {
227 223
         //Given
228
-        ScoreSheet scoreSheet = new ScoreSheet();
229 224
         ArrayList<Integer> test = new ArrayList<>();
230 225
         test.add(1);
231 226
         test.add(3);
@@ -242,7 +237,6 @@ public class ScoreSheetTest {
242 237
     @Test
243 238
     public void testScoreNumbers() {
244 239
         //Given
245
-        ScoreSheet scoreSheet = new ScoreSheet();
246 240
         ArrayList<Integer> test = new ArrayList<>();
247 241
         test.add(2);
248 242
         test.add(3);
@@ -262,7 +256,6 @@ public class ScoreSheetTest {
262 256
     @Test
263 257
     public void testScoreTotalDice() {
264 258
         //Given
265
-        ScoreSheet scoreSheet = new ScoreSheet();
266 259
         ArrayList<Integer> test = new ArrayList<>();
267 260
         test.add(2);
268 261
         test.add(3);
@@ -282,13 +275,6 @@ public class ScoreSheetTest {
282 275
     @Test
283 276
     public void testSetRowCHANCE() {
284 277
         //Given
285
-        ScoreSheet scoreSheet = new ScoreSheet();
286
-        Dice dice1 = new Dice();
287
-        Dice dice2 = new Dice();
288
-        Dice dice3 = new Dice();
289
-        Dice dice4 = new Dice();
290
-        Dice dice5 = new Dice();
291
-        Dice[] cup = new Dice[5];
292 278
         cup[0] = dice1;
293 279
         cup[1] = dice2;
294 280
         cup[2] = dice3;
@@ -299,363 +285,319 @@ public class ScoreSheetTest {
299 285
         }
300 286
         int expected = dice1.getValue() + dice2.getValue() + dice3.getValue() + dice4.getValue() + dice5.getValue();
301 287
 
302
-        //When
303
-
304
-        scoreSheet.setRow(ScoreSheet.ROW.CHANCE, cup);
305
-        int actual = scoreSheet.getScore(ScoreSheet.ROW.CHANCE);
288
+            //When
289
+            scoreSheet.setRow(ScoreSheet.ROW.CHANCE, cup);
290
+            int actual = scoreSheet.getScore(ScoreSheet.ROW.CHANCE);
306 291
 
307
-        //Then
308
-        Assert.assertEquals(expected, actual);
292
+            //Then
293
+            Assert.assertEquals(expected, actual);
309 294
 
310
-    }
311
-
312
-    @Test
313
-    public void testSetRowACES() {
314
-        //Given
315
-        ScoreSheet scoreSheet = new ScoreSheet();
316
-        Dice dice1 = new Dice();
317
-        Dice dice2 = new Dice();
318
-        Dice dice3 = new Dice();
319
-        Dice dice4 = new Dice();
320
-        Dice dice5 = new Dice();
321
-        Dice[] cup = new Dice[5];
322
-        cup[0] = dice1;
323
-        cup[1] = dice2;
324
-        cup[2] = dice3;
325
-        cup[3] = dice4;
326
-        cup[4] = dice5;
327
-        for (Dice d : cup) {
328
-            d.roll();
329 295
         }
330 296
 
331
-        //When
332
-        scoreSheet.setRow(ScoreSheet.ROW.ACES, cup);
297
+        @Test
298
+        public void testSetRowACES () {
299
+            //Given
300
+            cup[0] = dice1;
301
+            cup[1] = dice2;
302
+            cup[2] = dice3;
303
+            cup[3] = dice4;
304
+            cup[4] = dice5;
305
+            for (Dice d : cup) {
306
+                d.roll();
307
+            }
333 308
 
309
+            //When
310
+            scoreSheet.setRow(ScoreSheet.ROW.ACES, cup);
334 311
 
335
-        //Then
336
-        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.ACES) != null));
337 312
 
338
-    }
313
+            //Then
314
+            Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.ACES) != null));
339 315
 
340
-    @Test
341
-    public void testSetRowTWOS() {
342
-        //Given
343
-        ScoreSheet scoreSheet = new ScoreSheet();
344
-        Dice dice1 = new Dice();
345
-        Dice dice2 = new Dice();
346
-        Dice dice3 = new Dice();
347
-        Dice dice4 = new Dice();
348
-        Dice dice5 = new Dice();
349
-        Dice[] cup = new Dice[5];
350
-        cup[0] = dice1;
351
-        cup[1] = dice2;
352
-        cup[2] = dice3;
353
-        cup[3] = dice4;
354
-        cup[4] = dice5;
355
-        for (Dice d : cup) {
356
-            d.roll();
357 316
         }
358 317
 
359
-        //When
360
-        scoreSheet.setRow(ScoreSheet.ROW.TWOS, cup);
318
+        @Test
319
+        public void testSetRowTWOS () {
320
+            //Given
321
+            cup[0] = dice1;
322
+            cup[1] = dice2;
323
+            cup[2] = dice3;
324
+            cup[3] = dice4;
325
+            cup[4] = dice5;
326
+            for (Dice d : cup) {
327
+                d.roll();
328
+            }
361 329
 
330
+            //When
331
+            scoreSheet.setRow(ScoreSheet.ROW.TWOS, cup);
362 332
 
363
-        //Then
364
-        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.TWOS) != null));
365 333
 
366
-    }
334
+            //Then
335
+            Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.TWOS) != null));
367 336
 
368
-    @Test
369
-    public void testSetRowTHREES() {
370
-        //Given
371
-        ScoreSheet scoreSheet = new ScoreSheet();
372
-        Dice dice1 = new Dice();
373
-        Dice dice2 = new Dice();
374
-        Dice dice3 = new Dice();
375
-        Dice dice4 = new Dice();
376
-        Dice dice5 = new Dice();
377
-        Dice[] cup = new Dice[5];
378
-        cup[0] = dice1;
379
-        cup[1] = dice2;
380
-        cup[2] = dice3;
381
-        cup[3] = dice4;
382
-        cup[4] = dice5;
383
-        for (Dice d : cup) {
384
-            d.roll();
385 337
         }
386 338
 
387
-        //When
388
-        scoreSheet.setRow(ScoreSheet.ROW.THREES, cup);
339
+        @Test
340
+        public void testSetRowTHREES () {
341
+            //Given
342
+            cup[0] = dice1;
343
+            cup[1] = dice2;
344
+            cup[2] = dice3;
345
+            cup[3] = dice4;
346
+            cup[4] = dice5;
347
+            for (Dice d : cup) {
348
+                d.roll();
349
+            }
389 350
 
351
+            //When
352
+            scoreSheet.setRow(ScoreSheet.ROW.THREES, cup);
390 353
 
391
-        //Then
392
-        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.THREES) != null));
393 354
 
394
-    }
355
+            //Then
356
+            Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.THREES) != null));
395 357
 
396
-    @Test
397
-    public void testSetRowFOURS() {
398
-        //Given
399
-        ScoreSheet scoreSheet = new ScoreSheet();
400
-        Dice dice1 = new Dice();
401
-        Dice dice2 = new Dice();
402
-        Dice dice3 = new Dice();
403
-        Dice dice4 = new Dice();
404
-        Dice dice5 = new Dice();
405
-        Dice[] cup = new Dice[5];
406
-        cup[0] = dice1;
407
-        cup[1] = dice2;
408
-        cup[2] = dice3;
409
-        cup[3] = dice4;
410
-        cup[4] = dice5;
411
-        for (Dice d : cup) {
412
-            d.roll();
413 358
         }
414 359
 
415
-        //When
416
-        scoreSheet.setRow(ScoreSheet.ROW.FOURS, cup);
360
+        @Test
361
+        public void testSetRowFOURS () {
362
+            //Given
363
+            cup[0] = dice1;
364
+            cup[1] = dice2;
365
+            cup[2] = dice3;
366
+            cup[3] = dice4;
367
+            cup[4] = dice5;
368
+            for (Dice d : cup) {
369
+                d.roll();
370
+            }
417 371
 
372
+            //When
373
+            scoreSheet.setRow(ScoreSheet.ROW.FOURS, cup);
418 374
 
419
-        //Then
420
-        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FOURS) != null));
421 375
 
422
-    }
376
+            //Then
377
+            Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FOURS) != null));
423 378
 
424
-    @Test
425
-    public void testSetRowFIVES() {
426
-        //Given
427
-        ScoreSheet scoreSheet = new ScoreSheet();
428
-        Dice dice1 = new Dice();
429
-        Dice dice2 = new Dice();
430
-        Dice dice3 = new Dice();
431
-        Dice dice4 = new Dice();
432
-        Dice dice5 = new Dice();
433
-        Dice[] cup = new Dice[5];
434
-        cup[0] = dice1;
435
-        cup[1] = dice2;
436
-        cup[2] = dice3;
437
-        cup[3] = dice4;
438
-        cup[4] = dice5;
439
-        for (Dice d : cup) {
440
-            d.roll();
441 379
         }
442 380
 
443
-        //When
444
-        scoreSheet.setRow(ScoreSheet.ROW.FIVES, cup);
381
+        @Test
382
+        public void testSetRowFIVES () {
383
+            //Given
384
+            cup[0] = dice1;
385
+            cup[1] = dice2;
386
+            cup[2] = dice3;
387
+            cup[3] = dice4;
388
+            cup[4] = dice5;
389
+            for (Dice d : cup) {
390
+                d.roll();
391
+            }
445 392
 
393
+            //When
394
+            scoreSheet.setRow(ScoreSheet.ROW.FIVES, cup);
446 395
 
447
-        //Then
448
-        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FIVES) != null));
449 396
 
450
-    }
397
+            //Then
398
+            Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FIVES) != null));
451 399
 
452
-    @Test
453
-    public void testSetRowSIXES() {
454
-        //Given
455
-        ScoreSheet scoreSheet = new ScoreSheet();
456
-        Dice dice1 = new Dice();
457
-        Dice dice2 = new Dice();
458
-        Dice dice3 = new Dice();
459
-        Dice dice4 = new Dice();
460
-        Dice dice5 = new Dice();
461
-        Dice[] cup = new Dice[5];
462
-        cup[0] = dice1;
463
-        cup[1] = dice2;
464
-        cup[2] = dice3;
465
-        cup[3] = dice4;
466
-        cup[4] = dice5;
467
-        for (Dice d : cup) {
468
-            d.roll();
469 400
         }
470 401
 
471
-        //When
472
-        scoreSheet.setRow(ScoreSheet.ROW.SIXES, cup);
402
+        @Test
403
+        public void testSetRowSIXES () {
404
+            //Given
405
+            cup[0] = dice1;
406
+            cup[1] = dice2;
407
+            cup[2] = dice3;
408
+            cup[3] = dice4;
409
+            cup[4] = dice5;
410
+            for (Dice d : cup) {
411
+                d.roll();
412
+            }
473 413
 
414
+            //When
415
+            scoreSheet.setRow(ScoreSheet.ROW.SIXES, cup);
474 416
 
475
-        //Then
476
-        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.SIXES) != null));
477 417
 
478
-    }
418
+            //Then
419
+            Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.SIXES) != null));
479 420
 
480
-    @Test
481
-    public void testSetRowThreeOfAKind() {
482
-        //Given
483
-        ScoreSheet scoreSheet = new ScoreSheet();
484
-        Dice dice1 = new Dice();
485
-        Dice dice2 = new Dice();
486
-        Dice dice3 = new Dice();
487
-        Dice dice4 = new Dice();
488
-        Dice dice5 = new Dice();
489
-        Dice[] cup = new Dice[5];
490
-        cup[0] = dice1;
491
-        cup[1] = dice2;
492
-        cup[2] = dice3;
493
-        cup[3] = dice4;
494
-        cup[4] = dice5;
495
-        for (Dice d : cup) {
496
-            d.roll();
497 421
         }
498 422
 
499
-        //When
500
-        scoreSheet.setRow(ScoreSheet.ROW.THREEOFAKIND, cup);
501
-
502
-
503
-        //Then
504
-        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.THREEOFAKIND) != null));
505
-
506
-    }
507
-
508
-    @Test
509
-    public void testSetRowFourOfAKind() {
510
-        //Given
511
-        ScoreSheet scoreSheet = new ScoreSheet();
512
-        Dice dice1 = new Dice();
513
-        Dice dice2 = new Dice();
514
-        Dice dice3 = new Dice();
515
-        Dice dice4 = new Dice();
516
-        Dice dice5 = new Dice();
517
-        Dice[] cup = new Dice[5];
518
-        cup[0] = dice1;
519
-        cup[1] = dice2;
520
-        cup[2] = dice3;
521
-        cup[3] = dice4;
522
-        cup[4] = dice5;
523
-        for (Dice d : cup) {
524
-            d.roll();
525
-        }
423
+        @Test
424
+        public void testSetRowThreeOfAKind () {
425
+            //Given
426
+            cup[0] = dice1;
427
+            cup[1] = dice2;
428
+            cup[2] = dice3;
429
+            cup[3] = dice4;
430
+            cup[4] = dice5;
431
+            for (Dice d : cup) {
432
+                d.roll();
433
+            }
526 434
 
527
-        //When
528
-        scoreSheet.setRow(ScoreSheet.ROW.FOUROFAKIND, cup);
435
+            //When
436
+            scoreSheet.setRow(ScoreSheet.ROW.THREEOFAKIND, cup);
529 437
 
530 438
 
531
-        //Then
532
-        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FOUROFAKIND) != null));
439
+            //Then
440
+            Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.THREEOFAKIND) != null));
533 441
 
534
-    }
535
-
536
-    @Test
537
-    public void testSetRowFullHouse() {
538
-        //Given
539
-        ScoreSheet scoreSheet = new ScoreSheet();
540
-        Dice dice1 = new Dice();
541
-        Dice dice2 = new Dice();
542
-        Dice dice3 = new Dice();
543
-        Dice dice4 = new Dice();
544
-        Dice dice5 = new Dice();
545
-        Dice[] cup = new Dice[5];
546
-        cup[0] = dice1;
547
-        cup[1] = dice2;
548
-        cup[2] = dice3;
549
-        cup[3] = dice4;
550
-        cup[4] = dice5;
551
-        for (Dice d : cup) {
552
-            d.roll();
553
-        }
554
-
555
-        //When
556
-        scoreSheet.setRow(ScoreSheet.ROW.FULLHOUSE, cup);
557
-
558
-
559
-        //Then
560
-        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FULLHOUSE) != null));
561
-
562
-    }
563
-
564
-    @Test
565
-    public void testSetRowSmallStraight() {
566
-        //Given
567
-        ScoreSheet scoreSheet = new ScoreSheet();
568
-        Dice dice1 = new Dice();
569
-        Dice dice2 = new Dice();
570
-        Dice dice3 = new Dice();
571
-        Dice dice4 = new Dice();
572
-        Dice dice5 = new Dice();
573
-        Dice[] cup = new Dice[5];
574
-        cup[0] = dice1;
575
-        cup[1] = dice2;
576
-        cup[2] = dice3;
577
-        cup[3] = dice4;
578
-        cup[4] = dice5;
579
-        for (Dice d : cup) {
580
-            d.roll();
581 442
         }
582 443
 
583
-        //When
584
-        scoreSheet.setRow(ScoreSheet.ROW.SMALLSTRAIGHT, cup);
444
+        @Test
445
+        public void testSetRowFourOfAKind () {
446
+            //Given
447
+            cup[0] = dice1;
448
+            cup[1] = dice2;
449
+            cup[2] = dice3;
450
+            cup[3] = dice4;
451
+            cup[4] = dice5;
452
+            for (Dice d : cup) {
453
+                d.roll();
454
+            }
585 455
 
456
+            //When
457
+            scoreSheet.setRow(ScoreSheet.ROW.FOUROFAKIND, cup);
586 458
 
587
-        //Then
588
-        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.SMALLSTRAIGHT) != null));
589 459
 
590
-    }
460
+            //Then
461
+            Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FOUROFAKIND) != null));
591 462
 
592
-    @Test
593
-    public void testSetRowLargeStraight() {
594
-        //Given
595
-        ScoreSheet scoreSheet = new ScoreSheet();
596
-        Dice dice1 = new Dice();
597
-        Dice dice2 = new Dice();
598
-        Dice dice3 = new Dice();
599
-        Dice dice4 = new Dice();
600
-        Dice dice5 = new Dice();
601
-        Dice[] cup = new Dice[5];
602
-        cup[0] = dice1;
603
-        cup[1] = dice2;
604
-        cup[2] = dice3;
605
-        cup[3] = dice4;
606
-        cup[4] = dice5;
607
-        for (Dice d : cup) {
608
-            d.roll();
609 463
         }
610 464
 
611
-        //When
612
-        scoreSheet.setRow(ScoreSheet.ROW.LARGESTRAIGHT, cup);
465
+        @Test
466
+        public void testSetRowFullHouse () {
467
+            //Given
468
+            cup[0] = dice1;
469
+            cup[1] = dice2;
470
+            cup[2] = dice3;
471
+            cup[3] = dice4;
472
+            cup[4] = dice5;
473
+            for (Dice d : cup) {
474
+                d.roll();
475
+
476
+            }
477
+                //When
478
+                scoreSheet.setRow(ScoreSheet.ROW.FULLHOUSE, cup);
479
+
480
+
481
+                //Then
482
+                Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FULLHOUSE) != null));
483
+
484
+            }
485
+
486
+            @Test
487
+            public void testSetRowSmallStraight () {
488
+                //Given
489
+                cup[0] = dice1;
490
+                cup[1] = dice2;
491
+                cup[2] = dice3;
492
+                cup[3] = dice4;
493
+                cup[4] = dice5;
494
+                for (Dice d : cup) {
495
+                    d.roll();
496
+                }
497
+
498
+                //When
499
+                scoreSheet.setRow(ScoreSheet.ROW.SMALLSTRAIGHT, cup);
500
+
501
+
502
+                //Then
503
+                Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.SMALLSTRAIGHT) != null));
504
+
505
+            }
506
+
507
+            @Test
508
+            public void testSetRowLargeStraight () {
509
+                //Given
510
+                cup[0] = dice1;
511
+                cup[1] = dice2;
512
+                cup[2] = dice3;
513
+                cup[3] = dice4;
514
+                cup[4] = dice5;
515
+                for (Dice d : cup) {
516
+                    d.roll();
517
+                }
518
+
519
+                //When
520
+                scoreSheet.setRow(ScoreSheet.ROW.LARGESTRAIGHT, cup);
521
+
522
+
523
+                //Then
524
+                Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.LARGESTRAIGHT) != null));
525
+
526
+            }
527
+
528
+            @Test
529
+            public void testSetRowYahtzee () {
530
+                //Given
531
+                cup[0] = dice1;
532
+                cup[1] = dice2;
533
+                cup[2] = dice3;
534
+                cup[3] = dice4;
535
+                cup[4] = dice5;
536
+                for (Dice d : cup) {
537
+                    d.roll();
538
+                }
539
+
540
+                //When
541
+                scoreSheet.setRow(ScoreSheet.ROW.YAHTZEE, cup);
542
+
543
+
544
+                //Then
545
+                Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.YAHTZEE) != null));
546
+
547
+            }
548
+
549
+            @Test
550
+            public void testGetSize () {
551
+                //Given
552
+                int expected = 13;
553
+
554
+                //When
555
+                int actual = ScoreSheet.getSize();
556
+
557
+                //Then
558
+                Assert.assertEquals(expected, actual);
559
+
560
+            }
561
+
562
+            @Test
563
+            public void testScoreCardToString () {
564
+                //Given
565
+                String expected = "1. Aces: Totals all Ones           ** open **\n" +
566
+                        "2. Twos: Totals all Twos           ** open **\n" +
567
+                        "3. Threes: Totals all Threes       ** open **\n" +
568
+                        "4. Fours: Totals all Fours         ** open **\n" +
569
+                        "5. Fives: Totals all Fives         ** open **\n" +
570
+                        "6. Sixes: Totals all Sixes         ** open **\n" +
571
+                        "7. 3 of a Kind                     ** open **\n" +
572
+                        "8. 4 of a Kind                     ** open **\n" +
573
+                        "9. Full House                      ** open **\n" +
574
+                        "10. Small Straight: Sequence of 4  ** open **\n" +
575
+                        "11. Large Striaght: Sequence of 5  ** open **\n" +
576
+                        "12. Yahtzee: 5 of a Kind           ** open **\n" +
577
+                        "13. Chance: Sum of Dice            ** open **\n";
613 578
 
614
-
615
-        //Then
616
-        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.LARGESTRAIGHT) != null));
617
-
618
-    }
579
+                //When
580
+                String actual = scoreSheet.scoreCardToString();
581
+
582
+                //Then
583
+                Assert.assertEquals(expected, actual);
584
+
585
+            }
619 586
 
620 587
     @Test
621
-    public void testSetRowYahtzee() {
588
+    public void testTotalScore () {
622 589
         //Given
623
-        ScoreSheet scoreSheet = new ScoreSheet();
624
-        Dice dice1 = new Dice();
625
-        Dice dice2 = new Dice();
626
-        Dice dice3 = new Dice();
627
-        Dice dice4 = new Dice();
628
-        Dice dice5 = new Dice();
629
-        Dice[] cup = new Dice[5];
630
-        cup[0] = dice1;
631
-        cup[1] = dice2;
632
-        cup[2] = dice3;
633
-        cup[3] = dice4;
634
-        cup[4] = dice5;
635
-        for (Dice d : cup) {
636
-            d.roll();
637
-        }
590
+        int expected = 0;
638 591
 
639 592
         //When
640
-        scoreSheet.setRow(ScoreSheet.ROW.YAHTZEE, cup);
641
-
593
+        int actual = scoreSheet.getTotalScore();
642 594
 
643 595
         //Then
644
-        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.YAHTZEE) != null));
596
+        Assert.assertEquals(expected, actual);
645 597
 
646 598
     }
647 599
 
648
-    @Test
649
-    public void testGetSize() {
650
-        //Given
651
-        int expected = 13;
652
-
653
-        //When
654
-        int actual = ScoreSheet.getSize();
655
-
656
-        //Then
657
-        Assert.assertEquals(expected, actual);
658 600
 
659
-    }
660 601
 
661 602
 }
603
+

+ 237
- 1
src/test/java/io/zipcoder/casino/YahtzeeTest.java View File

@@ -35,7 +35,7 @@ public class YahtzeeTest {
35 35
     @Test
36 36
     public void testCreateGame() {
37 37
         //When
38
-        yahtzee.createGame();
38
+        yahtzee.startGame();
39 39
         int expected = 5;
40 40
         int actual = yahtzee.getDicePlayer().getCup().length;
41 41
 
@@ -45,5 +45,241 @@ public class YahtzeeTest {
45 45
 
46 46
     }
47 47
 
48
+    @Test
49
+    public void testRollOptionsNoRoll() {
50
+        //When
51
+        yahtzee.startGame();
52
+        String expected = yahtzee.getDicePlayer().cupToString();
53
+        yahtzee.rollOptions(3, "");
54
+        String actual = yahtzee.getDicePlayer().cupToString();
55
+
56
+        //Then
57
+        Assert.assertEquals(expected, actual);
58
+
59
+
60
+    }
61
+
62
+    @Test
63
+    public void testRollOptionsRollAll() {
64
+        //When
65
+        yahtzee.startGame();
66
+        String expected = yahtzee.getDicePlayer().cupToString();
67
+        yahtzee.rollOptions(1, "");
68
+        String actual = yahtzee.getDicePlayer().cupToString();
69
+
70
+        //Then
71
+        Assert.assertNotEquals(expected, actual);
72
+
73
+
74
+    }
75
+
76
+    @Test
77
+    public void testReRoll() {
78
+        //When
79
+        yahtzee.startGame();
80
+        int diceOneValue = yahtzee.getDicePlayer().getCup()[0].getValue();
81
+        int diceTwoValue = yahtzee.getDicePlayer().getCup()[1].getValue();
82
+        yahtzee.rollOptions(2, Integer.toString(diceTwoValue));
83
+        int actual = yahtzee.getDicePlayer().getCup()[0].getValue();
84
+
85
+        //Then
86
+        Assert.assertNotEquals(diceOneValue, actual);
87
+
88
+
89
+    }
90
+
91
+    @Test
92
+    public void testEmptyRowTrue() {
93
+        //When
94
+        yahtzee.startGame();
95
+
96
+        //Then
97
+        Assert.assertTrue(yahtzee.checkEmptyRow(ScoreSheet.ROW.CHANCE));
98
+
99
+
100
+    }
101
+
102
+    @Test
103
+    public void testEmptyRowFalse() {
104
+        //When
105
+        yahtzee.startGame();
106
+        yahtzee.rollAll();
107
+        yahtzee.getDicePlayer().getScoreSheet().setRow(ScoreSheet.ROW.CHANCE, yahtzee.getDicePlayer().getCup());
108
+
109
+        //Then
110
+        Assert.assertFalse(yahtzee.checkEmptyRow(ScoreSheet.ROW.CHANCE));
111
+
112
+
113
+    }
114
+
115
+    @Test
116
+    public void testPayout() {
117
+        //When
118
+        int expected = yahtzee.getDicePlayer().getPlayer().getCurrentBalance();
119
+        yahtzee.payout();
120
+        int actual = yahtzee.getDicePlayer().getPlayer().getCurrentBalance();
121
+
122
+        //Then
123
+        Assert.assertEquals(expected, actual);
124
+
125
+    }
126
+
127
+
128
+    @Test
129
+    public void testSelectingRow1() {
130
+        //When
131
+        ScoreSheet.ROW expected = ScoreSheet.ROW.ACES;
132
+        ScoreSheet.ROW actual = yahtzee.selectingRow(1);
133
+
134
+        //Then
135
+        Assert.assertEquals(expected, actual);
136
+
137
+    }
138
+
139
+    @Test
140
+    public void testSelectingRow2() {
141
+        //When
142
+        ScoreSheet.ROW expected = ScoreSheet.ROW.TWOS;
143
+        ScoreSheet.ROW actual = yahtzee.selectingRow(2);
144
+
145
+        //Then
146
+        Assert.assertEquals(expected, actual);
147
+
148
+    }
149
+
150
+    @Test
151
+    public void testSelectingRow3() {
152
+        //When
153
+        ScoreSheet.ROW expected = ScoreSheet.ROW.THREES;
154
+        ScoreSheet.ROW actual = yahtzee.selectingRow(3);
155
+
156
+        //Then
157
+        Assert.assertEquals(expected, actual);
158
+
159
+    }
160
+
161
+    @Test
162
+    public void testSelectingRow4() {
163
+        //When
164
+        ScoreSheet.ROW expected = ScoreSheet.ROW.FOURS;
165
+        ScoreSheet.ROW actual = yahtzee.selectingRow(4);
166
+
167
+        //Then
168
+        Assert.assertEquals(expected, actual);
169
+
170
+    }
171
+
172
+    @Test
173
+    public void testSelectingRow5() {
174
+        //When
175
+        ScoreSheet.ROW expected = ScoreSheet.ROW.FIVES;
176
+        ScoreSheet.ROW actual = yahtzee.selectingRow(5);
177
+
178
+        //Then
179
+        Assert.assertEquals(expected, actual);
180
+
181
+    }
182
+
183
+    @Test
184
+    public void testSelectingRow6() {
185
+        //When
186
+        ScoreSheet.ROW expected = ScoreSheet.ROW.SIXES;
187
+        ScoreSheet.ROW actual = yahtzee.selectingRow(6);
188
+
189
+        //Then
190
+        Assert.assertEquals(expected, actual);
191
+
192
+    }
193
+
194
+    @Test
195
+    public void testSelectingRow7() {
196
+        //When
197
+        ScoreSheet.ROW expected = ScoreSheet.ROW.THREEOFAKIND;
198
+        ScoreSheet.ROW actual = yahtzee.selectingRow(7);
199
+
200
+        //Then
201
+        Assert.assertEquals(expected, actual);
202
+
203
+    }
204
+
205
+    @Test
206
+    public void testSelectingRow8() {
207
+        //When
208
+        ScoreSheet.ROW expected = ScoreSheet.ROW.FOUROFAKIND;
209
+        ScoreSheet.ROW actual = yahtzee.selectingRow(8);
210
+
211
+        //Then
212
+        Assert.assertEquals(expected, actual);
213
+
214
+    }
215
+
216
+    @Test
217
+    public void testSelectingRow9() {
218
+        //When
219
+        ScoreSheet.ROW expected = ScoreSheet.ROW.FULLHOUSE;
220
+        ScoreSheet.ROW actual = yahtzee.selectingRow(9);
221
+
222
+        //Then
223
+        Assert.assertEquals(expected, actual);
224
+
225
+    }
226
+
227
+    @Test
228
+    public void testSelectingRow10() {
229
+        //When
230
+        ScoreSheet.ROW expected = ScoreSheet.ROW.SMALLSTRAIGHT;
231
+        ScoreSheet.ROW actual = yahtzee.selectingRow(10);
232
+
233
+        //Then
234
+        Assert.assertEquals(expected, actual);
235
+
236
+    }
237
+
238
+    @Test
239
+    public void testSelectingRow11() {
240
+        //When
241
+        ScoreSheet.ROW expected = ScoreSheet.ROW.LARGESTRAIGHT;
242
+        ScoreSheet.ROW actual = yahtzee.selectingRow(11);
243
+
244
+        //Then
245
+        Assert.assertEquals(expected, actual);
246
+
247
+    }
248
+
249
+    @Test
250
+    public void testSelectingRow12() {
251
+        //When
252
+        ScoreSheet.ROW expected = ScoreSheet.ROW.YAHTZEE;
253
+        ScoreSheet.ROW actual = yahtzee.selectingRow(12);
254
+
255
+        //Then
256
+        Assert.assertEquals(expected, actual);
257
+
258
+    }
259
+
260
+    @Test
261
+    public void testSelectingRow13() {
262
+        //When
263
+        ScoreSheet.ROW expected = ScoreSheet.ROW.CHANCE;
264
+        ScoreSheet.ROW actual = yahtzee.selectingRow(13);
265
+
266
+        //Then
267
+        Assert.assertEquals(expected, actual);
268
+
269
+    }
270
+
271
+    @Test
272
+    public void testFinalScore() {
273
+        //Given
274
+        String expected = "Your total balance is now: $" + yahtzee.getDicePlayer().getPlayer().getCurrentBalance();;
275
+
276
+        //When
277
+        String actual = yahtzee.getDicePlayer().balanceAtEnd();
278
+
279
+        //Then
280
+        Assert.assertEquals(expected, actual);
281
+
282
+    }
283
+
48 284
 
49 285
 }