|
@@ -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
|
+}
|