Explorar el Código

merged with working

Simran Bhutani hace 6 años
padre
commit
10be3833c4

+ 2
- 2
pom.xml Ver fichero

@@ -13,8 +13,8 @@
13 13
                 <groupId>org.apache.maven.plugins</groupId>
14 14
                 <artifactId>maven-compiler-plugin</artifactId>
15 15
                 <configuration>
16
-                    <source>7</source>
17
-                    <target>7</target>
16
+                    <source>8</source>
17
+                    <target>8</target>
18 18
                 </configuration>
19 19
             </plugin>
20 20
         </plugins>

+ 2
- 2
src/main/java/io/zipcoder/casino/Card.java Ver fichero

@@ -44,9 +44,9 @@ public class Card {
44 44
         this.suit = suit;
45 45
     }
46 46
 
47
-    public CardValue getCardValue()
47
+    public int getCardValue()
48 48
     {
49
-        return cardValue;
49
+        return cardValue.getCardValue();
50 50
     }
51 51
 
52 52
     public void setCardValue(CardValue cardValue)

+ 17
- 5
src/main/java/io/zipcoder/casino/CardGame.java Ver fichero

@@ -14,6 +14,7 @@ public abstract class CardGame {
14 14
     private int ante;
15 15
     private CardPlayer playersTurn;
16 16
     private Player winner = null;
17
+    private Player loser = null;
17 18
     private ArrayList<CardPlayer> players = new ArrayList<CardPlayer>();
18 19
     private Deck deck = new Deck();
19 20
 
@@ -25,9 +26,9 @@ public abstract class CardGame {
25 26
     }
26 27
 
27 28
     //use hand size to determine dealing
28
-    public abstract void Deal();
29
+    public abstract void deal();
29 30
 
30
-    public void Shuffle(){
31
+    public void shuffle(){
31 32
 
32 33
         //shuffle the card stack
33 34
 
@@ -102,7 +103,6 @@ public abstract class CardGame {
102 103
                 break;
103 104
             }
104 105
         }
105
-        System.out.println("it is now " + playersTurn.getPlayer().getName() + "'s turn");
106 106
     }
107 107
 
108 108
     public void chooseNextTurn(){
@@ -112,13 +112,25 @@ public abstract class CardGame {
112 112
             if((players.indexOf(playersTurn) + 1) == players.size()){
113 113
                 //start again at the starting player
114 114
                 playersTurn = players.get(0);
115
-                System.out.println("it is now " + playersTurn.getPlayer().getName() + "'s turn");
115
+                //System.out.println("it is now " + playersTurn.getPlayer().getName() + "'s turn");
116 116
 
117 117
             //if it is not the end of the turn circle
118 118
             } else {
119 119
                 playersTurn = players.get(players.indexOf(playersTurn) + 1);
120
-                System.out.println("it is now " + playersTurn.getPlayer().getName() + "'s turn");
120
+                //System.out.println("it is now " + playersTurn.getPlayer().getName() + "'s turn");
121 121
             }
122 122
         }
123 123
     }
124
+
125
+    public void printTurn(){
126
+        System.out.println("it is now " + playersTurn.getPlayer().getName() + "'s turn");
127
+    }
128
+
129
+    public Player getLoser() {
130
+        return loser;
131
+    }
132
+
133
+    public void setLoser(Player loser) {
134
+        this.loser = loser;
135
+    }
124 136
 }

+ 20
- 0
src/main/java/io/zipcoder/casino/CardPlayer.java Ver fichero

