Browse Source

Made it so you can play another game

Lauren Green 6 years ago
parent
commit
b20be8d9fe

+ 37
- 27
src/main/java/io/zipcoder/casino/Console.java View File

24
 
24
 
25
     public void chooseGame()
25
     public void chooseGame()
26
     {
26
     {
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.startGame();
37
-                break;
38
-
39
-            case "three card stud":
40
-                int[] studMinMax = getMinMax();
41
-                Game stud = new Stud(studMinMax[0], studMinMax[1], 10);
42
-                ((Stud) stud).addPlayers(player);
43
-                stud.startGame();
44
-                break;
45
-
46
-            case "yahtzee":
47
-                Game yahtzee = new Yahtzee(player);
48
-                yahtzee.startGame();
49
-                break;
50
-
51
-            default:
52
-                Printer.noMatchingGameName(gameLib);
53
-                break;
27
+        boolean play = true;
28
+        while(play) {
29
+            System.out.println("Please choose a game to play!");
30
+            String command = getCommand();
31
+
32
+            switch (command) {
33
+
34
+                case "war":
35
+                    int[] warMinMax = getMinMax();
36
+                    Game war = new War(warMinMax[0], warMinMax[1], 10);
37
+                    ((War) war).addPlayers(player);
38
+                    war.startGame();
39
+                    break;
40
+
41
+                case "three card stud":
42
+                    int[] studMinMax = getMinMax();
43
+                    Game stud = new Stud(studMinMax[0], studMinMax[1], 10);
44
+                    ((Stud) stud).addPlayers(player);
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;
56
+            }
57
+            System.out.println("Do you want to play another game? Y or N");
58
+            Scanner in = new Scanner(System.in);
59
+            String response = in.next();
60
+            if (response.equalsIgnoreCase("N")) {
61
+                play = false;
62
+            }
54
         }
63
         }
64
+
55
     }
65
     }
56
 
66
 
