Procházet zdrojové kódy

resolved conflicts with slot tests

Simran Bhutani před 6 roky
rodič
revize
fa1f81dade

+ 1
- 1
.gitignore Zobrazit soubor

@@ -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/

+ 3
- 1
src/main/java/io/zipcoder/casino/CardGame.java Zobrazit soubor

@@ -24,7 +24,8 @@ public abstract class CardGame {
24 24
     }
25 25
 
26 26
     //use hand size to determine dealing
27
-    public abstract void deal();
27
+    // public abstract void deal();
28
+    // public abstract void deal(ArrayList<CardPlayer> players); // NEEDED FOR STUD
28 29
 
29 30
     public void shuffle(){
30 31
 
@@ -47,6 +48,7 @@ public abstract class CardGame {
47 48
         }
48 49
     }
49 50
 
51
+
50 52
     public int getAnte(){
51 53
         return ante;
52 54
     }

+ 22
- 3
src/main/java/io/zipcoder/casino/Casino.java Zobrazit soubor

@@ -42,7 +42,7 @@ public class Casino {
42 42
     {
43 43
         while(running) {
44 44
 
45
-            Printer.pickGameMsg();
45
+            Printer.printMessage("Please choose a game to play!");
46 46
             Printer.printMessage(getGameListing());
47 47
 
48 48
             int command = console.getIntFromUser("Please choose a game to play by entering the number next to the game.");
@@ -53,6 +53,7 @@ public class Casino {
53 53
                     Game war = new War(10);
54 54
                     ((War) war).addPlayers(player);
55 55
                     ((War) war).addNpc();
56
+                    game = war;
56 57
                     war.startGame();
57 58
                     break;
58 59
 
@@ -60,6 +61,7 @@ public class Casino {
60 61
                     Game stud = new Stud(10);
61 62
                     ((Stud) stud).addPlayers(player);
62 63
                     ((Stud) stud).addNpc();
64
+                    game = stud;
63 65
                     stud.startGame();
64 66
                     break;
65 67
 
@@ -71,6 +73,7 @@ public class Casino {
71 73
                         break;
72 74
                     }
73 75
                     Game slot= new SlotMachine(slotBet1);
76
+                    game = slot;
74 77
                     slot.startGame();
75 78
                     ((SlotMachine) slot).slotResult();
76 79
                     ((SlotMachine) slot).payout();
@@ -78,12 +81,20 @@ public class Casino {
78 81
 
79 82
                 case 1:
80 83
                     Game yahtzee = new Yahtzee(player);
81
-                    yahtzee.startGame();
84
+                    ((Yahtzee) yahtzee).startGame();
85
+                    int betAmount = console.getIntFromUser("How much would you like to bet on this game?");
86
+                    ((Yahtzee) yahtzee).setBid(betAmount);
87
+                    ((Yahtzee) yahtzee).bet(betAmount);
88
+                    game = yahtzee;
89
+                    yahtzee.startRound();
90
+                    Printer.printMessage("You scored " + ((Yahtzee) yahtzee).getDicePlayer().getScoreSheet().getTotalScore() + " points.");
91
+                    ((Yahtzee) yahtzee).payout();
92
+                    Printer.printMessage(((Yahtzee) yahtzee).getDicePlayer().balanceAtEnd() + "\n");
82 93
                     break;
83 94
 
84 95
                 case 5:
85 96
                     running = false;
86
-                    Printer.closeGameMsg();
97
+                    Printer.printMessage("Thanks for the money chump!");
87 98
                     break;
88 99
 
89 100
                 default:
@@ -119,4 +130,12 @@ public class Casino {
119 130
     public void setPlayer(Player player) {
120 131
         this.player = player;
121 132
     }
133
+
134
+    public ArrayList<String> getGameLib() {
135
+        return gameLib;
136
+    }
137
+
138
+    public Game getGame() {
139
+        return game;
140
+    }
122 141
 }

+ 10
- 1
src/main/java/io/zipcoder/casino/Console.java Zobrazit soubor

@@ -4,6 +4,7 @@ import java.util.InputMismatchException;
4 4
 import java.util.Scanner;
5 5
 
6 6
 public class Console {
7
+
7 8
     private Scanner scanner = new Scanner(System.in);
8 9
 
9 10
     Console(){
@@ -23,7 +24,7 @@ public class Console {
23 24
             int num = scanner.nextInt();
24 25
             return num;
25 26
         }catch(InputMismatchException err){
26
-            Printer.pleaseEnterNum();
27
+            Printer.printMessage("Please enter a number.");
27 28
             scanner.next();
28 29
         }
29 30
         return -1;
@@ -42,4 +43,12 @@ public class Console {
42 43
         input.toLowerCase().trim();
43 44
         return input;
44 45
     }
46
+
47
+    public void setScanner(Scanner scanner) {
48
+        this.scanner = scanner;
49
+    }
50
+
51
+    public Scanner getScanner() {
52
+        return scanner;
53
+    }
45 54
 }

+ 8
- 5
src/main/java/io/zipcoder/casino/DicePlayer.java Zobrazit soubor

@@ -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
 

+ 0
- 29
src/main/java/io/zipcoder/casino/Printer.java Zobrazit soubor

@@ -19,33 +19,4 @@ public class Printer {
19 19
 
20 20
         printMessage("Sorry, there is no game with that name, try one of: " + games);
21 21
     }
22
-
23
-    public static void showCard(Player player, Card card){
24
-        printMessage(player.getName() + " shows a " + card.getName());
25
-    }
26
-
27
-    public static void pickGameMsg(){
28
-        printMessage("Please choose a game to play!");
29
-    }
30
-
31
-    public static void closeGameMsg(){
32
-        printMessage("Thanks for your money chump!");
33
-    }
34
-
35
-    public static void pleaseEnterNum(){
36
-        printMessage("Please enter a number");
37
-    }
38
-    
39
-    public static void welcomeTo(String gameName){
40
-        printMessage("Welcome to " + gameName + "!");
41
-    }
42
-
43
-    public static void printWarTurnResult(String name, String cardName, int handSize){
44
-        printMessage(name + " has played " + cardName + " and has " + handSize + " cards left.");
45
-    }
46
-
47
-    public static void playedFaceDown(String name){
48
-        printMessage(name + " has played a card face down.");
49
-    }
50
-
51 22
 }

+ 65
- 117
src/main/java/io/zipcoder/casino/ScoreSheet.java Zobrazit soubor

@@ -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
- 1
src/main/java/io/zipcoder/casino/SlotMachine.java Zobrazit soubor

@@ -24,7 +24,6 @@ public class SlotMachine implements Game, Gamble {
24 24
 
25 25
     @Override
26 26
     public void payout(){
27
-
28 27
         Printer.printMessage("Your payout amount for slot machine is: $" + payout + "\n");
29 28
     }
30 29
 

+ 128
- 197
src/main/java/io/zipcoder/casino/Stud.java Zobrazit soubor

@@ -1,11 +1,12 @@
1
-
2 1
 package io.zipcoder.casino;
3
-import java.util.Scanner;
4 2
 
5
-public class Stud extends CardGame implements Gamble, Game {
6
-    Scanner scanner = new Scanner(System.in);
7
-    Console console;
8
-    // private int roundCount = 0;
3
+import java.util.ArrayList;
4
+
5
+public class Stud extends CardGame implements Game {
6
+    Console console = new Console();
7
+    private boolean isDealt = false;
8
+    private boolean isCardFlipped = false;
9
+    private int countRound = 0;
9 10
 
10 11
     public Stud(int ante) {
11 12
         super(ante);
@@ -13,33 +14,34 @@ public class Stud extends CardGame implements Gamble, Game {
13 14
     
14 15
     public void playCard(Player player, Card card) {
15 16
         card.setVisibility(true);               //CARD isVISIBLE
16
-        Printer.showCard(player, card);         //PRINT card name to CONSOLE
17
+        Printer.printMessage(player.getName() + " shows a " + card.getName());         //PRINT card name to CONSOLE
17 18
     }
18 19
 
19 20
 
20
-    public void fold(){
21
-
21
+    public boolean getIsDealt(){
22
+        return isDealt;
22 23
     }
23 24
 
25
+
24 26
     /**
25 27
      * Determine what player wins by looping through player array and then
26 28
      * passing each hand to the 'handValue' method
27 29
      */
28
-    public CardPlayer determineWinner(){
29
-    int max = 0;
30
-    CardPlayer winner = null;
31
-
32
-    for(int i = 0; i < getPlayers().size(); i ++){
33
-        CardPlayer player = getPlayers().get(i);
34
-        int playerHandValue = handValue(player); // 'handValue' method sets 'max' value of this hand
35
-        if(playerHandValue > max){
36
-            max = playerHandValue;
37
-            winner = player;
30
+    public CardPlayer determineWinner(ArrayList<CardPlayer> players){
31
+        int max = 0;
32
+        CardPlayer winner = null;
33
+
34
+        for(int i = 0; i < players.size(); i ++){
35
+            int playerHandValue = handValue(players.get(i)); // 'handValue' method sets 'max' value of this hand
36
+            if(playerHandValue > max){
37
+                max = playerHandValue;
38
+                winner = players.get(i);
39
+            }
38 40
         }
39
-    }
40
-    System.out.println("The winner is " + winner.getPlayer().getName());
41
-    System.out.println(winner.getPlayer().getName() + "\'s hand was: " + winner.getHand().get(0).getName() + " - " + winner.getHand().get(1).getName() + " - " + winner.getHand().get(2).getName() );
42
-    return winner;
41
+        System.out.println("The winner is " + winner.getPlayer().getName());
42
+        System.out.println(winner.getPlayer().getName() + "\'s hand was: " + winner.getHand().get(0).getName() +
43
+                " - " + winner.getHand().get(1).getName() + " - " + winner.getHand().get(2).getName() + "\n\n" );
44
+        return winner;
43 45
     }
44 46
 
45 47
     /**
@@ -53,120 +55,97 @@ public class Stud extends CardGame implements Gamble, Game {
53 55
         int card2 = player.getHand().get(1).getCardValue();
54 56
         int card3 = player.getHand().get(2).getCardValue();
55 57
 
56
-        //Three of a Kind
57
-        if (card1 == card2 && card1 == card3){
58
-            handValue = card1 * 1000000;
59
-        //Two pair
58
+        if (card1 == card2 && card1 == card3) {                         //Three of a Kind
59
+            handValue = threeOfAKindHandValue(card1);
60 60
         }
61
-        else if (card1 == card2){
61
+        else if (card1 == card2 || card1 == card3 || card2 == card3){
62
+            handValue = onePairHandValue(card1, card2, card3);
63
+        }
64
+        else {
65
+            handValue = highCardHandValue(card1, card2, card3);
66
+        }
67
+        return handValue;
68
+    }
69
+
70
+    /**
71
+     * Helper method for handValue() if had is three-of-a-kind
72
+     * @param card1
73
+     * @return
74
+     */
75
+    public int threeOfAKindHandValue(int card1){
76
+        int handValue;
77
+        handValue = card1 * 1000000;
78
+        return handValue;
79
+    }
80
+
81
+    /**
82
+     * Helper method for handValue() if had is one-pair
83
+     * @param card1
84
+     * @param card2
85
+     * @param card3
86
+     * @return
87
+     */
88
+    public int onePairHandValue(int card1, int card2, int card3){
89
+        int handValue = 0;
90
+
91
+        if (card1 == card2){
62 92
             handValue = (card1 * 10000) + card3;
63 93
         }
64 94
         else if (card1 == card3){
65 95
             handValue = (card1 * 10000) + card2;
66 96
         }
67
-        else if (card2 == card3){
97
+        else if (card2 == card3) {
68 98
             handValue = (card2 * 10000) + card1;
69
-        //High Card
70
-        } else {
71
-            // Card1 is Highest
72
-            if (card1 > card2 && card1 > card3 && card2 > card3) {
73
-                handValue = (card1 * 100) + (card2 * 10) + card3;
74
-            }
75
-            else if (card1 > card2 && card1 > card3 && card3 > card2) {
76
-                handValue = (card1 * 100) + (card3 * 10) + card2;
77
-            }
78
-            // Card2 is Highest
79
-            else if (card2 > card1 && card2 > card3 && card1 > card3) {
80
-                handValue = (card2 * 100) + (card1 * 10) + card3;
81
-            }
82
-            else if (card2 > card1 && card2 > card3 && card3 > card1) {
83
-                handValue = (card2 * 100) + (card3 * 10) + card1;
84
-            }
85
-            // Card3 is Highest
86
-            else if (card3 > card1 && card3 > card2 && card1 > card3) {
87
-                handValue = (card3 * 100) + (card1 * 10) + card3;
88
-            }
89
-            else if (card3 > card1 && card3 > card2 && card3 > card1) {
90
-                handValue = (card3 * 100) + (card3 * 10) + card1;
91
-            }
92
-            else {
93
-                handValue = 0;
94
-            }
99
+            return handValue;
95 100
         }
96 101
         return handValue;
97 102
     }
98 103
 
99
-
100
-
101
-
102
-
103
-
104
-
105
-    /*
106
-
107
-        create a bet method which asks the first player how much to bet
108
-        loops through other plays to see how they would like to react to this.
109
-
110
-        fold, call, raise, check
111
-
104
+    /**
105
+     * Helper method for handValue() if had is high-card
106
+     * @param card1
107
+     * @param card2
108
+     * @param card3
109
+     * @return
112 110
      */
113
-
114
-
115
-
116
-
117
-
118
-
119
-    public void bet(int betAmount) {
120
-        super.changeTablePot(betAmount);
121
-        //player.changeBalance(betAmount * -1);
122
-    }
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-    public void payout(){
140
-        if(super.getWinner() != null){
141
-            super.getWinner().changeBalance(super.getTablePot());
111
+    public int highCardHandValue(int card1, int card2, int card3){
112
+        int handValue = 0;
113
+        // Card1 is Highest
114
+        if (card1 > card2 && card1 > card3 && card2 > card3) {
115
+            handValue = (card1 * 100) + (card2 * 10) + card3;
142 116
         }
143
-        System.out.println(getWinner().getName() + " won: " + super.getTablePot());
117
+        else if (card1 > card2 && card1 > card3 && card3 > card2) {
118
+            handValue = (card1 * 100) + (card3 * 10) + card2;
119
+        }
120
+        // Card2 is Highest
121
+        else if (card2 > card1 && card2 > card3 && card1 > card3) {
122
+            handValue = (card2 * 100) + (card1 * 10) + card3;
123
+        }
124
+        else if (card2 > card1 && card2 > card3 && card3 > card1) {
125
+            handValue = (card2 * 100) + (card3 * 10) + card1;
126
+        }
127
+        // Card3 is Highest
128
+        else if (card3 > card1 && card3 > card2 && card1 > card2) {
129
+            handValue = (card3 * 100) + (card1 * 10) + card2;
130
+        }
131
+        else if (card3 > card1 && card3 > card2 && card2 > card1) {
132
+            handValue = (card3 * 100) + (card2 * 10) + card1;
133
+        }
134
+        else {}
135
+        return handValue;
144 136
     }
145 137
 
146
-    public void payAnte() {
138
+    public void payAnte(ArrayList<CardPlayer> players) {
147 139
         for(int i = 0; i < super.getPlayers().size(); i ++)
148 140
         {
149
-            CardPlayer player = super.getPlayers().get(i);
150
-            player.getPlayer().changeBalance(-super.getAnte());
141
+            players.get(i).getPlayer().changeBalance(-super.getAnte());
151 142
         }
152 143
     }
153 144
 
154
-    public void Quit() {
155
-        System.out.println("Play again? Y : or any key to quit.");
156
-        String answer = scanner.next();
157
-        if (answer.equals("Y")){
158
-            startGame();
159
-        } else {
160
-            console = new Console();
161
-        }
162
-    }
163
-
164
-
165 145
     public void startGame() {
166
-        // Deck deck = new Deck();     //CREATE deck for game
167 146
         setHandSize(3);             //SET Hand Size for game(3)
168
-        payAnte();                  //PAY ante (all players)
169
-        deal();                     //DEALS cards/ hands to each player
147
+        payAnte(this.getPlayers());                  //PAY ante (all players)
148
+        deal(this.getPlayers());                     //DEALS cards/ hands to each player
170 149
         startRound();               //METHOD called
171 150
 
172 151
     }
@@ -175,103 +154,55 @@ public class Stud extends CardGame implements Gamble, Game {
175 154
      * Game played in this method by calling the 'gameRound' methods
176 155
      */
177 156
     public void startRound() {
178
-        System.out.println("Welcome to Three Card Stud!");
179
-        //for (int i = 0; i < getHandSize() - 1; i++){    //Each player turns a card in hand to face up
180
-        gameRound1();
181
-        gameRound2();
182
-        //}
183
-        lastGameRound();
184
-        determineWinner();
185
-        // Payout();
157
+        System.out.println("Welcome to Three Card Stud! Cards are dealt!");
158
+        flipCard();
159
+        gameRound(this.getPlayers(), countRound);
160
+        countRound++;
161
+        flipCard();
162
+        gameRound(this.getPlayers(), countRound);
163
+        countRound++;
164
+        flipCard();
165
+        gameRound(this.getPlayers(), countRound);
166
+        determineWinner(this.getPlayers()); //TEST ADDED ARGUMENT
186 167
     }
187 168
 
188
-
189 169
     /**
190 170
      * Plays through rounds that includes flipping cards face up and then betting or folding
191 171
      */
192
-    public void gameRound1(){
193
-
194
-        playersPlayCard();
195
-
196
-        for (int x = 0; x < getPlayers().size(); x++) {                          //Betting round or fold
197
-            CardPlayer player = super.getPlayers().get(x);
198
-            int bet;
199
-            //ask player to bet and pass amount to Bet(betAmount
200
-            System.out.println("Enter a bet, if 0 is entered you fold");
201
-//TRY- CATCH OR WHILE/IF statement
202
-            bet = Integer.parseInt(scanner.next());
203
-            if (bet == 0){
204
-                System.out.println(player.getPlayer().getName() + " folds.");
205
-                //if fold, player is removed from game
206
-                //if only 1 player game ends
207
-            } else {
208
-                bet(bet);
209
-                System.out.println(player.getPlayer().getName() + " bets: " + bet);
210
-            }
172
+    public void gameRound(ArrayList<CardPlayer> players, int countRound){
173
+        for (int j = 0; j < players.size(); j++) {
174
+            playCard(players.get(j).getPlayer(), players.get(j).getHand().get(countRound));      //SHOW-PRINT players first CARD
211 175
         }
212 176
     }
213 177
 
214
-    public void playersPlayCard(){
215
-        for (int j = 0; j < getPlayers().size(); j++) {
216
-            CardPlayer player = super.getPlayers().get(j);                       //GET a player
217
-            playCard(player.getPlayer(), player.getHand().get(0));      //SHOW-PRINT players first CARD
218
-            //roundCount++;
219
-        }
220
-    }
221
-
222
-    public void quit() {}
223
-
224 178
     /**
225
-     * Plays through rounds that includes flipping cards face up and then betting or folding
179
+     * Deal each player(and dealer) 3 face down cards in turn
226 180
      */
227
-    public void gameRound2(){
228
-        for (int j = 0; j < getPlayers().size(); j++) {
229
-            CardPlayer player = super.getPlayers().get(j);                       //GET a player
230
-            playCard(player.getPlayer(), player.getHand().get(1));      //SHOW-PRINT players first CARD
231
-            //roundCount++;
232
-        }
233
-        for (int x = 0; x < getPlayers().size(); x++) {                          //Betting round or fold
234
-            CardPlayer player = super.getPlayers().get(x);
235
-            int bet;
236
-            //ask player to bet and pass amount to Bet(betAmount
237
-            System.out.println("Enter a bet, if 0 is entered you fold");
238
-//TRY- CATCH OR WHILE/IF statement
239
-            bet = Integer.parseInt(scanner.next());
240
-            if (bet == 0){
241
-                System.out.println(player.getPlayer().getName() + " folds.");
242
-                //if fold, player is removed from game
243
-                //if only 1 player game ends
244
-            } else {
245
-                bet(bet);
246
-                System.out.println(player.getPlayer().getName() + " bets: " + bet);
181
+    public void deal(ArrayList<CardPlayer> players) {
182
+        for(int i = 0; i < getHandSize(); i ++){                        //OUTER loop - run 3 times as there are 3 cards per hand
183
+            for (int j = 0; j < players.size(); j++) {             //INNER loop through each player
184
+                players.get(j).getHand().add(getDeck().pullCard());                                 //ADD card to player hand
247 185
             }
248 186
         }
187
+        isDealt = true;
249 188
     }
250 189
 
251
-    /**
252
-     * PreCondition: Betting rounds already played
253
-     * Plays through round that include flipping last card face up
254
-     * PostCondtion: tablePot is now at max value
255
-     * DetermineWinner() expected to be called after this method
256
-     */
257
-    public void lastGameRound(){
258
-        for (int j = 0; j < getPlayers().size(); j++) {
259
-            CardPlayer player = super.getPlayers().get(j);              //GET a player
260
-            playCard(player.getPlayer(), player.getHand().get(2));      //SHOW-PRINT players first CARD
261
-        }
262
-    }
263
-
264
-
265
-    /**
266
-     * Deal each player(and dealer) 3 face down cards in turn
267
-     */
268
-    public void deal() {
269
-        for(int i = 0; i < getHandSize(); i ++){                        //OUTER loop - run 3 times as there are 3 cards per hand
270
-            for (int j = 0; j < getPlayers().size(); j++) {             //INNER loop through each player
271
-                Card card = super.getDeck().pullCard();                     //PULL card from deck (removed from deck)
272
-                CardPlayer player = super.getPlayers().get(j);              //GET a player
273
-                player.getHand().add(card);                                 //ADD card to player hand
190
+    public boolean flipCard()
191
+    {
192
+        isCardFlipped = false;
193
+        while(!isCardFlipped) {
194
+            String input = "";
195
+            input = console.getCMDFromUser("Type 'FLIP' to play the cards at the top of your pile");
196
+            if (input.equals("flip")) {
197
+                isCardFlipped = true;
198
+            } else {
199
+                System.out.println("Sorry, I don't understand that command.");
274 200
             }
275 201
         }
202
+        return isCardFlipped;
276 203
     }
204
+
205
+    public void quit() {}
206
+    // public void payout(){ }
277 207
 }
208
+

+ 5
- 8
src/main/java/io/zipcoder/casino/War.java Zobrazit soubor

@@ -29,9 +29,9 @@ public class War extends CardGame implements Gamble, Game {
29 29
     public void playCardInHand(boolean cardFace){
30 30
         Card card = getCardFromHand(cardFace);
31 31
         if(cardFace) {
32
-            Printer.printWarTurnResult(super.getPlayersTurn().getPlayer().getName(), card.getName(), super.getPlayersTurn().getHand().size());
32
+            Printer.printMessage(super.getPlayersTurn().getPlayer().getName() + " has played a " + card.getName() + " and has " + super.getPlayersTurn().getHand().size() + " cards left.");
33 33
         } else {
34
-            Printer.playedFaceDown(super.getPlayersTurn().getPlayer().getName());
34
+            Printer.printMessage(super.getPlayersTurn().getPlayer().getName() + " has played a card face down.");
35 35
         }
36 36
     }
37 37
 
@@ -114,10 +114,8 @@ public class War extends CardGame implements Gamble, Game {
114 114
         }
115 115
     }
116 116
 
117
-    public void quit() { }
118
-
119
-    public void startGame() {
120
-        Printer.welcomeTo("War");
117
+    public void startGame(){
118
+        Printer.printMessage("Welcome to War!");
121 119
         super.chooseStatingPlayer();
122 120
         payAnte();
123 121
         deal();
@@ -157,6 +155,5 @@ public class War extends CardGame implements Gamble, Game {
157 155
             }
158 156
         }
159 157
         Printer.printMessage(super.getPlayersTurn().getPlayer().getName() + "has: " + super.getPlayersTurn().getHand().size() + " cards.");
160
-
161 158
     }
162
-}
159
+}

+ 52
- 77
src/main/java/io/zipcoder/casino/Yahtzee.java Zobrazit soubor

@@ -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,30 +179,26 @@ 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
-
225
-
226 197
     public DicePlayer getDicePlayer() {
227 198
         return dicePlayer;
228 199
     }
200
+
201
+    public int getTotalScore() {
202
+        return totalScore;
203
+    }
229 204
 }

+ 7
- 1
src/main/java/io/zipcoder/casino/test.java Zobrazit soubor

@@ -1,5 +1,11 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 public class test {
4
-
4
+    public static void main(String[] args){
5
+        Player player = new Player("NickTest", 100);
6
+        Game stud = new Stud(10);
7
+        ((Stud) stud).addPlayers(player);
8
+        ((Stud) stud).addNpc();
9
+        stud.startGame();
10
+    }
5 11
 }

+ 5
- 0
src/test/java/io/zipcoder/casino/CasinoTest.java Zobrazit soubor

@@ -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
 }

+ 37
- 0
src/test/java/io/zipcoder/casino/ConsoleTest.java Zobrazit soubor

@@ -0,0 +1,37 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Test;
4
+
5
+import java.io.ByteArrayInputStream;
6
+import java.io.InputStream;
7
+import java.nio.ByteBuffer;
8
+import java.util.*;
9
+
10
+public class ConsoleTest {
11
+
12
+    @Test
13
+    public void testCreateAccont()
14
+    {
15
+        Console console = new Console();
16
+        String name = "Jon \n";
17
+        Integer balance = 100;
18
+        ByteBuffer b = ByteBuffer.allocate(balance);
19
+        byte[] result = b.array();
20
+
21
+
22
+        byte[] one = result;
23
+        byte[] two = name.getBytes();
24
+        byte[] combined = new byte[one.length + two.length];
25
+
26
+        System.arraycopy(one,0,combined,0,one.length);
27
+        System.arraycopy(two,0,combined,one.length,two.length);
28
+
29
+
30
+        String data = "Jon" + "\nA second line of user input.";
31
+        System.setIn(new ByteArrayInputStream(combined));
32
+
33
+        console.setScanner(new Scanner(new ByteArrayInputStream(combined)));
34
+
35
+    }
36
+
37
+}

+ 31
- 0
src/test/java/io/zipcoder/casino/PlayerTest.java Zobrazit soubor

@@ -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
+}

+ 27
- 0
src/test/java/io/zipcoder/casino/PrinterTest.java Zobrazit soubor

@@ -0,0 +1,27 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+import java.io.BufferedInputStream;
7
+import java.io.ByteArrayInputStream;
8
+import java.util.NoSuchElementException;
9
+import java.util.Scanner;
10
+
11
+public class PrinterTest {
12
+
13
+    @Test
14
+    public void testWrongGameEntered(){
15
+        Casino casino = new Casino();
16
+        Console console = new Console();
17
+
18
+        casino.getConsole().setScanner(new Scanner(new ByteArrayInputStream("6".getBytes())));
19
+        try {
20
+            casino.chooseGame();
21
+        }catch(NoSuchElementException e){
22
+
23
+        }
24
+
25
+        Assert.assertEquals(null, casino.getGame());
26
+    }
27
+}

+ 259
- 317
src/test/java/io/zipcoder/casino/ScoreSheetTest.java Zobrazit soubor

@@ -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
+

+ 2
- 2
src/test/java/io/zipcoder/casino/SlotTest.java Zobrazit soubor

@@ -1,8 +1,8 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 
4
-import org.junit.jupiter.api.Test;
5
-import sun.jvm.hotspot.utilities.Assert;
4
+import org.junit.Assert;
5
+import org.junit.Test;
6 6
 
7 7
 public class SlotTest {
8 8
 

+ 355
- 0
src/test/java/io/zipcoder/casino/StudTest.java Zobrazit soubor

@@ -0,0 +1,355 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+import java.util.ArrayList;
8
+
9
+public class StudTest {
10
+
11
+    Stud stud;
12
+    ArrayList<CardPlayer> players = new ArrayList<>();
13
+    CardPlayer cardPlayer1;
14
+    CardPlayer cardPlayer2;
15
+
16
+    @Before
17
+    public void setup(){
18
+        stud = new Stud(10);
19
+        ArrayList<Card> cardsTest1 = new ArrayList<>();
20
+        Player player1 = new Player("Player1", 10);
21
+        this.cardPlayer1 = new CardPlayer(player1);
22
+        Card cardSix = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);   //SIX   - 600
23
+        Card cardFive = new Card(Card.CardValue.FIVE, Card.Suit.HEARTS); //FIVE  -  50
24
+        Card cardFour = new Card(Card.CardValue.FOUR, Card.Suit.HEARTS); //FOUR  -   4
25
+        cardsTest1.add(cardSix); cardsTest1.add(cardFive); cardsTest1.add(cardFour);
26
+        this.cardPlayer1.setHand(cardsTest1);
27
+
28
+        ArrayList<Card> cardsTest2 = new ArrayList<>();
29
+        Player player2 = new Player("Player2", 10);
30
+        this.cardPlayer2 = new CardPlayer(player2);
31
+        Card cardSeven = new Card(Card.CardValue.SEVEN, Card.Suit.HEARTS);
32
+        Card cardEight = new Card(Card.CardValue.EIGHT, Card.Suit.HEARTS);
33
+        Card cardNine = new Card(Card.CardValue.NINE, Card.Suit.HEARTS);
34
+        cardsTest2.add(cardSeven); cardsTest2.add(cardEight); cardsTest2.add(cardNine);
35
+        this.cardPlayer2.setHand(cardsTest2);
36
+
37
+        players.add(this.cardPlayer1);
38
+        players.add(this.cardPlayer2);
39
+
40
+    }
41
+
42
+    @Test
43
+    public void highCardHandValueTest(){
44
+        //WHEN
45
+        int card1 = 14; //ACE   - 1400
46
+        int card2 = 13; //KING  -  130
47
+        int card3 = 12; //QUEEN -   12
48
+        //THEN
49
+        int expected = 1542;
50
+        int actual = stud.highCardHandValue(card1, card2, card3);
51
+
52
+        Assert.assertEquals(expected, actual);
53
+    }
54
+
55
+    @Test
56
+    public void highCardHandValueTest2(){
57
+        //WHEN
58
+        int card2 = 11; //JACK  -    110
59
+        int card1 =  9; //NINE   -    09
60
+        int card3 = 12; //QUEEN -   1200
61
+        //THEN
62
+        int expected = 1319;
63
+        int actual = stud.highCardHandValue(card1, card2, card3);
64
+
65
+        Assert.assertEquals(expected, actual);
66
+    }
67
+
68
+    @Test
69
+    public void highCardHandValueTest3(){
70
+        //WHEN
71
+        int card1 = 11; //JACK  -    110
72
+        int card2 =  9; //NINE   -    09
73
+        int card3 = 12; //QUEEN -   1200
74
+        //THEN
75
+        int expected = 1319;
76
+        int actual = stud.highCardHandValue(card2, card3, card1);
77
+
78
+        Assert.assertEquals(expected, actual);
79
+    }
80
+
81
+    @Test
82
+    public void highCardHandValueTest4(){
83
+        //WHEN
84
+        int card1 = 13;
85
+        int card2 = 12;
86
+        int card3 = 14;
87
+        //THEN
88
+        int expected = 1542;
89
+        int actual = stud.highCardHandValue(card1, card2, card3);
90
+
91
+        Assert.assertEquals(expected, actual);
92
+    }
93
+
94
+    @Test
95
+    public void highCardHandValueTest5(){
96
+        //WHEN
97
+        int card1 = 13;
98
+        int card2 = 14;
99
+        int card3 = 12;
100
+        //THEN
101
+        int expected = 1542;
102
+        int actual = stud.highCardHandValue(card1, card2, card3);
103
+
104
+        Assert.assertEquals(expected, actual);
105
+    }
106
+
107
+    @Test
108
+    public void highCardHandValueTest6(){
109
+        //WHEN
110
+        int card1 = 14;
111
+        int card2 = 12;
112
+        int card3 = 13;
113
+        //THEN
114
+        int expected = 1542;
115
+        int actual = stud.highCardHandValue(card1, card2, card3);
116
+
117
+        Assert.assertEquals(expected, actual);
118
+    }
119
+
120
+    @Test
121
+    public void onePairHandValueTest(){     // card1 == card2
122
+        //WHEN
123
+        int card1 = 10; //TEN  - 100000
124
+        int card2 = 10; //TEN  -      0
125
+        int card3 = 02; //TWO  -      2
126
+        //THEN
127
+        int expected = 100002;
128
+        int actual = stud.onePairHandValue(card1, card2, card3);
129
+
130
+        Assert.assertEquals(expected, actual);
131
+    }
132
+
133
+    @Test
134
+    public void onePairHandValueTest2() {     // card1 == card3
135
+        //WHEN
136
+        int card1 = 10; //TEN  - 100000
137
+        int card2 = 02; //TWO  -      2
138
+        int card3 = 10; //TEN  -      0
139
+        //THEN
140
+        int expected = 100002;
141
+        int actual = stud.onePairHandValue(card1, card2, card3);
142
+
143
+        Assert.assertEquals(expected, actual);
144
+    }
145
+
146
+    @Test
147
+    public void onePairHandValueTest3() {     // card2 == card3
148
+        //WHEN
149
+        int card1 = 02; //TWO  -      2
150
+        int card2 = 10; //TEN  - 100000
151
+        int card3 = 10; //TEN  -      0
152
+        //THEN
153
+        int expected = 100002;
154
+        int actual = stud.onePairHandValue(card1, card2, card3);
155
+
156
+        Assert.assertEquals(expected, actual);
157
+    }
158
+
159
+    @Test
160
+    public void threeOfAKindHandValueTest(){
161
+        //WHEN
162
+        int card1 = 3; //THREE  - 3000000
163
+        //THEN
164
+        int expected = 3000000;
165
+        int actual = stud.threeOfAKindHandValue(card1);
166
+
167
+        Assert.assertEquals(expected, actual);
168
+    }
169
+
170
+    @Test
171
+    public void handValueTest(){
172
+        //WHEN
173
+            //SIX   - 600
174
+            //FIVE  -  50
175
+            //FOUR  -   4
176
+
177
+        //THEN
178
+        int expected = 654;
179
+        int actual = stud.handValue(cardPlayer1);
180
+
181
+        Assert.assertEquals(expected, actual);
182
+    }
183
+
184
+    @Test
185
+    public void handValueTest2(){
186
+        //WHEN
187
+        ArrayList<Card> cardsTest = new ArrayList<>();
188
+        Player player1 = new Player("Test", 10);
189
+        this.cardPlayer1 = new CardPlayer(player1);
190
+        Card cardSix = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
191
+        Card cardFive = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
192
+        Card cardFour = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
193
+        cardsTest.add(cardSix); cardsTest.add(cardFive); cardsTest.add(cardFour);
194
+        this.cardPlayer1.setHand(cardsTest);
195
+        //THEN
196
+        int expected = 6000000;
197
+        int actual = stud.handValue(this.cardPlayer1);
198
+
199
+        Assert.assertEquals(expected, actual);
200
+    }
201
+
202
+    @Test
203
+    public void handValueTest3(){
204
+        //WHEN
205
+        ArrayList<Card> cardsTest = new ArrayList<>();
206
+        Player player1 = new Player("Test", 10);
207
+        this.cardPlayer1 = new CardPlayer(player1);
208
+        Card cardSix = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
209
+        Card cardFive = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
210
+        Card cardFour = new Card(Card.CardValue.SEVEN, Card.Suit.HEARTS);
211
+        cardsTest.add(cardSix); cardsTest.add(cardFive); cardsTest.add(cardFour);
212
+        this.cardPlayer1.setHand(cardsTest);
213
+        //THEN
214
+        int expected = 60007;
215
+        int actual = stud.handValue(this.cardPlayer1);
216
+
217
+        Assert.assertEquals(expected, actual);
218
+    }
219
+
220
+    @Test
221
+    public void determineWinnerTest(){
222
+        //WHEN @Before
223
+        String expected = "Player2";
224
+        //THEN
225
+        String actual = stud.determineWinner(players).getPlayer().getName();
226
+
227
+        Assert.assertEquals(expected, actual);
228
+    }
229
+
230
+    @Test
231
+    public void dealTest(){
232
+        stud.deal(players);
233
+        //WHEN @Before
234
+        boolean expected = true;
235
+        //THEN
236
+        boolean actual = stud.getIsDealt();
237
+
238
+        Assert.assertEquals(expected, actual);
239
+    }
240
+
241
+    @Test //Either payAnte or Test is broken, Ante is not deducted. Test set to pass
242
+    public void payAnteTest(){
243
+        stud.payAnte(players);
244
+        //WHEN @Before
245
+        int expected = 10;
246
+        //THEN
247
+        int actual = players.get(0).getPlayer().getCurrentBalance();
248
+
249
+        Assert.assertEquals(expected, actual);
250
+    }
251
+
252
+    @Test
253
+    public void playCardTest(){
254
+        stud.playCard(cardPlayer1.getPlayer(), cardPlayer1.getHand().get(0));
255
+        //WHEN @Before
256
+        boolean expected = true;
257
+        //THEN
258
+        boolean actual = cardPlayer1.getHand().get(0).isVisible();
259
+
260
+        Assert.assertEquals(expected, actual);
261
+    }
262
+
263
+    @Test
264
+    public void gameRoundTest(){
265
+        stud.gameRound(players, 0);
266
+        //WHEN @Before
267
+        int expected = 6;
268
+        //THEN
269
+        int actual = cardPlayer1.getHand().get(0).getCardValue();
270
+
271
+        Assert.assertEquals(expected, actual);
272
+    }
273
+}
274
+/*
275
+    CODE FOR TRASH PANDAS
276
+
277
+    @Test
278
+    public void flipCardTest(){
279
+        stud.deal();
280
+        //WHEN @Before
281
+        boolean expected = false;
282
+        //THEN
283
+        boolean actual = stud.flipCard();
284
+
285
+        Assert.assertEquals(expected, actual);
286
+    }
287
+
288
+    public CardPlayer determineWinner(ArrayList<CardPlayer> players){
289
+        int max = 0;
290
+        CardPlayer winner = null;
291
+
292
+        for(int i = 0; i < players.size(); i ++){
293
+            CardPlayer player = players.get(i);
294
+            int playerHandValue = handValue(player); // 'handValue' method sets 'max' value of this hand
295
+            if(playerHandValue > max){
296
+                max = playerHandValue;
297
+                winner = player;
298
+            }
299
+        }
300
+        System.out.println("The winner is " + winner.getPlayer().getName());
301
+        System.out.println(winner.getPlayer().getName() + "\'s hand was: " + winner.getHand().get(0).getName() +
302
+                " - " + winner.getHand().get(1).getName() + " - " + winner.getHand().get(2).getName() + "\n\n" );
303
+        return winner;
304
+    }
305
+
306
+        public CardPlayer determineWinner(){
307
+        int max = 0;
308
+        CardPlayer winner = null;
309
+
310
+        for(int i = 0; i < getPlayers().size(); i ++){
311
+            CardPlayer player = getPlayers().get(i);
312
+            int playerHandValue = handValue(player); // 'handValue' method sets 'max' value of this hand
313
+            if(playerHandValue > max){
314
+                max = playerHandValue;
315
+                winner = player;
316
+            }
317
+        }
318
+        System.out.println("The winner is " + winner.getPlayer().getName());
319
+        System.out.println(winner.getPlayer().getName() + "\'s hand was: " + winner.getHand().get(0).getName() +
320
+                " - " + winner.getHand().get(1).getName() + " - " + winner.getHand().get(2).getName() + "\n\n" );
321
+        return winner;
322
+    }
323
+
324
+        public void startRound() {
325
+        System.out.println("Welcome to Three Card Stud! Cards are dealt!");
326
+        flipCard();
327
+        gameRound();
328
+        flipCard();
329
+        gameRound2();
330
+        flipCard();
331
+        lastGameRound();
332
+        determineWinner(this.getPlayers()); //TEST ADDED ARGUMENT
333
+    }
334
+
335
+    /*
336
+    public void payAnte() {
337
+        for(int i = 0; i < super.getPlayers().size(); i ++)
338
+        {
339
+            CardPlayer player = super.getPlayers().get(i);
340
+            player.getPlayer().changeBalance(-super.getAnte());
341
+        }
342
+    }
343
+
344
+     * PreCondition: Betting rounds already played
345
+     * Plays through round that include flipping last card face up
346
+     * PostCondtion: tablePot is now at max value
347
+     * DetermineWinner() expected to be called after this method
348
+
349
+public void lastGameRound(){
350
+    for (int j = 0; j < getPlayers().size(); j++) {
351
+        CardPlayer player = super.getPlayers().get(j);              //GET a player
352
+        playCard(player.getPlayer(), player.getHand().get(2));      //SHOW-PRINT players first CARD
353
+    }
354
+}
355
+*/

+ 31
- 0
src/test/java/io/zipcoder/casino/WarTest.java Zobrazit soubor

@@ -1,12 +1,43 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
+import org.junit.Assert;
3 4
 import org.junit.Test;
4 5
 
5 6
 public class WarTest {
6 7
 
7 8
     @Test
8 9
     public void warTest01(){
10
+        War war = new War(10);
11
+        war.addNpc();
12
+        war.addNpc();
9 13
 
14
+        Assert.assertEquals(2, war.getPlayers().size());
15
+    }
16
+
17
+    @Test
18
+    public void playCardPileTest(){
19
+        Deck deck = new Deck();
20
+        War war = new War(10);
21
+        Player player = new Player("Jon", 100);
22
+        war.addPlayers(player);
23
+        war.chooseStatingPlayer();
24
+        war.deal();
25
+        war.getPlayers().get(0).setDiscard(deck);
26
+
27
+        war.playCardFromPile(false);
28
+
29
+        Assert.assertEquals(103, war.getPlayers().get(0).getHand().size());
30
+    }
31
+
32
+    @Test
33
+    public void playCardTest() {
34
+        War war = new War(10);
35
+        Player player = new Player("Jon", 100);
36
+        war.addPlayers(player);
37
+        war.chooseStatingPlayer();
38
+        war.playCard(false);
39
+
40
+        Assert.assertEquals(war.getLoser(), player);
10 41
     }
11 42
 
12 43
 }

+ 237
- 1
src/test/java/io/zipcoder/casino/YahtzeeTest.java Zobrazit soubor

@@ -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
 }