Simran Bhutani преди 6 години
родител
ревизия
03e318a12a

+ 2
- 0
.gitignore Целия файл

@@ -9,6 +9,8 @@ local.properties
9 9
 .settings/
10 10
 .loadpath
11 11
 .recommenders
12
+.DS_Store
13
+
12 14
 
13 15
 # External tool builders
14 16
 .externalToolBuilders/

BIN
src/.DS_Store Целия файл


BIN
src/main/.DS_Store Целия файл


BIN
src/main/java/.DS_Store Целия файл


BIN
src/main/java/io/.DS_Store Целия файл


BIN
src/main/java/io/zipcoder/.DS_Store Целия файл


+ 5
- 3
src/main/java/io/zipcoder/casino/CardGame.java Целия файл

@@ -19,9 +19,7 @@ public abstract class CardGame {
19 19
     private Deck deck = new Deck();
20 20
 
21 21
 
22
-    CardGame(int minBet, int maxBet, int ante){
23
-        this.minBet = minBet;
24
-        this.maxBet = maxBet;
22
+    CardGame(int ante){
25 23
         this.ante = ante;
26 24
     }
27 25
 
@@ -81,6 +79,10 @@ public abstract class CardGame {
81 79
         return handSize;
82 80
     }
83 81
 
82
+    public void setHandSize(int handSize) {
83
+        this.handSize = handSize;
84
+    }
85
+
84 86
     public CardPlayer getPlayersTurn() {
85 87
         return playersTurn;
86 88
     }

+ 4
- 0
src/main/java/io/zipcoder/casino/CardPlayer.java Целия файл

@@ -17,6 +17,10 @@ public class CardPlayer {
17 17
         return hand;
18 18
     }
19 19
 
20
+    public void setHand(ArrayList<Card> hand) {
21
+        this.hand = hand;
22
+    }
23
+
20 24
     public Player getPlayer() {
21 25
         return player;
22 26
     }

+ 36
- 16
src/main/java/io/zipcoder/casino/Console.java Целия файл

@@ -8,7 +8,11 @@ public class Console {
8 8
     private ArrayList<String> gameLib = new ArrayList<>();
9 9
     private Game game = null;
10 10
     private Player player;
11
-    private boolean running = true;
11
+    public boolean running = true;
12
+
13
+    private ArrayList<Player> players = new ArrayList<>();
14
+
15
+
12 16
 
13 17
     Console(){
14 18
         gameLib.add("yahtzee");
@@ -16,6 +20,7 @@ public class Console {
16 20
         gameLib.add("stud");
17 21
         gameLib.add("slot");
18 22
         gameLib.add("quit");
23
+
19 24
     }
20 25
 
21 26
     public void createAccount()
@@ -26,9 +31,14 @@ public class Console {
26 31
         System.out.println("How much money are you bringing to the table?");
27 32
         int balance = getIntFromUser();
28 33
 
29
-        player = new Player(name, balance);
34
+        Player player = new Player(name, balance);
35
+        players.add(player);
30 36
     }
31 37
 
38
+    /**
39
+     * Currently required to make Stud a 2 player game, could later refactor to declare 'player' in createAccount method and pass to PlayerArray
40
+     */
41
+
32 42
     public void chooseGame()
33 43
     {
34 44
 
@@ -41,17 +51,19 @@ public class Console {
41 51
 
42 52
             switch (command) {
43 53
 
54
+
44 55
                 case 2:
45 56
                     int[] warMinMax = getMinMax();
46
-                    Game war = new War(warMinMax[0], warMinMax[1], 10);
57
+                    Game war = new War(10);
47 58
                     ((War) war).addPlayers(player);
48 59
                     ((War) war).addNpc();
49 60
                     war.startGame();
50 61
                     break;
51 62
 
63
+
52 64
                 case 3:
53 65
                     int[] studMinMax = getMinMax();
54
-                    Game stud = new Stud(studMinMax[0], studMinMax[1], 10);
66
+                    Game stud = new Stud(10);
55 67
                     ((Stud) stud).addPlayers(player);
56 68
                     ((Stud) stud).addNpc();
57 69
                     stud.startGame();
@@ -95,6 +107,7 @@ public class Console {
95 107
         return -1;
96 108
     }
97 109
 
110
+
98 111
     public int[] getMinMax(){
99 112
         Printer.getBet("minimum bet");
100 113
         int min = 0;
@@ -141,22 +154,29 @@ public class Console {
141 154
         return command;
142 155
     }
143 156
 
144
-    public String continueAskGame(){
157
+    public int getStudPlayers() {
158
+        int numOfStudPlayers = 0;
145 159
 
146
-        String command = "";
147
-
148
-        System.out.println("Please choose a game to play!");
149
-        command = getCommand();
160
+        while (numOfStudPlayers <= 1) {
150 161
 
151
-        if(gameLib.indexOf(command) == -1)
152
-        {
153
-            while(gameLib.indexOf(command) == -1)
154
-            {
155
-                Printer.noMatchingGameName(gameLib);
156
-                command = getCommand();
162
+            System.out.println("How many players are there?");
163
+            try {
164
+                numOfStudPlayers = scanner.nextInt();
165
+            } catch (InputMismatchException e) {
166
+                System.out.println("Please enter a number");
157 167
             }
158 168
         }
159
-        return command;
169
+
170
+        return numOfStudPlayers;
171
+    }
172
+
173
+    public void addStudPlayers(Game game){
174
+        int numPlayers = getStudPlayers();
175
+
176
+        for(int i = 1; i < numPlayers; i ++) {
177
+            createAccount();
178
+            ((Stud) game).addPlayers(players.get(i));
179
+        }
160 180
     }
161 181
 
162 182
     public void getGameIndex(){

+ 1
- 0
src/main/java/io/zipcoder/casino/Gamble.java Целия файл

@@ -1,6 +1,7 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 public interface Gamble {
4
+
4 5
      void bet(int betAmount);
5 6
      void payout();
6 7
 }

+ 8
- 0
src/main/java/io/zipcoder/casino/Printer.java Целия файл

@@ -27,4 +27,12 @@ public class Printer {
27 27
     public static void unacceptableMinBet(){
28 28
         System.out.println("Your bet must be above $0");
29 29
     }
30
+
31
+    public static void studHandsDealt(){
32
+        System.out.println("Each player Dealt 3 cards");
33
+    }
34
+
35
+    public static void showCard(Player player, Card card){
36
+        System.out.println(player.getName() + " shows a " + card.getName());
37
+    }
30 38
 }

+ 0
- 2
src/main/java/io/zipcoder/casino/ScoreSheet.java Целия файл

@@ -2,8 +2,6 @@
2 2
 
3 3
 package io.zipcoder.casino;
4 4
 
5
-import com.sun.tools.example.debug.expr.ASCII_UCodeESC_CharStream;
6
-
7 5
 import java.util.*;
8 6
 
9 7
 public class ScoreSheet {

+ 237
- 14
src/main/java/io/zipcoder/casino/Stud.java Целия файл

@@ -1,54 +1,277 @@
1 1
 
2 2
 package io.zipcoder.casino;
3
+import java.util.Scanner;
3 4
 
4 5
 public class Stud extends CardGame implements Gamble, Game {
5
-    public Stud(int minBet, int maxBet, int ante) {
6
-        super(minBet, maxBet, ante);
6
+    Scanner scanner = new Scanner(System.in);
7
+    Console console;
8
+    // private int roundCount = 0;
9
+
10
+    public Stud(int ante) {
11
+        super(ante);
12
+    }
13
+    
14
+    public void playCard(Player player, Card card) {
15
+        card.setVisibility(true);               //CARD isVISIBLE
16
+        Printer.showCard(player, card);         //PRINT card name to CONSOLE
7 17
     }
8 18
 
9
-    public void deal() {
19
+
20
+    public void fold(){
10 21
 
11 22
     }
12 23
 
13
-    public void determineWinner(){
24
+    /**
25
+     * Determine what player wins by looping through player array and then
26
+     * passing each hand to the 'handValue' method
27
+     */
28
+    public CardPlayer determineWinner(){
29
+    int max = 0;
30
+    CardPlayer winner = null;
14 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;
38
+        }
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;
15 43
     }
16 44
 
17
-    public void fold(){
45
+    /**
46
+     * Method will return a int value, larger value means strong hand to determine the winning player
47
+     * @param player
48
+     * @return
49
+     */
50
+    public int handValue(CardPlayer player){
51
+        int handValue = 0;
52
+        int card1 = player.getHand().get(0).getCardValue();
53
+        int card2 = player.getHand().get(1).getCardValue();
54
+        int card3 = player.getHand().get(2).getCardValue();
18 55
 
56
+        //Three of a Kind
57
+        if (card1 == card2 && card1 == card3){
58
+            handValue = card1 * 1000000;
59
+        //Two pair
60
+        }
61
+        else if (card1 == card2){
62
+            handValue = (card1 * 10000) + card3;
63
+        }
64
+        else if (card1 == card3){
65
+            handValue = (card1 * 10000) + card2;
66
+        }
67
+        else if (card2 == card3){
68
+            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
+            }
95
+        }
96
+        return handValue;
19 97
     }
20 98
 
21
-    /**
22
-     * Below 3 Implemented from Gamble
23
-     * @param betAmount
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
+
24 112
      */
113
+
114
+
115
+
116
+
117
+
118
+
25 119
     public void bet(int betAmount) {
120
+        super.changeTablePot(betAmount);
121
+        //player.changeBalance(betAmount * -1);
122
+    }
123
+
124
+
125
+
126
+
26 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());
142
+        }
143
+        System.out.println(getWinner().getName() + " won: " + super.getTablePot());
27 144
     }
28 145
 
29
-    public void payout() {
146
+    public void payAnte() {
147
+        for(int i = 0; i < super.getPlayers().size(); i ++)
148
+        {
149
+            CardPlayer player = super.getPlayers().get(i);
150
+            player.getPlayer().changeBalance(-super.getAnte());
151
+        }
152
+    }
30 153
 
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
+        }
31 162
     }
32 163
 
33 164
 
34
-    public void Ante(int anteAmount) {
165
+    public void startGame() {
166
+        // Deck deck = new Deck();     //CREATE deck for game
167
+        setHandSize(3);             //SET Hand Size for game(3)
168
+        payAnte();                  //PAY ante (all players)
169
+        deal();                     //DEALS cards/ hands to each player
170
+        startRound();               //METHOD called
35 171
 
36 172
     }
37 173
 
174
+    /**
175
+     * Game played in this method by calling the 'gameRound' methods
176
+     */
177
+    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();
186
+    }
187
+
38 188
 
39 189
     /**
40
-     * Below 3 Implemented from Game
190
+     * Plays through rounds that includes flipping cards face up and then betting or folding
41 191
      */
192
+    public void gameRound1(){
42 193
 
43
-    public void quit() {
194
+        playersPlayCard();
44 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
+            }
211
+        }
45 212
     }
46 213
 
47
-    public void startGame() {
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
+    }
48 221
 
222
+    public void quit() {}
223
+
224
+    /**
225
+     * Plays through rounds that includes flipping cards face up and then betting or folding
226
+     */
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);
247
+            }
248
+        }
249
+    }
250
+
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
+        }
49 262
     }
50 263
 
51
-    public void startRound() {
52 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
274
+            }
275
+        }
53 276
     }
54 277
 }

+ 16
- 7
src/main/java/io/zipcoder/casino/War.java Целия файл

@@ -14,8 +14,8 @@ public class War extends CardGame implements Gamble, Game {
14 14
     private Scanner scanner = new Scanner(System.in);
15 15
     private boolean war = false;
16 16
 
17
-    War(int minBet, int maxBet, int ante) {
18
-        super(minBet, maxBet, ante);
17
+    War(int ante) {
18
+        super(ante);
19 19
     }
20 20
 
21 21
 
@@ -97,7 +97,6 @@ public class War extends CardGame implements Gamble, Game {
97 97
                 war = true;
98 98
             }
99 99
         }
100
-
101 100
         if(war)
102 101
         {
103 102
             warMembers.add(winner);
@@ -152,9 +151,9 @@ public class War extends CardGame implements Gamble, Game {
152 151
 
153 152
     public void startRound() {
154 153
         while(super.getLoser() == null) {
155
-            System.out.println("Type play to play the top card from your pile.");
156
-            String input = scanner.next();
157
-            input = input.toLowerCase().trim();
154
+
155
+            String input = getCommand();
156
+
158 157
             if (input.equals("play")) {
159 158
                 //each player
160 159
                 for (CardPlayer player : super.getPlayers()) {
@@ -179,6 +178,13 @@ public class War extends CardGame implements Gamble, Game {
179 178
 
180 179
     }
181 180
 
181
+    public String getCommand(){
182
+        System.out.println("Type play to play the top card from your pile.");
183
+        String input = scanner.next();
184
+        input = input.toLowerCase().trim();
185
+        return input;
186
+    }
187
+
182 188
     public void deal() {
183 189
         //while there are cards in the deck
184 190
         while(super.getDeck().size() != 0){
@@ -195,6 +201,9 @@ public class War extends CardGame implements Gamble, Game {
195 201
                 super.getDeck().remove(card);
196 202
             }
197 203
         }
198
-        System.out.println(super.getPlayersTurn().getPlayer().getName() + " has: " + super.getPlayersTurn().getHand().size() + " cards.");
204
+
205
+        System.out.println(super.getPlayersTurn().getPlayer().getName() +
206
+                "has: " + super.getPlayersTurn().getHand().size() + " cards.");
207
+
199 208
     }
200 209
 }

+ 14
- 7
src/main/java/io/zipcoder/casino/Yahtzee.java Целия файл

@@ -21,13 +21,7 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
21 21
         this.betAmount = bid;
22 22
     }
23 23
 
24
-
25
-    @Override
26
-    public void quit() {
27
-
28
-    }
29
-
30
-    public void startGame() {
24
+    public void createGame() {
31 25
         Dice dice1 = new Dice();
32 26
         Dice dice2 = new Dice();
33 27
         Dice dice3 = new Dice();
@@ -39,6 +33,10 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
39 33
         dicePlayer.getCup()[2] = dice3;
40 34
         dicePlayer.getCup()[3] = dice4;
41 35
         dicePlayer.getCup()[4] = dice5;
36
+    }
37
+
38
+    public void startGame() {
39
+        createGame();
42 40
 
43 41
         System.out.println("How much would you like to bet on this game?");
44 42
         int betAmount = scanner.nextInt();
@@ -50,6 +48,7 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
50 48
         payout();
51 49
         dicePlayer.printBalanceAtEnd();
52 50
         System.out.println();
51
+
53 52
     }
54 53
 
55 54
     public void startRound() {
@@ -222,4 +221,12 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
222 221
         System.out.println("You won $" + payOut);
223 222
     }
224 223
 
224
+    @Override
225
+    public void quit() {
226
+
227
+    }
228
+
229
+    public DicePlayer getDicePlayer() {
230
+        return dicePlayer;
231
+    }
225 232
 }

+ 379
- 0
src/test/java/io/zipcoder/casino/ScoreSheetTest.java Целия файл

@@ -279,4 +279,383 @@ public class ScoreSheetTest {
279 279
 
280 280
     }
281 281
 
282
+    @Test
283
+    public void testSetRowCHANCE() {
284
+        //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
+        cup[0] = dice1;
293
+        cup[1] = dice2;
294
+        cup[2] = dice3;
295
+        cup[3] = dice4;
296
+        cup[4] = dice5;
297
+        for (Dice d : cup) {
298
+            d.roll();
299
+        }
300
+        int expected = dice1.getValue() + dice2.getValue() + dice3.getValue() + dice4.getValue() + dice5.getValue();
301
+
302
+        //When
303
+
304
+        scoreSheet.setRow(ScoreSheet.ROW.CHANCE, cup);
305
+        int actual = scoreSheet.getScore(ScoreSheet.ROW.CHANCE);
306
+
307
+        //Then
308
+        Assert.assertEquals(expected, actual);
309
+
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
+        }
330
+
331
+        //When
332
+        scoreSheet.setRow(ScoreSheet.ROW.ACES, cup);
333
+
334
+
335
+        //Then
336
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.ACES) != null));
337
+
338
+    }
339
+
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
+        }
358
+
359
+        //When
360
+        scoreSheet.setRow(ScoreSheet.ROW.TWOS, cup);
361
+
362
+
363
+        //Then
364
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.TWOS) != null));
365
+
366
+    }
367
+
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
+        }
386
+
387
+        //When
388
+        scoreSheet.setRow(ScoreSheet.ROW.THREES, cup);
389
+
390
+
391
+        //Then
392
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.THREES) != null));
393
+
394
+    }
395
+
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
+        }
414
+
415
+        //When
416
+        scoreSheet.setRow(ScoreSheet.ROW.FOURS, cup);
417
+
418
+
419
+        //Then
420
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FOURS) != null));
421
+
422
+    }
423
+
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
+        }
442
+
443
+        //When
444
+        scoreSheet.setRow(ScoreSheet.ROW.FIVES, cup);
445
+
446
+
447
+        //Then
448
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FIVES) != null));
449
+
450
+    }
451
+
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
+        }
470
+
471
+        //When
472
+        scoreSheet.setRow(ScoreSheet.ROW.SIXES, cup);
473
+
474
+
475
+        //Then
476
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.SIXES) != null));
477
+
478
+    }
479
+
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
+        }
498
+
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
+        }
526
+
527
+        //When
528
+        scoreSheet.setRow(ScoreSheet.ROW.FOUROFAKIND, cup);
529
+
530
+
531
+        //Then
532
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.FOUROFAKIND) != null));
533
+
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
+        }
582
+
583
+        //When
584
+        scoreSheet.setRow(ScoreSheet.ROW.SMALLSTRAIGHT, cup);
585
+
586
+
587
+        //Then
588
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.SMALLSTRAIGHT) != null));
589
+
590
+    }
591
+
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
+        }
610
+
611
+        //When
612
+        scoreSheet.setRow(ScoreSheet.ROW.LARGESTRAIGHT, cup);
613
+
614
+
615
+        //Then
616
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.LARGESTRAIGHT) != null));
617
+
618
+    }
619
+
620
+    @Test
621
+    public void testSetRowYahtzee() {
622
+        //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
+        }
638
+
639
+        //When
640
+        scoreSheet.setRow(ScoreSheet.ROW.YAHTZEE, cup);
641
+
642
+
643
+        //Then
644
+        Assert.assertTrue((scoreSheet.getScore(ScoreSheet.ROW.YAHTZEE) != null));
645
+
646
+    }
647
+
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
+
659
+    }
660
+
282 661
 }

