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,34 +24,44 @@ public class Console {
24 24
 
25 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 67
     public int getIntFromUser(){

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

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