Lauren Green 6 лет назад
Родитель
Сommit
ce3c6d1b31

+ 0
- 1
src/main/java/io/zipcoder/casino/CardGame.java Просмотреть файл

32
 
32
 
33
     }
33
     }
34
 
34
 
35
-
36
     public Deck getDeck() {
35
     public Deck getDeck() {
37
         return deck;
36
         return deck;
38
     }
37
     }

+ 0
- 1
src/main/java/io/zipcoder/casino/Game.java Просмотреть файл

1
 package io.zipcoder.casino;
1
 package io.zipcoder.casino;
2
 
2
 
3
 public interface Game {
3
 public interface Game {
4
-
5
      void startGame();
4
      void startGame();
6
      void startRound();
5
      void startRound();
7
 }
6
 }

+ 19
- 25
src/main/java/io/zipcoder/casino/Printer.java Просмотреть файл

4
 
4
 
5
 public class Printer {
5
 public class Printer {
6
 
6
 
7
+    public static void printMessage(String string) {
8
+        System.out.println(string);
9
+    }
10
+
7
     public static void noMatchingGameName(ArrayList<String> gameNames){
11
     public static void noMatchingGameName(ArrayList<String> gameNames){
8
 
12
 
9
         String games = "";
13
         String games = "";
13
         }
17
         }
14
         games = games.trim();
18
         games = games.trim();
15
 
19
 
16
-        System.out.println("Sorry, there is no game with that name, try one of: " + games);
17
-    }
18
-
19
-    public static void getBet(String phrase){
20
-        System.out.println("What is the " + phrase + " at the table you're looking for?");
21
-    }
22
-
23
-    public static void unacceptableMaxBet(int minBet){
24
-        System.out.println("Your bet must be above " + minBet);
25
-    }
26
-
27
-    public static void unacceptableMinBet(){
28
-        System.out.println("Your bet must be above $0");
29
-    }
30
-
31
-    public static void studHandsDealt(){
32
-        System.out.println("Each player Dealt 3 cards");
20
+        printMessage("Sorry, there is no game with that name, try one of: " + games);
33
     }
21
     }
34
 
22
 
35
     public static void showCard(Player player, Card card){
23
     public static void showCard(Player player, Card card){
36
-        System.out.println(player.getName() + " shows a " + card.getName());
24
+        printMessage(player.getName() + " shows a " + card.getName());
37
     }
25
     }
38
 
26
 
39
     public static void pickGameMsg(){
27
     public static void pickGameMsg(){
40
-        System.out.println("Please choose a game to play!");
28
+        printMessage("Please choose a game to play!");
41
     }
29
     }
42
 
30
 
43
     public static void closeGameMsg(){
31
     public static void closeGameMsg(){
44
-        System.out.println("Thanks for your money chump!");
45
-    }
46
-
47
-    public static void printMessage(String string) {
48
-        System.out.println(string);
32
+        printMessage("Thanks for your money chump!");
49
     }
33
     }
50
 
34
 
51
     public static void pleaseEnterNum(){
35
     public static void pleaseEnterNum(){
52
-        System.out.println("Please enter a number");
36
+        printMessage("Please enter a number");
37
+    }
38
+    
39
+    public static void welcomeTo(String gameName){
40
+        printMessage("Welcome to " + gameName + "!");
53
     }
41
     }
54
 
42
 
43
+    public static void printWarTurnResult(String name, String cardName, int handSize){
44
+        printMessage(name + " has played " + cardName + " and has " + handSize + " cards left.");
45
+    }
55
 
46
 
47
+    public static void playedFaceDown(String name){
48
+        printMessage(name + " has played a card face down.");
49
+    }
56
 }
50
 }

+ 5
- 30
src/main/java/io/zipcoder/casino/SlotMachine.java Просмотреть файл

13
         this.betAmount = betAmount;
13
         this.betAmount = betAmount;
14
     }
14
     }
15
 
15
 
16
-    // implemented from gamble
17
     @Override
16
     @Override
