|
@@ -8,16 +8,21 @@ import java.util.*;
|
8
|
8
|
|
9
|
9
|
public class Yahtzee extends DiceGame {
|
10
|
10
|
|
11
|
|
- Player aPlayer;
|
12
|
|
- Dice diceRoller = new Dice(5);
|
13
|
|
- Die[] dice = diceRoller.rollAll();
|
14
|
|
- int[] diceValueCounts = new int[6];
|
15
|
|
- Console aConsole = new Console();
|
16
|
|
- boolean playAgain;
|
17
|
|
- boolean scoreSheetFull = false;
|
18
|
|
- Map<YahtzeeField, Integer> scoreSheet = new LinkedHashMap<YahtzeeField, Integer>();
|
19
|
|
-
|
|
11
|
+ //==================================================================================
|
|
12
|
+ // Fields
|
|
13
|
+ //==================================================================================
|
|
14
|
+ private Console aConsole = new Console();
|
|
15
|
+ private Player aPlayer;
|
|
16
|
+ private Map<YahtzeeField, Integer> scoreSheet = new LinkedHashMap<>();
|
|
17
|
+ private Dice diceRoller = new Dice(5);
|
|
18
|
+ private Die[] dice = diceRoller.rollAll();
|
|
19
|
+ private int[] diceValues = new int[5];
|
|
20
|
+ private int[] diceValueCounts = new int[6];
|
|
21
|
+ private boolean playAgain = true;
|
20
|
22
|
|
|
23
|
+ //==================================================================================
|
|
24
|
+ // Constructor
|
|
25
|
+ //==================================================================================
|
21
|
26
|
public Yahtzee(Player aPlayer) {
|
22
|
27
|
this.aPlayer = aPlayer;
|
23
|
28
|
}
|
|
@@ -27,32 +32,23 @@ public class Yahtzee extends DiceGame {
|
27
|
32
|
//==================================================================================
|
28
|
33
|
|
29
|
34
|
public void playGame() {
|
30
|
|
-
|
31
|
35
|
aConsole.println("Welcome to Yahtzee " + aPlayer.getName());
|
32
|
|
-
|
33
|
|
- boolean playAgain = true;
|
34
|
36
|
while (playAgain) {
|
35
|
|
-
|
36
|
37
|
createBlankScoreSheet();
|
37
|
38
|
printScoreSheet();
|
38
|
|
-
|
|
39
|
+ boolean scoreSheetFull = false;
|
39
|
40
|
while (!scoreSheetFull) {
|
40
|
41
|
rollDice();
|
41
|
|
- printDice(getDiceValues(this.dice));
|
42
|
|
-
|
|
42
|
+ printDice();
|
43
|
43
|
rollAgainLoop();
|
44
|
|
-
|
45
|
|
- YahtzeeField fieldChoice = chooseYahtzeeField();
|
46
|
|
- int score = scoreDice(fieldChoice);
|
47
|
|
- updateScoreSheet(fieldChoice, score);
|
|
44
|
+ scoreRoll();
|
48
|
45
|
printScoreSheet();
|
49
|
46
|
scoreSheetFull = checkScoreSheetForCompletion();
|
50
|
47
|
}
|
51
|
|
-
|
52
|
48
|
int totalScore = getTotalScore();
|
53
|
49
|
printEndOfGameMessage(totalScore);
|
|
50
|
+ playAgain = userInputYesNoToBoolean(aConsole.getStringInput("Do you want to play again?"));
|
54
|
51
|
}
|
55
|
|
-
|
56
|
52
|
}
|
57
|
53
|
|
58
|
54
|
//==================================================================================
|
|
@@ -62,7 +58,7 @@ public class Yahtzee extends DiceGame {
|
62
|
58
|
/*
|
63
|
59
|
Create blank score sheet
|
64
|
60
|
*/
|
65
|
|
- public void createBlankScoreSheet() {
|
|
61
|
+ private void createBlankScoreSheet() {
|
66
|
62
|
for (YahtzeeField field : YahtzeeField.values()) {
|
67
|
63
|
scoreSheet.put(field, null);
|
68
|
64
|
}
|
|
@@ -71,7 +67,7 @@ public class Yahtzee extends DiceGame {
|
71
|
67
|
/*
|
72
|
68
|
Check score sheet for completion
|
73
|
69
|
*/
|
74
|
|
- public boolean checkScoreSheetForCompletion() {
|
|
70
|
+ private boolean checkScoreSheetForCompletion() {
|
75
|
71
|
for (Map.Entry<YahtzeeField, Integer> entry : scoreSheet.entrySet()) {
|
76
|
72
|
Integer value = entry.getValue();
|
77
|
73
|
if (value == null) {
|
|
@@ -84,17 +80,17 @@ public class Yahtzee extends DiceGame {
|
84
|
80
|
/*
|
85
|
81
|
Print score sheet
|
86
|
82
|
*/
|
87
|
|
- public void printScoreSheet() {
|
|
83
|
+ private void printScoreSheet() {
|
88
|
84
|
aConsole.println("Scoresheet: " + scoreSheet.toString());
|
89
|
85
|
}
|
90
|
86
|
|
91
|
87
|
/*
|
92
|
88
|
Get total score
|
93
|
89
|
*/
|
94
|
|
- public int getTotalScore() {
|
|
90
|
+ private int getTotalScore() {
|
95
|
91
|
int sumOfUpperSection = getUpperSectionScore();
|
96
|
92
|
int bonus = 0;
|
97
|
|
- if (sumOfUpperSection >= 63){
|
|
93
|
+ if (sumOfUpperSection >= 63) {
|
98
|
94
|
bonus = 35;
|
99
|
95
|
}
|
100
|
96
|
int sumOfLowerSection = getLowerSectionScore();
|
|
@@ -104,15 +100,15 @@ public class Yahtzee extends DiceGame {
|
104
|
100
|
/*
|
105
|
101
|
Get upper section score
|
106
|
102
|
*/
|
107
|
|
- public int getUpperSectionScore(){
|
|
103
|
+ private int getUpperSectionScore() {
|
108
|
104
|
int upperScore = 0;
|
109
|
105
|
Iterator it = scoreSheet.entrySet().iterator();
|
110
|
|
- while (it.hasNext()){
|
111
|
|
- Map.Entry scoreEntry = (Map.Entry)it.next();
|
|
106
|
+ while (it.hasNext()) {
|
|
107
|
+ Map.Entry scoreEntry = (Map.Entry) it.next();
|
112
|
108
|
if (scoreEntry.getKey() == YahtzeeField.ACES || scoreEntry.getKey() == YahtzeeField.TWOS ||
|
113
|
109
|
scoreEntry.getKey() == YahtzeeField.THREES || scoreEntry.getKey() == YahtzeeField.FOURS ||
|
114
|
|
- scoreEntry.getKey() == YahtzeeField.FIVES || scoreEntry.getKey() == YahtzeeField.SIXES){
|
115
|
|
- upperScore += (int)(scoreEntry.getValue());
|
|
110
|
+ scoreEntry.getKey() == YahtzeeField.FIVES || scoreEntry.getKey() == YahtzeeField.SIXES) {
|
|
111
|
+ upperScore += (int) (scoreEntry.getValue());
|
116
|
112
|
}
|
117
|
113
|
}
|
118
|
114
|
return upperScore;
|
|
@@ -121,40 +117,49 @@ public class Yahtzee extends DiceGame {
|
121
|
117
|
/*
|
122
|
118
|
Get lower section score
|
123
|
119
|
*/
|
124
|
|
- public int getLowerSectionScore(){
|
|
120
|
+ private int getLowerSectionScore() {
|
125
|
121
|
int lowerScore = 0;
|
126
|
122
|
Iterator it = scoreSheet.entrySet().iterator();
|
127
|
|
- while (it.hasNext()){
|
128
|
|
- Map.Entry scoreEntry = (Map.Entry)it.next();
|
|
123
|
+ while (it.hasNext()) {
|
|
124
|
+ Map.Entry scoreEntry = (Map.Entry) it.next();
|
129
|
125
|
if (scoreEntry.getKey() == YahtzeeField.THREEOFAKIND || scoreEntry.getKey() == YahtzeeField.FOUROFAKIND ||
|
130
|
126
|
scoreEntry.getKey() == YahtzeeField.FULLHOUSE || scoreEntry.getKey() == YahtzeeField.SMSTRAIGHT ||
|
131
|
127
|
scoreEntry.getKey() == YahtzeeField.LGSTRAIGHT || scoreEntry.getKey() == YahtzeeField.YAHTZEE ||
|
132
|
|
- scoreEntry.getKey() == YahtzeeField.CHANCE){
|
133
|
|
- lowerScore += (int)(scoreEntry.getValue());
|
|
128
|
+ scoreEntry.getKey() == YahtzeeField.CHANCE) {
|
|
129
|
+ lowerScore += (int) (scoreEntry.getValue());
|
134
|
130
|
}
|
135
|
131
|
}
|
136
|
132
|
return lowerScore;
|
137
|
133
|
}
|
138
|
134
|
|
139
|
|
- /*
|
140
|
|
- Print end of game stats
|
141
|
|
- */
|
142
|
|
- public void printEndOfGameMessage(int totalScore){
|
143
|
|
- aConsole.println("Game over!");
|
144
|
|
- aConsole.println("Your total score is: " + totalScore);
|
145
|
|
- if(aConsole.yesOrNo("Would you like to play again?").equalsIgnoreCase("no")){
|
146
|
|
- playAgain= false;
|
147
|
|
- }
|
148
|
|
- }
|
|
135
|
+ /*
|
|
136
|
+ Print end of game stats
|
|
137
|
+ */
|
|
138
|
+ private void printEndOfGameMessage(int totalScore) {
|
|
139
|
+ aConsole.println("Game over!");
|
|
140
|
+ aConsole.println("Your total score is: " + totalScore);
|
|
141
|
+ if (aConsole.yesOrNo("Would you like to play again?").equalsIgnoreCase("no")) {
|
|
142
|
+ playAgain = false;
|
|
143
|
+ }
|
|
144
|
+ }
|
149
|
145
|
|
150
|
146
|
//==================================================================================
|
151
|
147
|
// SCORING ROLL METHODS
|
152
|
148
|
//==================================================================================
|
153
|
149
|
|
154
|
150
|
/*
|
|
151
|
+ Score roll
|
|
152
|
+ */
|
|
153
|
+ public void scoreRoll() {
|
|
154
|
+ YahtzeeField fieldChoice = chooseYahtzeeField();
|
|
155
|
+ int score = scoreDice(fieldChoice);
|
|
156
|
+ updateScoreSheet(fieldChoice, score);
|
|
157
|
+ }
|
|
158
|
+
|
|
159
|
+ /*
|
155
|
160
|
See fields and formula for score
|
156
|
161
|
*/
|
157
|
|
- public void printRules(){
|
|
162
|
+ public void printRules() {
|
158
|
163
|
aConsole.println("Roll 5 dice up to 3 times and try to get the highest score");
|
159
|
164
|
}
|
160
|
165
|
|
|
@@ -165,7 +170,7 @@ public class Yahtzee extends DiceGame {
|
165
|
170
|
String userInput = aConsole.getStringInput("Which field do you want to score?").toUpperCase();
|
166
|
171
|
boolean inputIsValid = isValidYahtzeeField(userInput);
|
167
|
172
|
|
168
|
|
- while (!inputIsValid){
|
|
173
|
+ while (!inputIsValid) {
|
169
|
174
|
aConsole.println("please enter valid & free yahtzee field.");
|
170
|
175
|
userInput = aConsole.getStringInput("Which field do you want to score?").toUpperCase();
|
171
|
176
|
inputIsValid = isValidYahtzeeField(userInput);
|
|
@@ -180,7 +185,7 @@ public class Yahtzee extends DiceGame {
|
180
|
185
|
public boolean isValidYahtzeeField(String userInput) {
|
181
|
186
|
for (YahtzeeField aYahtzeeField : YahtzeeField.values()) {
|
182
|
187
|
if (aYahtzeeField.toString().equals(userInput)) {
|
183
|
|
- if(scoreSheet.get(YahtzeeField.valueOf(userInput)) == null){
|
|
188
|
+ if (scoreSheet.get(YahtzeeField.valueOf(userInput)) == null) {
|
184
|
189
|
return true;
|
185
|
190
|
}
|
186
|
191
|
}
|
|
@@ -191,10 +196,8 @@ public class Yahtzee extends DiceGame {
|
191
|
196
|
/*
|
192
|
197
|
Score dice
|
193
|
198
|
*/
|
194
|
|
- public int scoreDice(YahtzeeField yahtzeeField) {
|
195
|
|
-
|
196
|
|
- updateDiceValues();
|
197
|
|
-
|
|
199
|
+ private int scoreDice(YahtzeeField yahtzeeField) {
|
|
200
|
+ setDiceValueCounts();
|
198
|
201
|
int score = 0;
|
199
|
202
|
switch (yahtzeeField) {
|
200
|
203
|
case ACES:
|
|
@@ -241,20 +244,10 @@ public class Yahtzee extends DiceGame {
|
241
|
244
|
}
|
242
|
245
|
|
243
|
246
|
/*
|
244
|
|
- Get count of each value in dice
|
245
|
|
- */
|
246
|
|
- public void updateDiceValues(){
|
247
|
|
- resetDiceValues();
|
248
|
|
- for (Die d : dice){
|
249
|
|
- diceValueCounts[d.getValue()-1]++;
|
250
|
|
- }
|
251
|
|
- }
|
252
|
|
-
|
253
|
|
- /*
|
254
|
247
|
Reset count of each value in dice
|
255
|
248
|
*/
|
256
|
|
- public void resetDiceValues(){
|
257
|
|
- for (int i=0; i < diceValueCounts.length; i++){
|
|
249
|
+ public void resetDiceValueCounts() {
|
|
250
|
+ for (int i = 0; i < diceValueCounts.length; i++) {
|
258
|
251
|
diceValueCounts[i] = 0;
|
259
|
252
|
}
|
260
|
253
|
}
|
|
@@ -262,9 +255,9 @@ public class Yahtzee extends DiceGame {
|
262
|
255
|
/*
|
263
|
256
|
Check "of a kind" criteria is met
|
264
|
257
|
*/
|
265
|
|
- public boolean ofAKindCriteria(int ofAKind){
|
266
|
|
- for (int count : diceValueCounts){
|
267
|
|
- if (count >= ofAKind){
|
|
258
|
+ public boolean ofAKindCriteria(int ofAKind) {
|
|
259
|
+ for (int count : diceValueCounts) {
|
|
260
|
+ if (count >= ofAKind) {
|
268
|
261
|
return true;
|
269
|
262
|
}
|
270
|
263
|
}
|
|
@@ -277,7 +270,7 @@ public class Yahtzee extends DiceGame {
|
277
|
270
|
public int scoreOfAKind(boolean meetsOfAKindCriteria) {
|
278
|
271
|
int score = 0;
|
279
|
272
|
if (meetsOfAKindCriteria) {
|
280
|
|
- for (Die d : dice){
|
|
273
|
+ for (Die d : dice) {
|
281
|
274
|
score += d.getValue();
|
282
|
275
|
}
|
283
|
276
|
}
|
|
@@ -287,9 +280,9 @@ public class Yahtzee extends DiceGame {
|
287
|
280
|
/*
|
288
|
281
|
Score yahtzee
|
289
|
282
|
*/
|
290
|
|
- public int scoreYahtzee(boolean meetsOfAKindCriteria){
|
|
283
|
+ private int scoreYahtzee(boolean meetsOfAKindCriteria) {
|
291
|
284
|
int score = 0;
|
292
|
|
- if (meetsOfAKindCriteria){
|
|
285
|
+ if (meetsOfAKindCriteria) {
|
293
|
286
|
score = 50;
|
294
|
287
|
}
|
295
|
288
|
return score;
|
|
@@ -298,14 +291,14 @@ public class Yahtzee extends DiceGame {
|
298
|
291
|
/*
|
299
|
292
|
Check Full House criteria is met
|
300
|
293
|
*/
|
301
|
|
- public boolean fullHouseCriteria(){
|
|
294
|
+ public boolean fullHouseCriteria() {
|
302
|
295
|
int i = 0;
|
303
|
|
- for (int count : diceValueCounts){
|
304
|
|
- if (count >= 2){
|
|
296
|
+ for (int count : diceValueCounts) {
|
|
297
|
+ if (count >= 2) {
|
305
|
298
|
i++;
|
306
|
299
|
}
|
307
|
300
|
}
|
308
|
|
- if(i==2){
|
|
301
|
+ if (i == 2) {
|
309
|
302
|
return true;
|
310
|
303
|
}
|
311
|
304
|
return false;
|
|
@@ -314,9 +307,9 @@ public class Yahtzee extends DiceGame {
|
314
|
307
|
/*
|
315
|
308
|
Score Full House
|
316
|
309
|
*/
|
317
|
|
- public int scoreFullHouse(boolean meetsFullHouseCriteria){
|
|
310
|
+ public int scoreFullHouse(boolean meetsFullHouseCriteria) {
|
318
|
311
|
int score = 0;
|
319
|
|
- if (meetsFullHouseCriteria){
|
|
312
|
+ if (meetsFullHouseCriteria) {
|
320
|
313
|
score = 25;
|
321
|
314
|
}
|
322
|
315
|
return score;
|
|
@@ -325,15 +318,15 @@ public class Yahtzee extends DiceGame {
|
325
|
318
|
/*
|
326
|
319
|
Check Small Straight criteria is met
|
327
|
320
|
*/
|
328
|
|
- public boolean smStraighCriteria(){
|
|
321
|
+ public boolean smStraighCriteria() {
|
329
|
322
|
boolean meetsCriteria = false;
|
330
|
323
|
int i = 0;
|
331
|
|
- for (int count : diceValueCounts){
|
332
|
|
- if (count > 1){
|
|
324
|
+ for (int count : diceValueCounts) {
|
|
325
|
+ if (count > 1) {
|
333
|
326
|
i++;
|
334
|
327
|
}
|
335
|
328
|
}
|
336
|
|
- if(i<=1){
|
|
329
|
+ if (i <= 1) {
|
337
|
330
|
meetsCriteria = true;
|
338
|
331
|
}
|
339
|
332
|
return meetsCriteria;
|
|
@@ -342,9 +335,9 @@ public class Yahtzee extends DiceGame {
|
342
|
335
|
/*
|
343
|
336
|
Score SM Straight
|
344
|
337
|
*/
|
345
|
|
- public int scoreSmStraight(boolean meetsSmStraightCriteria){
|
|
338
|
+ private int scoreSmStraight(boolean meetsSmStraightCriteria) {
|
346
|
339
|
int score = 0;
|
347
|
|
- if (meetsSmStraightCriteria){
|
|
340
|
+ if (meetsSmStraightCriteria) {
|
348
|
341
|
score = 30;
|
349
|
342
|
}
|
350
|
343
|
return score;
|
|
@@ -353,15 +346,15 @@ public class Yahtzee extends DiceGame {
|
353
|
346
|
/*
|
354
|
347
|
Check Large Straight criteria is met
|
355
|
348
|
*/
|
356
|
|
- public boolean lgStraightCriteria(){
|
|
349
|
+ public boolean lgStraightCriteria() {
|
357
|
350
|
boolean meetsCriteria = false;
|
358
|
351
|
int i = 0;
|
359
|
|
- for (int count : diceValueCounts){
|
360
|
|
- if (count > 1){
|
|
352
|
+ for (int count : diceValueCounts) {
|
|
353
|
+ if (count > 1) {
|
361
|
354
|
i++;
|
362
|
355
|
}
|
363
|
356
|
}
|
364
|
|
- if(i<1){
|
|
357
|
+ if (i < 1) {
|
365
|
358
|
meetsCriteria = true;
|
366
|
359
|
}
|
367
|
360
|
return meetsCriteria;
|
|
@@ -370,9 +363,9 @@ public class Yahtzee extends DiceGame {
|
370
|
363
|
/*
|
371
|
364
|
Score LG Straight
|
372
|
365
|
*/
|
373
|
|
- public int scoreLgStraight(boolean meetsLgStraightCriteria){
|
|
366
|
+ public int scoreLgStraight(boolean meetsLgStraightCriteria) {
|
374
|
367
|
int score = 0;
|
375
|
|
- if (meetsLgStraightCriteria){
|
|
368
|
+ if (meetsLgStraightCriteria) {
|
376
|
369
|
score = 40;
|
377
|
370
|
}
|
378
|
371
|
return score;
|
|
@@ -382,7 +375,7 @@ public class Yahtzee extends DiceGame {
|
382
|
375
|
Score dice "count" fields: aces, twos, threes, fours, fives, or sixes
|
383
|
376
|
*/
|
384
|
377
|
public int scoreCountFields(int countField) {
|
385
|
|
- return diceValueCounts[countField-1] * countField;
|
|
378
|
+ return diceValueCounts[countField - 1] * countField;
|
386
|
379
|
}
|
387
|
380
|
|
388
|
381
|
/*
|
|
@@ -397,14 +390,6 @@ public class Yahtzee extends DiceGame {
|
397
|
390
|
//==================================================================================
|
398
|
391
|
|
399
|
392
|
/*
|
400
|
|
- Roll dice
|
401
|
|
- */
|
402
|
|
- public Die[] rollDice() {
|
403
|
|
- dice = diceRoller.rollAll();
|
404
|
|
- return dice;
|
405
|
|
- }
|
406
|
|
-
|
407
|
|
- /*
|
408
|
393
|
Ask user if they want to roll again
|
409
|
394
|
*/
|
410
|
395
|
public String userInputRollAgain() {
|
|
@@ -414,7 +399,7 @@ public class Yahtzee extends DiceGame {
|
414
|
399
|
/*
|
415
|
400
|
Convert user's choice to roll again to boolean
|
416
|
401
|
*/
|
417
|
|
- public boolean userInputRollAgainBoolean(String userInputString) {
|
|
402
|
+ public boolean userInputYesNoToBoolean(String userInputString) {
|
418
|
403
|
if (userInputString.equals("YES")) {
|
419
|
404
|
return true;
|
420
|
405
|
} else {
|
|
@@ -428,7 +413,7 @@ public class Yahtzee extends DiceGame {
|
428
|
413
|
public void rollAgainLoop() {
|
429
|
414
|
|
430
|
415
|
String rollAgainString = userInputRollAgain();
|
431
|
|
- boolean rollAgain = userInputRollAgainBoolean(rollAgainString);
|
|
416
|
+ boolean rollAgain = userInputYesNoToBoolean(rollAgainString);
|
432
|
417
|
|
433
|
418
|
int rollCounter = 1;
|
434
|
419
|
while (rollAgain) {
|
|
@@ -437,14 +422,14 @@ public class Yahtzee extends DiceGame {
|
437
|
422
|
Integer[] diceToRollAgain = turnUserInputRollAgainToArray(diceToRollAgainList);
|
438
|
423
|
//roll remaining dice
|
439
|
424
|
rollSelectedDiceAgain(diceToRollAgain);
|
440
|
|
- printDice(getDiceValues(this.dice));
|
|
425
|
+ printDice();
|
441
|
426
|
rollCounter++;
|
442
|
427
|
if (rollCounter >= 3) {
|
443
|
428
|
break;
|
444
|
429
|
}
|
445
|
430
|
|
446
|
431
|
rollAgainString = userInputRollAgain();
|
447
|
|
- rollAgain = userInputRollAgainBoolean(rollAgainString);
|
|
432
|
+ rollAgain = userInputYesNoToBoolean(rollAgainString);
|
448
|
433
|
}
|
449
|
434
|
}
|
450
|
435
|
|
|
@@ -458,7 +443,7 @@ public class Yahtzee extends DiceGame {
|
458
|
443
|
String positionOfDiceToKeep = aConsole.getStringInput("Enter position of dice to roll again or enter to perform roll");
|
459
|
444
|
if (positionOfDiceToKeep.equals("")) {
|
460
|
445
|
stillSelecting = false;
|
461
|
|
- } else if (Integer.parseInt(positionOfDiceToKeep) > 0 || Integer.parseInt(positionOfDiceToKeep) < 6){
|
|
446
|
+ } else if (Integer.parseInt(positionOfDiceToKeep) > 0 || Integer.parseInt(positionOfDiceToKeep) < 6) {
|
462
|
447
|
diceToRollAgainList.add(Integer.parseInt(positionOfDiceToKeep));
|
463
|
448
|
stillSelecting = true;
|
464
|
449
|
aConsole.println("Enter a number between 1 and 5 or enter to roll");
|
|
@@ -474,7 +459,7 @@ public class Yahtzee extends DiceGame {
|
474
|
459
|
*/
|
475
|
460
|
public Integer[] turnUserInputRollAgainToArray(List<Integer> diceToRollAgainList) {
|
476
|
461
|
Integer[] diceToRollAgainArray = null;
|
477
|
|
- diceToRollAgainArray = diceToRollAgainList.toArray(new Integer[diceToRollAgainList.size()]);
|
|
462
|
+ diceToRollAgainArray = diceToRollAgainList.toArray(new Integer[0]);
|
478
|
463
|
return diceToRollAgainArray;
|
479
|
464
|
}
|
480
|
465
|
|
|
@@ -490,20 +475,57 @@ public class Yahtzee extends DiceGame {
|
490
|
475
|
/*
|
491
|
476
|
Print dice
|
492
|
477
|
*/
|
493
|
|
- public void printDice(int[] diceValues) {
|
|
478
|
+ public void printDice() {
|
494
|
479
|
DrawYahtzeeDice diceDrawer = new DrawYahtzeeDice();
|
|
480
|
+ setDiceValues();
|
495
|
481
|
aConsole.println(diceDrawer.drawYahtzeeDice(diceValues).toString());
|
496
|
482
|
aConsole.println(" 1 2 3 4 5 ");
|
497
|
483
|
}
|
498
|
484
|
|
|
485
|
+ //==================================================================================
|
|
486
|
+ // Getters and Setters
|
|
487
|
+ //==================================================================================
|
|
488
|
+
|
499
|
489
|
/*
|
500
|
|
- Create dice values array
|
|
490
|
+ Set dice value (roll all dice)
|
501
|
491
|
*/
|
502
|
|
- public int[] getDiceValues(Die[] dice){
|
503
|
|
- int[] diceValues = new int[5];
|
|
492
|
+ public void rollDice() {
|
|
493
|
+ dice = diceRoller.rollAll();
|
|
494
|
+ }
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+ /*
|
|
498
|
+ Set value count array
|
|
499
|
+ */
|
|
500
|
+ public void setDiceValueCounts() {
|
|
501
|
+ resetDiceValueCounts();
|
|
502
|
+ for (Die d : dice) {
|
|
503
|
+ diceValueCounts[d.getValue() - 1]++;
|
|
504
|
+ }
|
|
505
|
+ }
|
|
506
|
+
|
|
507
|
+ /*
|
|
508
|
+ Get value count array
|
|
509
|
+ */
|
|
510
|
+ public int[] getDiceValueCounts() {
|
|
511
|
+ return this.diceValueCounts;
|
|
512
|
+ }
|
|
513
|
+
|
|
514
|
+ /*
|
|
515
|
+ Set dice values array
|
|
516
|
+ */
|
|
517
|
+ public void setDiceValues() {
|
504
|
518
|
for (int i = 0; i < dice.length; i++) {
|
505
|
519
|
diceValues[i] = (dice[i].getValue());
|
506
|
520
|
}
|
507
|
|
- return diceValues;
|
|
521
|
+ }
|
|
522
|
+
|
|
523
|
+ /*
|
|
524
|
+ Get dice values array
|
|
525
|
+ */
|
|
526
|
+ public int[] getDiceValues() {
|
|
527
|
+ return this.diceValues;
|
508
|
528
|
}
|
509
|
529
|
}
|
|
530
|
+
|
|
531
|
+
|