57
     public int getIntFromUser(){
67
     public int getIntFromUser(){

+ 44
- 31
src/main/java/io/zipcoder/casino/Yahtzee.java View File

3
 import java.util.ArrayList;
3
 import java.util.ArrayList;
4
 import java.util.Scanner;
4
 import java.util.Scanner;
5
 
5
 
6
-public class Yahtzee extends DiceGame implements Game, Gamble{
6
+public class Yahtzee extends DiceGame implements Game, Gamble {
7
 
7
 
8
     DicePlayer dicePlayer;
8
     DicePlayer dicePlayer;
9
     private Scanner scanner = new Scanner(System.in);
9
     private Scanner scanner = new Scanner(System.in);
10
     int betAmount = 0;
10
     int betAmount = 0;
11
-    Console console = new Console();
12
 
11
 
13
     public Yahtzee(Player player) {
12
     public Yahtzee(Player player) {
14
         this.dicePlayer = new DicePlayer(player);
13
         this.dicePlayer = new DicePlayer(player);
23
     }
22
     }
24
 
23
 
25
 
24
 
25
+    @Override
26
+    public void quit() {
27
+
28
+    }
29
+
26
     public void startGame() {
30
     public void startGame() {
27
         Dice dice1 = new Dice();
31
         Dice dice1 = new Dice();
28
         Dice dice2 = new Dice();
32
         Dice dice2 = new Dice();
46
         payout();
50
         payout();
47
         dicePlayer.printBalanceAtEnd();
51
         dicePlayer.printBalanceAtEnd();
48
         System.out.println();
52
         System.out.println();
49
-        quit();
50
     }
53
     }
51
 
54
 
52
     public void startRound() {
55
     public void startRound() {
53
 
56
 
54
-        for(int i = 0; i < ScoreSheet.getSize(); i++) {
57
+        for (int i = 0; i < ScoreSheet.getSize(); i++) {
55
             for (Dice d : dicePlayer.getCup()) {
58
             for (Dice d : dicePlayer.getCup()) {
56
                 d.roll();
59
                 d.roll();
57
             }
60
             }
65
 
68
 
66
     }
69
     }
67
 
70
 
68
-    public void roundRoutine(){
71
+    public void roundRoutine() {
69
 
72
 
70
         giveOptions();
73
         giveOptions();
71
         giveOptions();
74
         giveOptions();
104
         }
107
         }
105
     }
108
     }
106
 
109
 
107
-    public void reRoll(String diceToRoll){
110
+    public void reRoll(String diceToRoll) {
108
 
111
 
109
         String[] numbersString = diceToRoll.split(" ");
112
         String[] numbersString = diceToRoll.split(" ");
110
         ArrayList<Integer> numbers = new ArrayList<>();
113
         ArrayList<Integer> numbers = new ArrayList<>();
111
-        for(String s: numbersString) {
114
+        for (String s : numbersString) {
112
             numbers.add(Integer.parseInt(s));
115
             numbers.add(Integer.parseInt(s));
113
         }
116
         }
114
 
117
 
115
-        for(Integer i : numbers) {
116
-            for(int j = 0; j < 5; j++) {
117
-                if(i == dicePlayer.getCup()[j].getValue()) {
118
+        for (Integer i : numbers) {
119
+            for (int j = 0; j < 5; j++) {
120
+                if (i == dicePlayer.getCup()[j].getValue()) {
118
                     dicePlayer.getCup()[j].roll();
121
                     dicePlayer.getCup()[j].roll();
119
                     break;
122
                     break;
120
                 }
123
                 }
128
         int choice = 13;
131
         int choice = 13;
129
         ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
132
         ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
130
 
133
 
131
-        while(validEntry) {
134
+        while (validEntry) {
132
             dicePlayer.getScoreSheet().printScoreCard();
135
             dicePlayer.getScoreSheet().printScoreCard();
133
             System.out.println();
136
             System.out.println();
134
             System.out.println("Which row would you like to apply your turn to on the scoresheet?.\n" +
137
             System.out.println("Which row would you like to apply your turn to on the scoresheet?.\n" +
138
             Scanner scanner2 = new Scanner(System.in);
141
             Scanner scanner2 = new Scanner(System.in);
139
             choice = scanner2.nextInt();
142
             choice = scanner2.nextInt();
140
 
143
 
141
-            switch(choice) {
142
-                case 1: row = ScoreSheet.ROW.ACES;
144
+            switch (choice) {
145
+                case 1:
146
+                    row = ScoreSheet.ROW.ACES;
143
                     break;
147
                     break;
144
-                case 2: row = ScoreSheet.ROW.TWOS;
148
+                case 2:
149
+                    row = ScoreSheet.ROW.TWOS;
145
                     break;
150
                     break;
146
-                case 3: row = ScoreSheet.ROW.THREES;
151
+                case 3:
152
+                    row = ScoreSheet.ROW.THREES;
147
                     break;
153
                     break;
148
-                case 4: row = ScoreSheet.ROW.FOURS;
154
+                case 4:
155
+                    row = ScoreSheet.ROW.FOURS;
149
                     break;
156
                     break;
150
-                case 5: row = ScoreSheet.ROW.FIVES;
157
+                case 5:
158
+                    row = ScoreSheet.ROW.FIVES;
151
                     break;
159
                     break;
152
-                case 6: row = ScoreSheet.ROW.SIXES;
160
+                case 6:
161
+                    row = ScoreSheet.ROW.SIXES;
153
                     break;
162
                     break;
154
-                case 7: row = ScoreSheet.ROW.THREEOFAKIND;
163
+                case 7:
164
+                    row = ScoreSheet.ROW.THREEOFAKIND;
155
                     break;
165
                     break;
156
-                case 8: row = ScoreSheet.ROW.FOUROFAKIND;
166
+                case 8:
167
+                    row = ScoreSheet.ROW.FOUROFAKIND;
157
                     break;
168
                     break;
158
-                case 9: row = ScoreSheet.ROW.FULLHOUSE;
169
+                case 9:
170
+                    row = ScoreSheet.ROW.FULLHOUSE;
159
                     break;
171
                     break;
160
-                case 10: row = ScoreSheet.ROW.SMALLSTRAIGHT;
172
+                case 10:
173
+                    row = ScoreSheet.ROW.SMALLSTRAIGHT;
161
                     break;
174
                     break;
162
-                case 11: row = ScoreSheet.ROW.LARGESTRAIGHT;
175
+                case 11:
176
+                    row = ScoreSheet.ROW.LARGESTRAIGHT;
163
                     break;
177
                     break;
164
-                case 12: row = ScoreSheet.ROW.YAHTZEE;
178
+                case 12:
179
+                    row = ScoreSheet.ROW.YAHTZEE;
165
                     break;
180
                     break;
166
-                case 13: row = ScoreSheet.ROW.CHANCE;
181
+                case 13:
182
+                    row = ScoreSheet.ROW.CHANCE;
167
                     break;
183
                     break;
168
             }
184
             }
169
             if (dicePlayer.getScoreSheet().getScore(row) == null) {
185
             if (dicePlayer.getScoreSheet().getScore(row) == null) {
176
         dicePlayer.getScoreSheet().setRow(row, dicePlayer.getCup());
192
         dicePlayer.getScoreSheet().setRow(row, dicePlayer.getCup());
177
         System.out.println();
193
         System.out.println();
178
         dicePlayer.getScoreSheet().printScoreCard();
194
         dicePlayer.getScoreSheet().printScoreCard();
179
-        }
195
+    }
180
 
196
 
181
     @Override
197
     @Override
182
     public void bet(int betAmount) {
198
     public void bet(int betAmount) {
187
     public void payout() {
203
     public void payout() {
188
         int score = dicePlayer.getScoreSheet().getTotalScore();
204
         int score = dicePlayer.getScoreSheet().getTotalScore();
189
         int payOut = 0;
205
         int payOut = 0;
190
-        if(score == 1575) {
206
+        if (score == 1575) {
191
             payOut = getBid() * 100;
207
             payOut = getBid() * 100;
192
         } else if (score > 1000) {
208
         } else if (score > 1000) {
193
             payOut = getBid() * 20;
209
             payOut = getBid() * 20;
206
         System.out.println("You won $" + payOut);
222
         System.out.println("You won $" + payOut);
207
     }
223
     }
208
 
224
 
209
-    public void quit() {
210
-        console.chooseGame();
211
-    }
212
-}
225
+}