18
     public void bet(int betAmount) {
17
     public void bet(int betAmount) {
19
         this.betAmount= betAmount;
18
         this.betAmount= betAmount;
22
 
21
 
23
     @Override
22
     @Override
24
     public void payout(){
23
     public void payout(){
25
-        System.out.println("Your payout amount for slot machine is: $" +payout +"\n");
26
-
24
+        Printer.printMessage("Your payout amount for slot machine is: $" + payout + "\n");
27
     }
25
     }
28
 
26
 
29
-
30
-    // implementd from game
31
-
32
-
33
     @Override
27
     @Override
34
     public void startGame() {
28
     public void startGame() {
35
-        System.out.println("You are all set to play a new slot game..zrrr..!"+"\n");
29
+        Printer.printMessage("You are all set to play a new slot game..zrrr..! \n");
36
         try {
30
         try {
37
             Thread.sleep(3000);
31
             Thread.sleep(3000);
38
         } catch (InterruptedException e) {
32
         } catch (InterruptedException e) {
39
             e.printStackTrace();
33
             e.printStackTrace();
40
         }
34
         }
41
-        System.out.println("Your slot is in progress"+"\n");
35
+        Printer.printMessage("Your slot is in progress"+"\n");
42
 
36
 
43
         try {
37
         try {
44
             Thread.sleep(3000);
38
             Thread.sleep(3000);
107
                 }
101
                 }
108
             }
102
             }
109
             outputword= "[ " + word1+ " ]" + "   " + "[ " + word2 + " ]" + "   "+ "[ " + word3 + " ]" + "\n" ;
103
             outputword= "[ " + word1+ " ]" + "   " + "[ " + word2 + " ]" + "   "+ "[ " + word3 + " ]" + "\n" ;
110
-            //System.out.println(outputword);
111
-
112
 
104
 
113
             if(((!word1.equals(word2)) )&& ((!word1.equals(word3))) && ((!word2.equals(word3)))){
105
             if(((!word1.equals(word2)) )&& ((!word1.equals(word3))) && ((!word2.equals(word3)))){
114
 
106
 
129
                 payout=betAmount*3;
121
                 payout=betAmount*3;
130
             }
122
             }
131
 
123
 
132
-            System.out.println(( outputword + "\n" ));
124
+            Printer.printMessage(( outputword + "\n" ));
133
 
125
 
134
         try {
126
         try {
135
             Thread.sleep(2000);
127
             Thread.sleep(2000);
136
         } catch (InterruptedException e) {
128
         } catch (InterruptedException e) {
137
             e.printStackTrace();
129
             e.printStackTrace();
138
         }
130
         }
139
-
140
-
141
-
142
-        }
143
-
144
-
145
-
146
-
147
-
131
+    }
148
 
132
 
149
     @Override
133
     @Override
150
     public void startRound() {
134
     public void startRound() {
151
 
135
 
152
     }
136
     }
153
-
154
-   /* public  void main(String[] args) {
155
-
156
-
157
-        //System.out.println("Enter the amount of money you wan to enter into the slot machine");
158
-        //Scanner scanner = new Scanner(System.in);
159
-
160
-
161
-    }*/
162
 }
137
 }
163
 
138
 

+ 51
- 99
src/main/java/io/zipcoder/casino/War.java Просмотреть файл

11
 
11
 
12
     private ArrayList<Card> tableCards = new ArrayList<Card>();
12
     private ArrayList<Card> tableCards = new ArrayList<Card>();
13
     private ArrayList<CardPlayer> warMembers = new ArrayList<CardPlayer>();
13
     private ArrayList<CardPlayer> warMembers = new ArrayList<CardPlayer>();
14
-    private Scanner scanner = new Scanner(System.in);
15
-    private boolean war = false;
16
-
17
-    War(int ante) {
18
-        super(ante);
19
-    }
14
+    private Console console = new Console();
20
 
15
 
16
+    War(int ante) { super(ante); }
21
 
17
 