@@ -6,6 +6,8 @@ public class CardPlayer {
6 6
     private Player player;
7 7
     private ArrayList<Card> hand = new ArrayList<>();
8 8
     private ArrayList<Card> discard = new ArrayList<>();
9
+    private Card playedCard = null;
10
+
9 11
 
10 12
     public CardPlayer(Player player){
11 13
         this.player = player;
@@ -30,4 +32,22 @@ public class CardPlayer {
30 32
 
31 33
         return null;
32 34
     }
35
+
36
+    public Card getPlayedCard() {
37
+        return playedCard;
38
+    }
39
+
40
+    public void setPlayedCard(Card playedCard) {
41
+        this.playedCard = playedCard;
42
+    }
43
+
44
+    public void addDiscard(ArrayList<Card> cards) {
45
+        this.discard.addAll(cards);
46
+    }
47
+    public ArrayList<Card> getDiscard() {
48
+        return discard;
49
+    }
50
+    public void setDiscard(ArrayList<Card> discard) {
51
+        this.discard = discard;
52
+    }
33 53
 }

+ 61
- 31
src/main/java/io/zipcoder/casino/Console.java Ver fichero

@@ -1,15 +1,21 @@
1 1
 package io.zipcoder.casino;
2
+import java.util.ArrayList;
2 3
 import java.util.InputMismatchException;
3 4
 import java.util.Scanner;
4 5
 
5 6
 public class Console {
6 7
     private Scanner scanner = new Scanner(System.in);
7
-    private String[] gameLib = {"yahtzee", "war", "three card stud"};
8
+    private ArrayList<String> gameLib = new ArrayList<>();
8 9
     private Game game = null;
9 10
     private Player player;
10 11
     private boolean running = true;
11 12
 
12
-    Console(){}
13
+    Console(){
14
+        gameLib.add("yahtzee");
15
+        gameLib.add("war");
16
+        gameLib.add("stud");
17
+        gameLib.add("quit");
18
+    }
13 19
 
14 20
     public void createAccount()
15 21
     {
@@ -24,35 +30,42 @@ public class Console {
24 30
 
25 31
     public void chooseGame()
26 32
     {
27
-        System.out.println("Please choose a game to play!");
28
-        String command = getCommand();
29
-
30
-        switch(command){
31
-
32
-            case "war":
33
-//                int[] warMinMax = getMinMax();
34
-//                Game war = new War(warMinMax[0], warMinMax[1], 10);
35
-//                ((War) war).addPlayers(player);
36
-//                ((War) war).addNpc();
37
-//                war.StartGame();
38
-                break;
39
-
40
-            case "three card stud":
41
-//                int[] studMinMax = getMinMax();
42
-//                Game stud = new Stud(studMinMax[0], studMinMax[1], 10);
43
-//                ((Stud) stud).addPlayers(player);
44
-//                ((Stud) stud).addNpc();
45
-//                stud.StartGame();
46
-                break;
47
-
48
-            case "yahtzee":
49
-                Game yahtzee = new Yahtzee(player);
50
-                yahtzee.StartGame();
51
-                break;
52
-
53
-            default:
54
-                Printer.noMatchingGameName(gameLib);
55
-                break;
33
+        while(running) {
34
+            System.out.println("Please choose a game to play!");
35
+            String command = getCommand();
36
+
37
+            switch (command) {
38
+
39
+                case "war":
40
+                    int[] warMinMax = getMinMax();
41
+                    Game war = new War(warMinMax[0], warMinMax[1], 10);
42
+                    ((War) war).addPlayers(player);
43
+                    ((War) war).addNpc();
44
+                    war.startGame();
45
+                    break;
46
+
47
+                case "three card stud":
48
+                    int[] studMinMax = getMinMax();
49
+                    Game stud = new Stud(studMinMax[0], studMinMax[1], 10);
50
+                    ((Stud) stud).addPlayers(player);
51
+                    ((Stud) stud).addNpc();
52
+                    stud.startGame();
53
+                    break;
54
+
55
+                case "yahtzee":
56
+                    Game yahtzee = new Yahtzee(player);
57
+                    yahtzee.startGame();
58
+                    break;
59
+
60
+                case "quit":
61
+                    System.out.println("Thanks for your money chump!");
62
+                    running = false;
63
+                    break;
64
+
65
+                default:
66
+                    Printer.noMatchingGameName(gameLib);
67
+                    break;
68
+            }
56 69
         }
57 70
     }
58 71
 
@@ -104,4 +117,21 @@ public class Console {
104 117
         return command;
105 118
     }
106 119
 
120
+    public String continueAskGame(){
121
+
122
+        String command = "";
123
+
124
+        System.out.println("Please choose a game to play!");
125
+        command = getCommand();
126
+
127
+        if(gameLib.indexOf(command) == -1)
128
+        {
129
+            while(gameLib.indexOf(command) == -1)
130
+            {
131
+                Printer.noMatchingGameName(gameLib);
132
+                command = getCommand();
133
+            }
134
+        }
135
+        return command;
136
+    }
107 137
 }

+ 0
- 1
src/main/java/io/zipcoder/casino/Dice.java Ver fichero

@@ -2,7 +2,6 @@ package io.zipcoder.casino;
2 2
 
3 3
 public class Dice {
4 4
 
5
-
6 5
     private int value;
7 6
 
8 7
     public void roll(){

+ 2
- 0
src/main/java/io/zipcoder/casino/DiceGame.java Ver fichero

@@ -5,4 +5,6 @@ public abstract class DiceGame {
5 5
     private int numberOfRolls;
6 6
     private Player[] players;
7 7
     private Player playersTurn;
8
+
9
+
8 10
 }

+ 11
- 0
src/main/java/io/zipcoder/casino/DicePlayer.java Ver fichero

@@ -23,5 +23,16 @@ public class DicePlayer {
23 23
         for(Dice d : cup) {
24 24
             System.out.print(d.getValue() + " ");
25 25
         }
26
+        System.out.println();
27
+    }
28
+
29
+    public Player getPlayer() {
30
+        return player;
31
+    }
32
+
33
+    public void printBalanceAtEnd() {
34
+        System.out.println("Your total balance is now: $" + getPlayer().getCurrentBalance());
26 35
     }
27 36
 }
37
+
38
+

+ 2
- 2
src/main/java/io/zipcoder/casino/Gamble.java Ver fichero

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

+ 3
- 3
src/main/java/io/zipcoder/casino/Game.java Ver fichero

@@ -1,7 +1,7 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 public interface Game {
4
-     void Quit();
5
-     void StartGame();
6
-     void StartRound();
4
+     void quit();
5
+     void startGame();
6
+     void startRound();
7 7
 }

+ 1
- 0
src/main/java/io/zipcoder/casino/Player.java Ver fichero

@@ -8,6 +8,7 @@ public class Player {
8 8
     Player(String name, int initialBalance){
9 9
         this.name = name;
10 10
         this.initialBalance = initialBalance;
11
+        this.currentBalance = initialBalance;
11 12
     }
12 13
 
13 14
     public int getInitialBalance() {

+ 5
- 3
src/main/java/io/zipcoder/casino/Printer.java Ver fichero

@@ -1,13 +1,15 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
+import java.util.ArrayList;
4
+
3 5
 public class Printer {
4 6
 
5
-    public static void noMatchingGameName(String[] gameNames){
7
+    public static void noMatchingGameName(ArrayList<String> gameNames){
6 8
 
7 9
         String games = "";
8 10
 
9
-        for(int i = 0; i < gameNames.length; i ++){
10
-            games += gameNames[i] + " ";
11
+        for(int i = 0; i < gameNames.size(); i ++){
12
+            games += gameNames.get(i) + " ";
11 13
         }
12 14
         games = games.trim();
13 15
 

+ 101
- 26
src/main/java/io/zipcoder/casino/ScoreSheet.java Ver fichero

@@ -2,14 +2,17 @@
2 2
 
3 3
 package io.zipcoder.casino;
4 4
 
5
+import com.sun.tools.example.debug.expr.ASCII_UCodeESC_CharStream;
6
+
5 7
 import java.util.*;
6 8
 
7 9
 public class ScoreSheet {
8 10
 
9
-    private enum ROW{
11
+    public enum ROW{
10 12
         ACES, TWOS, THREES, FOURS, FIVES, SIXES, THREEOFAKIND, FOUROFAKIND, FULLHOUSE, SMALLSTRAIGHT, LARGESTRAIGHT, YAHTZEE, CHANCE;
11 13
     }
12 14
     private Map<ROW, Integer> scores = new EnumMap<>(ROW.class);
15
+    private static final int size = ROW.values().length;
13 16
 
14 17
     ScoreSheet(){
15 18
 
@@ -17,37 +20,101 @@ public class ScoreSheet {
17 20
 
18 21
     public int getTotalScore() {
19 22
 
20
-        int topTotalScore = 0;
21
-        int bottomTotalScore = 0;
22
-        int index = 0;
23
-        for(ROW r : ROW.values()) {
24
-            while (index < 6) {
25
-                topTotalScore += scores.get(r);
26
-                index++;
27
-            }
28
-            if (topTotalScore >= 63) {
29
-                topTotalScore += 35;
30
-            }
31
-            while (index >= 6) {
32
-                bottomTotalScore += scores.get(r);
33
-                index++;
34
-            }
35
-        }
36
-        return topTotalScore + bottomTotalScore;
23
+        int totalScore = 0;
24
+        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));
25
+        if (totalScore >= 63) {
26
+            totalScore += 35;
37 27
         }
28
+        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));
29
+
30
+        return totalScore;
31
+    }
32
+
38 33
 
39 34
     public void printScoreCard(){
40
-        for(ROW r : ROW.values()) {
41
-            System.out.println(r + ": " + scores.get(r));
35
+        System.out.print(String.format("%-35s","1. Aces: Totals all Ones"));
36
+        if(getScore(ScoreSheet.ROW.ACES) != null) {
37
+            System.out.println("** " + getScore(ScoreSheet.ROW.ACES) + " **");
38
+        } else {
39
+            System.out.println("** open **");
42 40
         }
43
-
41
+        System.out.print(String.format("%-35s","2. Twos: Totals all Twos"));
42
+        if(getScore(ScoreSheet.ROW.TWOS) != null) {
43
+            System.out.println("** " + getScore(ScoreSheet.ROW.TWOS) + " **");
44
+        } else {
45
+            System.out.println("** open **");
46
+        }
47
+        System.out.print(String.format("%-35s", "3. Threes: Totals all Threes"));
48
+        if(getScore(ScoreSheet.ROW.THREES) != null) {
49
+            System.out.println("** " + getScore(ScoreSheet.ROW.THREES) + " **");
50
+        } else {
51
+            System.out.println("** open **");
52
+        }
53
+        System.out.print(String.format("%-35s", "4. Fours: Totals all Fours"));
54
+        if(getScore(ScoreSheet.ROW.FOURS) != null) {
55
+            System.out.println("** " + getScore(ScoreSheet.ROW.FOURS) + " **");
56
+        } else {
57
+            System.out.println("** open **");
58
+        }
59
+        System.out.print(String.format("%-35s", "5. Fives: Totals all Fives"));
60
+        if(getScore(ScoreSheet.ROW.FIVES) != null) {
61
+            System.out.println("** " + getScore(ScoreSheet.ROW.FIVES) + " **");
62
+        } else {
63
+            System.out.println("** open **");
64
+        }
65
+        System.out.print(String.format("%-35s", "6. Sixes: Totals all Sixes"));
66
+        if(getScore(ScoreSheet.ROW.SIXES) != null) {
67
+            System.out.println("** " + getScore(ScoreSheet.ROW.SIXES) + " **");
68
+        } else {
69
+            System.out.println("** open **");
70
+        }
71
+        System.out.print(String.format("%-35s", "7. 3 of a Kind"));
72
+        if(getScore(ScoreSheet.ROW.THREEOFAKIND) != null) {
73
+            System.out.println("** " + getScore(ScoreSheet.ROW.THREEOFAKIND) + " **");
74
+        } else {
75
+            System.out.println("** open **");
76
+        }
77
+        System.out.print(String.format("%-35s", "8. 4 of a Kind"));
78
+        if(getScore(ScoreSheet.ROW.FOUROFAKIND) != null) {
79
+            System.out.println("** " + getScore(ScoreSheet.ROW.FOUROFAKIND) + " **");
80
+        } else {
81
+            System.out.println("** open **");
82
+        }
83
+        System.out.print(String.format("%-35s", "9. Full House"));
84
+        if(getScore(ScoreSheet.ROW.FULLHOUSE) != null) {
85
+            System.out.println("** " + getScore(ScoreSheet.ROW.FULLHOUSE) + " **");
86
+        } else {
87
+            System.out.println("** open **");
88
+        }
89
+        System.out.print(String.format("%-35s","10. Small Straight: Sequence of 4"));
90
+        if(getScore(ScoreSheet.ROW.SMALLSTRAIGHT) != null) {
91
+            System.out.println("** " + getScore(ScoreSheet.ROW.SMALLSTRAIGHT) + " **");
92
+        } else {
93
+            System.out.println("** open **");
94
+        }
95
+        System.out.print(String.format("%-35s","11. Large Striaght: Sequence of 5"));
96
+        if(getScore(ScoreSheet.ROW.LARGESTRAIGHT) != null) {
97
+            System.out.println("** " + getScore(ScoreSheet.ROW.LARGESTRAIGHT) + " **");
98
+        } else {
99
+            System.out.println("** open **");
100
+        }
101
+        System.out.print(String.format("%-35s","12. Yahtzee: 5 of a Kind "));
102
+        if(getScore(ScoreSheet.ROW.YAHTZEE) != null) {
103
+            System.out.println("** " + getScore(ScoreSheet.ROW.YAHTZEE) + " **");
104
+        } else {
105
+            System.out.println("** open **");
106
+        }
107
+        System.out.print(String.format("%-35s", "13. Chance: Sum of Dice"));
108
+        if(getScore(ScoreSheet.ROW.CHANCE) != null) {
109
+            System.out.println("** " + getScore(ScoreSheet.ROW.CHANCE) + " **");
110
+        } else {
111
+            System.out.println("** open **");
112
+        }
113
+        System.out.println();
44 114
     }
45 115
 
46 116
     public void setRow(ROW row, Dice[] cup){
47 117
 
48
-        if(scores.get(row) != null) {
49
-            System.out.println("Error, you have already filled that row");
50
-        } else {
51 118
             ArrayList<Integer> numbers = new ArrayList<>();
52 119
             for (Dice d : cup) {
53 120
                 numbers.add(d.getValue());
@@ -121,7 +188,7 @@ public class ScoreSheet {
121 188
             }
122 189
         }
123 190
 
124
-    }
191
+
125 192
 
126 193
     public boolean checkFullHouse(ArrayList<Integer> numbers) {
127 194
 
@@ -180,7 +247,7 @@ public class ScoreSheet {
180 247
             counts[numbers.get(i) - 1]++;
181 248
 
182 249
         for (int i: counts) {
183
-            if (i == numb) return true;
250
+            if (i >= numb) return true;
184 251
         }
185 252
         return false;
186 253
     }
@@ -204,4 +271,12 @@ public class ScoreSheet {
204 271
         }
205 272
         return score;
206 273
     }
274
+
275
+    public static int getSize() {
276
+        return size;
277
+    }
278
+
279
+    public Integer getScore(ROW row) {
280
+        return this.scores.get(row);
281
+    }
207 282
 }

+ 54
- 56
src/main/java/io/zipcoder/casino/Stud.java Ver fichero

@@ -1,56 +1,54 @@
1
-//package io.zipcoder.casino;
2
-//
3
-//public class Stud extends CardGame implements Gamble, Game {
4
-//    public Stud(int minBet, int maxBet) {
5
-//
6
-//        super(minBet, maxBet);
7
-//    public Stud( int minBet, int maxBet, int ante){
8
-//            super(minBet, maxBet, ante);
9
-//        }
10
-//
11
-//        public void Deal () {
12
-//
13
-//        }
14
-//
15
-//
16
-//        public void determineWinner () {
17
-//
18
-//        }
19
-//
20
-//        public void fold () {
21
-//
22
-//        }
23
-//
24
-//        /**
25
-//         * Below 3 Implemented from Gamble
26
-//         * @param betAmount
27
-//         */
28
-//        public void Bet ( int betAmount){
29
-//
30
-//        }
31
-//
32
-//        public int Payout ( int payoutAmount){
33
-//            return 0;
34
-//        }
35
-//
36
-//        public void Ante ( int anteAmount){
37
-//
38
-//        }
39
-//
40
-//        /**
41
-//         * Below 3 Implemented from Game
42
-//         */
43
-//
44
-//        public void Quit(){
45
-//
46
-//        }
47
-//
48
-//        public void StartGame(){
49
-//
50
-//        }
51
-//
52
-//        public void StartRound(){
53
-//
54
-//        }
55
-//    }
56
-//}
1
+
2
+package io.zipcoder.casino;
3
+
4
+public class Stud extends CardGame implements Gamble, Game {
5
+    public Stud(int minBet, int maxBet, int ante) {
6
+        super(minBet, maxBet, ante);
7
+    }
8
+
9
+    public void deal() {
10
+
11
+    }
12
+
13
+    public void determineWinner(){
14
+
15
+    }
16
+
17
+    public void fold(){
18
+
19
+    }
20
+
21
+    /**
22
+     * Below 3 Implemented from Gamble
23
+     * @param betAmount
24
+     */
25
+    public void bet(int betAmount) {
26
+
27
+    }
28
+
29
+    public void payout() {
30
+
31
+    }
32
+
33
+
34
+    public void Ante(int anteAmount) {
35
+
36
+    }
37
+
38
+
39
+    /**
40
+     * Below 3 Implemented from Game
41
+     */
42
+
43
+    public void quit() {
44
+
45
+    }
46
+
47
+    public void startGame() {
48
+
49
+    }
50
+
51
+    public void startRound() {
52
+
53
+    }
54
+}

+ 200
- 107
src/main/java/io/zipcoder/casino/War.java Ver fichero

@@ -1,107 +1,200 @@
1
-//package io.zipcoder.casino;
2
-//
3
-//import java.util.ArrayList;
4
-//import java.util.HashMap;
5
-//import java.util.regex.Pattern;
6
-//
7
-//public class War extends CardGame implements Gamble, Game {
8
-//
9
-//    private ArrayList<Card> tableCards = new ArrayList<Card>();
10
-//
11
-//    War(int minBet, int maxBet, int ante) {
12
-//        super(minBet, maxBet, ante);
13
-//    }
14
-//
15
-//
16
-//    /**
17
-//     * Specific to war methods
18
-//     */
19
-//    public void playCard(){
20
-//        //take a card from the hand
21
-//        //add it to the tablecard face up
22
-//    }
23
-//
24
-//    public void warMethod(){
25
-//        //take three cards from your hand face down
26
-//        //play one card face up
27
-//    }
28
-//
29
-//    public void determineWinner(Card player1card, Card player2card){
30
-//
31
-//    }
32
-//
33
-//    /**
34
-//     * Below 3 Implemented from Gamble
35
-//     */
36
-//    public void Bet(int betAmount) {
37
-//        super.changeTablePot(betAmount);
38
-//    }
39
-//
40
-//    public int Payout(int payoutAmount) {
41
-//        if(super.getWinner() != null){
42
-//            super.getWinner().changeBalance(super.getTablePot());
43
-//        }
44
-//        return 0;
45
-//    }
46
-//
47
-//    public void payAnte() {
48
-//        for(int i = 0; i < super.getPlayers().size(); i ++)
49
-//        {
50
-//            CardPlayer player = super.getPlayers().get(i);
51
-//            player.getPlayer().changeBalance(-super.getAnte());
52
-//        }
53
-//    }
54
-//
55
-//    /**
56
-//     * Below 3 Implemented from Game
57
-//     */
58
-//
59
-//    public void Quit() {
60
-//
61
-//    }
62
-//
63
-//    public void StartGame() {
64
-//        System.out.println("Welcome to war!");
65
-//        super.chooseStatingPlayer();
66
-//        payAnte();
67
-//        Deal();
68
-//        //super.chooseNextTurn();
69
-//    }
70
-//
71
-//    public void StartRound() {
72
-//        //player plays a card faceup
73
-//        //remove cards from player hand
74
-//        //pc plays a card faceup
75
-//        //remove cards from npc hand
76
-//        //determinewinner
77
-//        //add all table cards to winners discard facedown
78
-//
79
-//        //when player is out of cards
80
-//        //shuffle players discard
81
-//        //insert discard into hand facedown
82
-//    }
83
-//
84
-//    public void Deal() {
85
-//        //while there are cards in the deck
86
-//        while(super.getDeck().size() != 0){
87
-//            //for each player playing the game
88
-//            for(int i = 0; i < super.getPlayers().size(); i ++)
89
-//            {
90
-//                //grab the card from the top (last added) to the deck
91
-//                Card card = super.getDeck().get(super.getDeck().size() - 1);
92
-//                //get the player whos hand we are adding the card to
93
-//                CardPlayer player = super.getPlayers().get(i);
94
-//                //add the card to their hand
95
-//                player.getHand().add(card);
96
-//
97
-//
98
-//
99
-//                //remove the card from the deck
100
-//                super.getDeck().remove(card);
101
-//
102
-//            }
103
-//        }
104
-//        System.out.println(super.getPlayersTurn().getPlayer().getName() + "has: " + super.getPlayersTurn().getHand().size() + " cards.");
105
-//    }
106
-//
107
-//}
1
+package io.zipcoder.casino;
2
+
3
+import java.util.*;
4
+import java.util.concurrent.Executors;
5
+import java.util.concurrent.ScheduledExecutorService;
6
+import java.util.concurrent.TimeUnit;
7
+import java.util.regex.Pattern;
8
+import java.util.concurrent.TimeUnit;
9
+
10
+public class War extends CardGame implements Gamble, Game {
11
+
12
+    private ArrayList<Card> tableCards = new ArrayList<Card>();
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 minBet, int maxBet, int ante) {
18
+        super(minBet, maxBet, ante);
19
+    }
20
+
21
+
22
+    /**
23
+     * Specific to war methods
24
+     */
25
+    public void playCard(boolean cardFace){
26
+        //if the player has cards in their hand
27
+        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
44
+        } 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.
50
+        } else if(super.getPlayersTurn().getHand().size() == 0 && super.getPlayersTurn().getDiscard().size() == 0){
51
+            super.setLoser(super.getPlayersTurn().getPlayer());
52
+            System.out.println(super.getPlayersTurn().getPlayer().getName() + " has lost the match!");
53
+        }
54
+    }
55
+
56
+    public CardPlayer warMethod(){
57
+        System.out.println("War!");
58
+
59
+        int max = 0;
60
+        CardPlayer winner = null;
61
+
62
+        //each player plays 3 cards
63
+        for(int i = 0; i < warMembers.size(); i ++){
64
+            for(int m = 0; m < 2; m ++){
65
+                playCard(false);
66
+            }
67
+            playCard(true);
68
+            super.chooseNextTurn();
69
+        }
70
+
71
+        //find the player with the highest value
72
+        winner = determineWinner(warMembers);
73
+        warMembers = new ArrayList<>();
74
+        return winner;
75
+    }
76
+
77
+    public CardPlayer determineWinner(ArrayList<CardPlayer> playerList){
78
+
79
+        int max = 0;
80
+        CardPlayer winner = null;
81
+        boolean war = false;
82
+
83
+        //loop through and get the max card value
84
+        for(int i = 0; i < playerList.size(); i ++){
85
+            CardPlayer player = playerList.get(i);
86
+            //if the players card is greater than the current max
87
+            if(player.getPlayedCard().getCardValue() > max)
88
+            {
89
+                //set their value as max
90
+                max = player.getPlayedCard().getCardValue();
91
+                //make them the winner
92
+                winner = player;
93
+                //set war to false
94
+                war = false;
95
+            }  else if (player.getPlayedCard().getCardValue() == max){
96
+                warMembers.add(player);
97
+                war = true;
98
+            }
99
+        }
100
+
101
+        if(war)
102
+        {
103
+            warMembers.add(winner);
104
+            winner = warMethod();
105
+            return winner;
106
+        } else if(!war)
107
+        {
108
+            System.out.println("The winner is " + winner.getPlayer().getName());
109
+            return winner;
110
+        }
111
+        return null;
112
+    }
113
+
114
+    /**
115
+     * Below 3 Implemented from Gamble
116
+     */
117
+    public void bet(int betAmount) {
118
+        super.changeTablePot(betAmount);
119
+    }
120
+
121
+
122
+    public void payout() {
123
+        if(super.getWinner() != null)
124
+        {
125
+            super.getWinner().changeBalance(super.getTablePot());
126
+        }
127
+    }
128
+
129
+    public void payAnte() {
130
+        for(int i = 0; i < super.getPlayers().size(); i ++)
131
+        {
132
+            CardPlayer player = super.getPlayers().get(i);
133
+            player.getPlayer().changeBalance(super.getAnte() * -1);
134
+        }
135
+    }
136
+
137
+    /**
138
+     * Below 3 Implemented from Game
139
+     */
140
+
141
+    public void quit() {
142
+
143
+    }
144
+
145
+    public void startGame() {
146
+        System.out.println("Welcome to war!");
147
+        super.chooseStatingPlayer();
148
+        payAnte();
149
+        deal();
150
+        startRound();
151
+    }
152
+
153
+    public void startRound() {
154
+        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();
158
+            if (input.equals("play")) {
159
+                //each player
160
+                for (CardPlayer player : super.getPlayers()) {
161
+                    //plays a card, then
162
+                    playCard(true);
163
+                    //the turn updates to be the next players.
164
+                    super.chooseNextTurn();
165
+                }
166
+                //determine the winner once all players play a card
167
+                CardPlayer winner = determineWinner(super.getPlayers());
168
+                System.out.println(winner.getPlayer().getName() + " has been rewarded " + tableCards.size() + " cards.");
169
+                //add all the table cards to the players discard
170
+                winner.addDiscard(tableCards);
171
+                //clear the table cards pile
172
+                tableCards = new ArrayList<Card>();
173
+                //if the user does not type play
174
+            } else {
175
+                //display a message
176
+                System.out.println("Sorry, I don't understand that command.");
177
+            }
178
+        }
179
+
180
+    }
181
+
182
+    public void deal() {
183
+        //while there are cards in the deck
184
+        while(super.getDeck().size() != 0){
185
+            //for each player playing the game
186
+            for(int i = 0; i < super.getPlayers().size(); i ++)
187
+            {
188
+                //grab the card from the top (last added) to the deck
189
+                Card card = super.getDeck().get(super.getDeck().size() - 1);
190
+                //get the player whos hand we are adding the card to
191
+                CardPlayer player = super.getPlayers().get(i);
192
+                //add the card to their hand
193
+                player.getHand().add(card);
194
+                //remove the card from the deck
195
+                super.getDeck().remove(card);
196
+            }
197
+        }
198
+        System.out.println(super.getPlayersTurn().getPlayer().getName() + " has: " + super.getPlayersTurn().getHand().size() + " cards.");
199
+    }
200
+}

+ 183
- 27
src/main/java/io/zipcoder/casino/Yahtzee.java Ver fichero

@@ -1,35 +1,33 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
-public class Yahtzee extends DiceGame implements Game{
3
+import java.util.ArrayList;
4
+import java.util.Scanner;
5
+
6
+public class Yahtzee extends DiceGame implements Game, Gamble {
4 7
 
5
-    private Dice[] cup;
6 8
     DicePlayer dicePlayer;
9
+    private Scanner scanner = new Scanner(System.in);
10
+    int betAmount = 0;
7 11
 
8 12
     public Yahtzee(Player player) {
9 13
         this.dicePlayer = new DicePlayer(player);
10 14
     }
11 15
 
12
-    public void compareScore(DicePlayer player1, DicePlayer player2){
13
-
14
-        player1.getScoreSheet().getTotalScore();
16
+    public int getBid() {
17
+        return betAmount;
15 18
     }
16 19
 
17
-    public void reRoll(){
18
-
20
+    public void setBid(int bid) {
21
+        this.betAmount = bid;
19 22
     }
20 23
 
21
-    public void stopRoll(){
22 24
 
23
-    }
24
-
25
-    /**
26
-     * implemented from 'Game'
27
-     */
28
-    public void Quit() {
25
+    @Override
26
+    public void quit() {
29 27
 
30 28
     }
31 29
 
32
-    public void StartGame() {
30
+    public void startGame() {
33 31
         Dice dice1 = new Dice();
34 32
         Dice dice2 = new Dice();
35 33
         Dice dice3 = new Dice();
@@ -41,29 +39,187 @@ public class Yahtzee extends DiceGame implements Game{
41 39
         dicePlayer.getCup()[2] = dice3;
42 40
         dicePlayer.getCup()[3] = dice4;
43 41
         dicePlayer.getCup()[4] = dice5;
42
+
43
+        System.out.println("How much would you like to bet on this game?");
44
+        int betAmount = scanner.nextInt();
45
+        setBid(betAmount);
46
+        bet(betAmount);
47
+
48
+        startRound();
49
+        System.out.println("You scored " + dicePlayer.getScoreSheet().getTotalScore() + " points.");
50
+        payout();
51
+        dicePlayer.printBalanceAtEnd();
52
+        System.out.println();
44 53
     }
45 54
 
46
-    public void StartRound() {
47
-        for(Dice d : dicePlayer.getCup()) {
48
-            d.roll();
55
+    public void startRound() {
56
+
57
+        for (int i = 0; i < ScoreSheet.getSize(); i++) {
58
+            for (Dice d : dicePlayer.getCup()) {
59
+                d.roll();
60
+            }
61
+            System.out.println("\nYou rolled:");
62
+            dicePlayer.printCup();
63
+            System.out.println();
64
+
65
+            roundRoutine();
66
+            recordingScore();
49 67
         }
50
-        dicePlayer.printCup();
51 68
 
52
-        //roundRoutine();
69
+    }
70
+
71
+    public void roundRoutine() {
72
+
73
+        giveOptions();
74
+        giveOptions();
53 75
 
54 76
     }
55 77
 
56
-    public void roundRoutine(){
78
+    public void giveOptions() {
79
+        int choice = 0;
80
+        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: ");
81
+
82
+        Scanner in = new Scanner(System.in);
83
+        choice = in.nextInt();
84
+
85
+        switch (choice) {
86
+            case 1:
87
+                for (Dice d : dicePlayer.getCup()) {
88
+                    d.roll();
89
+                }
90
+                System.out.println("\nYou rolled:");
91
+                dicePlayer.printCup();
92
+                System.out.println();
93
+                break;
94
+
95
+            case 2:
96
+                System.out.println("Which numbers would you like to reroll? List the numbers separated by spaces.");
97
+                Scanner in2 = new Scanner(System.in);
98
+                String diceToRoll = in2.nextLine();
99
+                reRoll(diceToRoll);
100
+                System.out.println("\nYou rolled:");
101
+                dicePlayer.printCup();
102
+                System.out.println();
103
+                break;
104
+
105
+            case 3:
106
+                break;
107
+        }
108
+    }
57 109
 
58
-        //ask if they want to score, or roll again?
110
+    public void reRoll(String diceToRoll) {
59 111
 
60
-            //roll again if requested
112
+        String[] numbersString = diceToRoll.split(" ");
113
+        ArrayList<Integer> numbers = new ArrayList<>();
114
+        for (String s : numbersString) {
115
+            numbers.add(Integer.parseInt(s));
116
+        }
61 117
 
62
-                //continue to roll until no more rolls are left
118
+        for (Integer i : numbers) {
119
+            for (int j = 0; j < 5; j++) {
120
+                if (i == dicePlayer.getCup()[j].getValue()) {
121
+                    dicePlayer.getCup()[j].roll();
122
+                    break;
123
+                }
124
+            }
125
+        }
126
+    }
63 127
 
64
-        //ask user how they would like to score
128
+    public void recordingScore() {
129
+
130
+        boolean validEntry = true;
131
+        int choice = 13;
132
+        ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
133
+
134
+        while (validEntry) {
135
+            dicePlayer.getScoreSheet().printScoreCard();
136
+            System.out.println();
137
+            System.out.println("Which row would you like to apply your turn to on the scoresheet?.\n" +
138
+                    "Remember you can only use each row once!");
139
+            System.out.print("Row:");
140
+
141
+            Scanner scanner2 = new Scanner(System.in);
142
+            choice = scanner2.nextInt();
143
+
144
+            switch (choice) {
145
+                case 1:
146
+                    row = ScoreSheet.ROW.ACES;
147
+                    break;
148
+                case 2:
149
+                    row = ScoreSheet.ROW.TWOS;
150
+                    break;
151
+                case 3:
152
+                    row = ScoreSheet.ROW.THREES;
153
+                    break;
154
+                case 4:
155
+                    row = ScoreSheet.ROW.FOURS;
156
+                    break;
157
+                case 5:
158
+                    row = ScoreSheet.ROW.FIVES;
159
+                    break;
160
+                case 6:
161
+                    row = ScoreSheet.ROW.SIXES;
162
+                    break;
163
+                case 7:
164
+                    row = ScoreSheet.ROW.THREEOFAKIND;
165
+                    break;
166
+                case 8:
167
+                    row = ScoreSheet.ROW.FOUROFAKIND;
168
+                    break;
169
+                case 9:
170
+                    row = ScoreSheet.ROW.FULLHOUSE;
171
+                    break;
172
+                case 10:
173
+                    row = ScoreSheet.ROW.SMALLSTRAIGHT;
174
+                    break;
175
+                case 11:
176
+                    row = ScoreSheet.ROW.LARGESTRAIGHT;
177
+                    break;
178
+                case 12:
179
+                    row = ScoreSheet.ROW.YAHTZEE;
180
+                    break;
181
+                case 13:
182
+                    row = ScoreSheet.ROW.CHANCE;
183
+                    break;
184
+            }
185
+            if (dicePlayer.getScoreSheet().getScore(row) == null) {
186
+                validEntry = false;
187
+            } else {
188
+                System.out.println("Error, you have already filled that row");
189
+            }
190
+        }
65 191
 
66
-        //calculate the users score
192
+        dicePlayer.getScoreSheet().setRow(row, dicePlayer.getCup());
193
+        System.out.println();
194
+        dicePlayer.getScoreSheet().printScoreCard();
195
+    }
67 196
 
197
+    @Override
198
+    public void bet(int betAmount) {
199
+        dicePlayer.getPlayer().changeBalance(betAmount * -1);
68 200
     }
69
-}
201
+
202
+    @Override
203
+    public void payout() {
204
+        int score = dicePlayer.getScoreSheet().getTotalScore();
205
+        int payOut = 0;
206
+        if (score == 1575) {
207
+            payOut = getBid() * 100;
208
+        } else if (score > 1000) {
209
+            payOut = getBid() * 20;
210
+        } else if (score > 500) {
211
+            payOut = getBid() * 10;
212
+        } else if (score > 400) {
213
+            payOut = getBid() * 5;
214
+        } else if (score > 300) {
215
+            payOut = getBid() * 3;
216
+        } else if (score > 200) {
217
+            payOut = getBid() * 2;
218
+        } else {
219
+            payOut = 0;
220
+        }
221
+        dicePlayer.getPlayer().changeBalance(payOut);
222
+        System.out.println("You won $" + payOut);
223
+    }
224
+
225
+}

+ 1
- 1
src/main/java/io/zipcoder/casino/test.java Ver fichero

@@ -8,4 +8,4 @@ public class test {
8 8
         console.chooseGame();
9 9
     }
10 10
 
11
-}
11
+}

+ 1
- 2
src/test/java/io/zipcoder/casino/ScoreSheetTest.java Ver fichero

@@ -3,9 +3,8 @@ package io.zipcoder.casino;
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6
-import java.lang.reflect.Array;
6
+
7 7
 import java.util.ArrayList;
8
-import java.util.Arrays;
9 8
 import java.util.Collections;
10 9
 
11 10
 public class ScoreSheetTest {