|
@@ -8,9 +8,11 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
|
8
|
8
|
DicePlayer dicePlayer;
|
9
|
9
|
Console console = new Console();
|
10
|
10
|
int betAmount = 0;
|
|
11
|
+ int totalScore = 0;
|
11
|
12
|
|
12
|
13
|
public Yahtzee(Player player) {
|
13
|
14
|
this.dicePlayer = new DicePlayer(player);
|
|
15
|
+ this.totalScore = this.dicePlayer.getScoreSheet().getTotalScore();
|
14
|
16
|
}
|
15
|
17
|
|
16
|
18
|
public int getBid() {
|
|
@@ -21,7 +23,7 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
|
21
|
23
|
this.betAmount = bid;
|
22
|
24
|
}
|
23
|
25
|
|
24
|
|
- public void createGame() {
|
|
26
|
+ public void startGame() {
|
25
|
27
|
Dice dice1 = new Dice();
|
26
|
28
|
Dice dice2 = new Dice();
|
27
|
29
|
Dice dice3 = new Dice();
|
|
@@ -33,70 +35,52 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
|
33
|
35
|
dicePlayer.getCup()[2] = dice3;
|
34
|
36
|
dicePlayer.getCup()[3] = dice4;
|
35
|
37
|
dicePlayer.getCup()[4] = dice5;
|
36
|
|
- }
|
37
|
|
-
|
38
|
|
- public void startGame() {
|
39
|
|
- createGame();
|
40
|
|
- int betAmount = console.getIntFromUser("How much would you like to bet on this game?");
|
41
|
|
- setBid(betAmount);
|
42
|
|
- bet(betAmount);
|
43
|
|
-
|
44
|
|
- startRound();
|
45
|
|
- System.out.println("You scored " + dicePlayer.getScoreSheet().getTotalScore() + " points.");
|
46
|
|
- payout();
|
47
|
|
- dicePlayer.printBalanceAtEnd();
|
48
|
|
- System.out.println();
|
49
|
38
|
|
50
|
39
|
}
|
51
|
40
|
|
|
41
|
+ @Override
|
52
|
42
|
public void startRound() {
|
53
|
|
-
|
54
|
43
|
for (int i = 0; i < ScoreSheet.getSize(); i++) {
|
55
|
|
- for (Dice d : dicePlayer.getCup()) {
|
56
|
|
- d.roll();
|
|
44
|
+ rollAll();
|
|
45
|
+ for(int j = 0; j < 2; j++) {
|
|
46
|
+ int choice = console.getIntFromUser("Would you like to:\n1. Roll all dice again.\n2. Roll some dice again.\n3. Stop rolling and score.\nNumber of Selection: ");
|
|
47
|
+ rollOptions(choice); }
|
|
48
|
+
|
|
49
|
+ boolean validEntry = false;
|
|
50
|
+ ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
|
|
51
|
+ while (!validEntry) {
|
|
52
|
+ Printer.printMessage(dicePlayer.getScoreSheet().scoreCardToString());
|
|
53
|
+
|
|
54
|
+ int choice = console.getIntFromUser("Which row would you like to apply your turn to on the scoresheet?.\n" +
|
|
55
|
+ "Remember you can only use each row once!");
|
|
56
|
+ row = selectingRow(choice);
|
|
57
|
+ validEntry = checkEmptyRow(row);
|
57
|
58
|
}
|
58
|
|
- System.out.println("\nYou rolled:");
|
59
|
|
- dicePlayer.printCup();
|
60
|
|
- System.out.println();
|
|
59
|
+ dicePlayer.getScoreSheet().setRow(row, dicePlayer.getCup());
|
|
60
|
+ Printer.printMessage("\n" + dicePlayer.getScoreSheet().scoreCardToString());
|
61
|
61
|
|
62
|
|
- roundRoutine();
|
63
|
|
- recordingScore();
|
64
|
62
|
}
|
65
|
63
|
|
66
|
64
|
}
|
67
|
65
|
|
68
|
|
- public void roundRoutine() {
|
69
|
|
-
|
70
|
|
- giveOptions();
|
71
|
|
- giveOptions();
|
72
|
|
-
|
|
66
|
+ public void rollAll() {
|
|
67
|
+ for (Dice d : dicePlayer.getCup()) {
|
|
68
|
+ d.roll();
|
|
69
|
+ }
|
|
70
|
+ Printer.printMessage("\nYou rolled:\n" + dicePlayer.cupToString() + "\n");
|
73
|
71
|
}
|
74
|
72
|
|
75
|
|
- public void giveOptions() {
|
76
|
|
- int choice = 0;
|
77
|
|
- 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: ");
|
78
|
73
|
|
79
|
|
- Scanner in = new Scanner(System.in);
|
80
|
|
- choice = in.nextInt();
|
|
74
|
+ public void rollOptions(int choice) {
|
81
|
75
|
|
82
|
76
|
switch (choice) {
|
83
|
77
|
case 1:
|
84
|
|
- for (Dice d : dicePlayer.getCup()) {
|
85
|
|
- d.roll();
|
86
|
|
- }
|
87
|
|
- System.out.println("\nYou rolled:");
|
88
|
|
- dicePlayer.printCup();
|
89
|
|
- System.out.println();
|
|
78
|
+ rollAll();
|
90
|
79
|
break;
|
91
|
80
|
|
92
|
81
|
case 2:
|
93
|
|
- System.out.println("Which numbers would you like to reroll? List the numbers separated by spaces.");
|
94
|
|
- Scanner in2 = new Scanner(System.in);
|
95
|
|
- String diceToRoll = in2.nextLine();
|
|
82
|
+ String diceToRoll = console.getLineFromUser("Which numbers would you like to reroll? List the numbers separated by spaces.");
|
96
|
83
|
reRoll(diceToRoll);
|
97
|
|
- System.out.println("\nYou rolled:");
|
98
|
|
- dicePlayer.printCup();
|
99
|
|
- System.out.println();
|
100
|
84
|
break;
|
101
|
85
|
|
102
|
86
|
case 3:
|
|
@@ -120,24 +104,14 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
|
120
|
104
|
}
|
121
|
105
|
}
|
122
|
106
|
}
|
|
107
|
+ Printer.printMessage("\nYou rolled:\n" + dicePlayer.cupToString() + "\n");
|
|
108
|
+
|
123
|
109
|
}
|
124
|
110
|
|
125
|
|
- public void recordingScore() {
|
|
111
|
+ public ScoreSheet.ROW selectingRow(int choice) {
|
126
|
112
|
|
127
|
|
- boolean validEntry = true;
|
128
|
|
- int choice = 13;
|
129
|
113
|
ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
|
130
|
114
|
|
131
|
|
- while (validEntry) {
|
132
|
|
- Printer.printMessage(dicePlayer.getScoreSheet().scoreCardToString());
|
133
|
|
- System.out.println();
|
134
|
|
- System.out.println("Which row would you like to apply your turn to on the scoresheet?.\n" +
|
135
|
|
- "Remember you can only use each row once!");
|
136
|
|
- System.out.print("Row:");
|
137
|
|
-
|
138
|
|
- Scanner scanner2 = new Scanner(System.in);
|
139
|
|
- choice = scanner2.nextInt();
|
140
|
|
-
|
141
|
115
|
switch (choice) {
|
142
|
116
|
case 1:
|
143
|
117
|
row = ScoreSheet.ROW.ACES;
|
|
@@ -179,17 +153,21 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
|
179
|
153
|
row = ScoreSheet.ROW.CHANCE;
|
180
|
154
|
break;
|
181
|
155
|
}
|
|
156
|
+
|
|
157
|
+ return row;
|
|
158
|
+
|
|
159
|
+ }
|
|
160
|
+
|
|
161
|
+ public boolean checkEmptyRow(ScoreSheet.ROW row) {
|
182
|
162
|
if (dicePlayer.getScoreSheet().getScore(row) == null) {
|
183
|
|
- validEntry = false;
|
|
163
|
+ return true;
|
184
|
164
|
} else {
|
185
|
|
- System.out.println("Error, you have already filled that row");
|
|
165
|
+ Printer.printMessage("Error, you have already filled that row");
|
|
166
|
+ return false;
|
186
|
167
|
}
|
187
|
168
|
}
|
188
|
169
|
|
189
|
|
- dicePlayer.getScoreSheet().setRow(row, dicePlayer.getCup());
|
190
|
|
- System.out.println();
|
191
|
|
- Printer.printMessage(dicePlayer.getScoreSheet().scoreCardToString());
|
192
|
|
- }
|
|
170
|
+
|
193
|
171
|
|
194
|
172
|
@Override
|
195
|
173
|
public void bet(int betAmount) {
|
|
@@ -198,7 +176,7 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
|
198
|
176
|
|
199
|
177
|
@Override
|
200
|
178
|
public void payout() {
|
201
|
|
- int score = dicePlayer.getScoreSheet().getTotalScore();
|
|
179
|
+ int score = getTotalScore();
|
202
|
180
|
int payOut = 0;
|
203
|
181
|
if (score == 1575) {
|
204
|
182
|
payOut = getBid() * 100;
|
|
@@ -216,7 +194,7 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
|
216
|
194
|
payOut = 0;
|
217
|
195
|
}
|
218
|
196
|
dicePlayer.getPlayer().changeBalance(payOut);
|
219
|
|
- System.out.println("You won $" + payOut);
|
|
197
|
+ Printer.printMessage("You won $" + payOut);
|
220
|
198
|
}
|
221
|
199
|
|
222
|
200
|
@Override
|
|
@@ -227,4 +205,8 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
|
227
|
205
|
public DicePlayer getDicePlayer() {
|
228
|
206
|
return dicePlayer;
|
229
|
207
|
}
|
|
208
|
+
|
|
209
|
+ public int getTotalScore() {
|
|
210
|
+ return totalScore;
|
|
211
|
+ }
|
230
|
212
|
}
|