22
-    /**
23
-     * Specific to war methods
24
-     */
25
     public void playCard(boolean cardFace){
18
     public void playCard(boolean cardFace){
26
-        //if the player has cards in their hand
27
         if(super.getPlayersTurn().getHand().size() > 0) {
19
         if(super.getPlayersTurn().getHand().size() > 0) {
28
-            //pull out a card to play
29
-            Card card = super.getPlayersTurn().getHand().get(0);
30
-            //play the card face up, on the table
31
-            card.setVisibility(cardFace);
32
-            tableCards.add(card);
33
-            //store the last played card in the players wrapper class
34
-            super.getPlayersTurn().setPlayedCard(card);
35
-            //remove this card from their hand
36
-            super.getPlayersTurn().getHand().remove(card);
37
-            //print the card that was played
38
-            if(cardFace == true) {
39
-                System.out.println(super.getPlayersTurn().getPlayer().getName() + " has played " + card.getName() + " and has " + super.getPlayersTurn().getHand().size() + " cards left.");
40
-            } else {
41
-                System.out.println(super.getPlayersTurn().getPlayer().getName() + " has played a card face down.");
42
-            }
43
-        //if the player has not cards in their hand but has cards in their discard, pickup their discard and play a card
20
+            playCardInHand(cardFace);
44
         } else if(super.getPlayersTurn().getHand().size() == 0 && super.getPlayersTurn().getDiscard().size() > 0) {
21
         } else if(super.getPlayersTurn().getHand().size() == 0 && super.getPlayersTurn().getDiscard().size() > 0) {
45
-            System.out.println(super.getPlayersTurn().getPlayer().getName() + " ran out of cards and picked up their discard pile.");
46
-            super.getPlayersTurn().getHand().addAll(super.getPlayersTurn().getDiscard());
47
-            super.getPlayersTurn().setDiscard(new ArrayList<Card>());
48
-            playCard(true);
49
-        //if the person has no cards in their hand, and no cards in discard they lose.
22
+            playCardFromPile(cardFace);
50
         } else if(super.getPlayersTurn().getHand().size() == 0 && super.getPlayersTurn().getDiscard().size() == 0){
23
         } else if(super.getPlayersTurn().getHand().size() == 0 && super.getPlayersTurn().getDiscard().size() == 0){
51
             super.setLoser(super.getPlayersTurn().getPlayer());
24
             super.setLoser(super.getPlayersTurn().getPlayer());
52
-            System.out.println(super.getPlayersTurn().getPlayer().getName() + " has lost the match!");
25
+            Printer.printMessage(super.getPlayersTurn().getPlayer().getName() + " has lost the match!");
53
         }
26
         }
54
     }
27
     }
55
 
28
 