+ 12
- 0
src/test/java/io/zipcoder/casino/WarTest.java Целия файл

@@ -0,0 +1,12 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Test;
4
+
5
+public class WarTest {
6
+
7
+    @Test
8
+    public void warTest01(){
9
+
10
+    }
11
+
12
+}

+ 51
- 0
src/test/java/io/zipcoder/casino/YahtzeeTest.java Целия файл

@@ -0,0 +1,51 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class YahtzeeTest {
7
+
8
+    Player player = new Player("Dan", 1000);
9
+    Yahtzee yahtzee = new Yahtzee(player);
10
+
11
+    @Test
12
+    public void testBet() {
13
+        //When
14
+        yahtzee.bet(400);
15
+        int expected = 600;
16
+        int actual = player.getCurrentBalance();
17
+
18
+        //Then
19
+        Assert.assertEquals(expected, actual);
20
+
21
+
22
+    }
23
+
24
+    @Test
25
+    public void testSetBidGetBid() {
26
+        //When
27
+        yahtzee.setBid(400);
28
+        int expected = 400;
29
+        int actual = yahtzee.getBid();
30
+
31
+        //Then
32
+        Assert.assertEquals(expected, actual);
33
+
34
+
35
+    }
36
+
37
+    @Test
38
+    public void testCreateGame() {
39
+        //When
40
+        yahtzee.createGame();
41
+        int expected = 5;
42
+        int actual = yahtzee.getDicePlayer().getCup().length;
43
+
44
+        //Then
45
+        Assert.assertEquals(expected, actual);
46
+
47
+
48
+    }
49
+
50
+
51
+}