56
-    public CardPlayer warMethod(){
57
-        System.out.println("War!");
29
+    public void playCardInHand(boolean cardFace){
30
+        Card card = getCardFromHand(cardFace);
31
+        if(cardFace) {
32
+            Printer.printWarTurnResult(super.getPlayersTurn().getPlayer().getName(), card.getName(), super.getPlayersTurn().getHand().size());
33
+        } else {
34
+            Printer.playedFaceDown(super.getPlayersTurn().getPlayer().getName());
35
+        }
36
+    }
58
 
37
 
38
+    public Card getCardFromHand(boolean cardFace){
39
+        Card card = super.getPlayersTurn().getHand().get(0);
40
+        card.setVisibility(cardFace);
41
+        tableCards.add(card);
42
+        super.getPlayersTurn().setPlayedCard(card);
43
+        super.getPlayersTurn().getHand().remove(card);
44
+        return card;
45
+    }
46
+
47
+    public void playCardFromPile(boolean cardFace){
48
+        Printer.printMessage(super.getPlayersTurn().getPlayer().getName() + " ran out of cards and picked up their discard pile.");
49
+        super.getPlayersTurn().getHand().addAll(super.getPlayersTurn().getDiscard());
50
+        super.getPlayersTurn().setDiscard(new ArrayList<Card>());
51
+        playCard(cardFace);
52
+    }
53
+
54
+    public CardPlayer warMethod(){
55
+        Printer.printMessage("War!");
59
         int max = 0;
56
         int max = 0;
60
         CardPlayer winner = null;
57
         CardPlayer winner = null;
61
-
62
-        //each player plays 3 cards
63
         for(int i = 0; i < warMembers.size(); i ++){
58
         for(int i = 0; i < warMembers.size(); i ++){
64
             for(int m = 0; m < 2; m ++){
59
             for(int m = 0; m < 2; m ++){
65
                 playCard(false);
60
                 playCard(false);
67
             playCard(true);
62
             playCard(true);
68
             super.chooseNextTurn();
63
             super.chooseNextTurn();
69
         }
64
         }
70
-
71
-        //find the player with the highest value
72
         winner = determineWinner(warMembers);
65
         winner = determineWinner(warMembers);
73
         warMembers = new ArrayList<>();
66
         warMembers = new ArrayList<>();
74
         return winner;
67
         return winner;
75
     }
68
     }
76
 
69
 
77
     public CardPlayer determineWinner(ArrayList<CardPlayer> playerList){
70
     public CardPlayer determineWinner(ArrayList<CardPlayer> playerList){
78
-
79
         int max = 0;
71
         int max = 0;
80
         CardPlayer winner = null;
72
         CardPlayer winner = null;
81
         boolean war = false;
73
         boolean war = false;
82
-
83
-        //loop through and get the max card value
84
         for(int i = 0; i < playerList.size(); i ++){
74
         for(int i = 0; i < playerList.size(); i ++){
85
             CardPlayer player = playerList.get(i);
75
             CardPlayer player = playerList.get(i);
86
-            //if the players card is greater than the current max
87
             if(player.getPlayedCard().getCardValue() > max)
76
             if(player.getPlayedCard().getCardValue() > max)
88
             {
77
             {
89
-                //set their value as max
90
                 max = player.getPlayedCard().getCardValue();
78
                 max = player.getPlayedCard().getCardValue();
91
-                //make them the winner
92
                 winner = player;
79
                 winner = player;
93
-                //set war to false
94
                 war = false;
80
                 war = false;
95
             }  else if (player.getPlayedCard().getCardValue() == max){
81
             }  else if (player.getPlayedCard().getCardValue() == max){
96
                 warMembers.add(player);
82
                 warMembers.add(player);
97
                 war = true;
83
                 war = true;
98
             }
84
             }
99
         }
85
         }
86
+        return checkWar(war, winner);
87
+    }
88
+
89
+    public CardPlayer checkWar(boolean war, CardPlayer winner){
100
         if(war)
90
         if(war)
101
         {
91
         {
102
             warMembers.add(winner);
92
             warMembers.add(winner);
104
             return winner;
94
             return winner;
105
         } else if(!war)
95
         } else if(!war)
106
         {
96
         {
107
-            System.out.println("The winner is " + winner.getPlayer().getName());
97
+            Printer.printMessage("The winner is " + winner.getPlayer().getName());
108
             return winner;
98
             return winner;
109
         }
99
         }
110
         return null;
100
         return null;
111
     }
101
     }
112
 
102
 
113
-    /**
114
-     * Below 3 Implemented from Gamble
115
-     */
116
-    public void bet(int betAmount) {
117
-        super.changeTablePot(betAmount);
118
-    }
119
-
103
+    public void bet(int betAmount) { super.changeTablePot(betAmount); }
120
 
104
 
121
     public void payout() {
105
     public void payout() {
122
-        if(super.getWinner() != null)
123
-        {
124
-            super.getWinner().changeBalance(super.getTablePot());
125
-        }
106
+        if(super.getWinner() != null) { super.getWinner().changeBalance(super.getTablePot()); }
126
     }
107
     }
127
 
108
 
128
     public void payAnte() {
109
     public void payAnte() {
133
         }
114
         }
134
     }
115
     }
135
 
116
 
136
-    /**
137
-     * Below 3 Implemented from Game
138
-     */
139
-
140
-
141
-    public void startGame() {
142
-        System.out.println("Welcome to war!");
117
+        Printer.welcomeTo("War");
143
         super.chooseStatingPlayer();
118
         super.chooseStatingPlayer();
144
         payAnte();
119
         payAnte();
145
         deal();
120
         deal();
148
 
123
 
149
     public void startRound() {
124
     public void startRound() {
150
         while(super.getLoser() == null) {
125
         while(super.getLoser() == null) {
151
-
152
-            String input = getCommand();
153
-
154
-            if (input.equals("play")) {
155
-                //each player
156
-                for (CardPlayer player : super.getPlayers()) {
157
-                    //plays a card, then
158
-                    playCard(true);
159
-                    //the turn updates to be the next players.
160
-                    super.chooseNextTurn();
161
-                }
162
-                //determine the winner once all players play a card
126
+            String input = console.getCMDFromUser("Type 'FLIP' to play the card at the top of your pile");
127
+            if (input.equals("flip")) {
128
+                eachPlayerPlayCard();
163
                 CardPlayer winner = determineWinner(super.getPlayers());
129
                 CardPlayer winner = determineWinner(super.getPlayers());
164
-                System.out.println(winner.getPlayer().getName() + " has been rewarded " + tableCards.size() + " cards.");
165
-                //add all the table cards to the players discard
130
+                Printer.printMessage(winner.getPlayer().getName() + " has been rewarded " + tableCards.size() + " cards.");
166
                 winner.addDiscard(tableCards);
131
                 winner.addDiscard(tableCards);
167
-                //clear the table cards pile
168
                 tableCards = new ArrayList<Card>();
132
                 tableCards = new ArrayList<Card>();
169
-                //if the user does not type play
170
             } else {
133
             } else {
171
-                //display a message
172
-                System.out.println("Sorry, I don't understand that command.");
134
+                Printer.printMessage("Sorry, I don't understand that command.");
173
             }
135
             }
174
         }
136
         }
175
-
176
     }
137
     }
177
 
138
 
178
-    public String getCommand(){
179
-        System.out.println("Type play to play the top card from your pile.");
180
-        String input = scanner.next();
181
-        input = input.toLowerCase().trim();
182
-        return input;
139
+    public void eachPlayerPlayCard(){
140
+        for (CardPlayer player : super.getPlayers()) {
141
+            playCard(true);
142
+            super.chooseNextTurn();
143
+        }
183
     }
144
     }
184
 
145
 
185
     public void deal() {
146
     public void deal() {
186
-        //while there are cards in the deck
187
         while(super.getDeck().size() != 0){
147
         while(super.getDeck().size() != 0){
188
-            //for each player playing the game
189
             for(int i = 0; i < super.getPlayers().size(); i ++)
148
             for(int i = 0; i < super.getPlayers().size(); i ++)
190
             {
149
             {
191
-                //grab the card from the top (last added) to the deck
192
                 Card card = super.getDeck().get(super.getDeck().size() - 1);
150
                 Card card = super.getDeck().get(super.getDeck().size() - 1);
193
-                //get the player whos hand we are adding the card to
194
                 CardPlayer player = super.getPlayers().get(i);
151
                 CardPlayer player = super.getPlayers().get(i);
195
-                //add the card to their hand
196
                 player.getHand().add(card);
152
                 player.getHand().add(card);
197
-                //remove the card from the deck
198
                 super.getDeck().remove(card);
153
                 super.getDeck().remove(card);
199
             }
154
             }
200
         }
155
         }
201
-
202
-        System.out.println(super.getPlayersTurn().getPlayer().getName() +
203
-                "has: " + super.getPlayersTurn().getHand().size() + " cards.");
204
-
156
+        Printer.printMessage(super.getPlayersTurn().getPlayer().getName() + "has: " + super.getPlayersTurn().getHand().size() + " cards.");
205
     }
157
     }
206
-}
158
+}

+ 0
- 6
src/test/java/io/zipcoder/casino/DiceTest.java Просмотреть файл

24
 
24
 
25
         Assert.assertEquals(expected,x);
25
         Assert.assertEquals(expected,x);
26
     }
26
     }
27
-
28
-    @Test
29
-    public void test()
30
-    {
31
-
32
-    }
33
 }
27
 }