|
@@ -1,9 +1,13 @@
|
1
|
1
|
package io.zipcoder.casino;
|
2
|
2
|
|
|
3
|
+import java.util.ArrayList;
|
|
4
|
+import java.util.Scanner;
|
|
5
|
+
|
3
|
6
|
public class Yahtzee extends DiceGame implements Game{
|
4
|
7
|
|
5
|
8
|
private Dice[] cup;
|
6
|
9
|
DicePlayer dicePlayer;
|
|
10
|
+ private Scanner scanner = new Scanner(System.in);
|
7
|
11
|
|
8
|
12
|
public Yahtzee(Player player) {
|
9
|
13
|
this.dicePlayer = new DicePlayer(player);
|
|
@@ -14,12 +18,21 @@ public class Yahtzee extends DiceGame implements Game{
|
14
|
18
|
player1.getScoreSheet().getTotalScore();
|
15
|
19
|
}
|
16
|
20
|
|
17
|
|
- public void reRoll(){
|
18
|
|
-
|
19
|
|
- }
|
20
|
|
-
|
21
|
|
- public void stopRoll(){
|
|
21
|
+ public void reRoll(String diceToRoll){
|
22
|
22
|
|
|
23
|
+ String[] numbersString = diceToRoll.replace(",", "").split(" ");
|
|
24
|
+ ArrayList<Integer> numbers = new ArrayList<>();
|
|
25
|
+ for(String s: numbersString) {
|
|
26
|
+ numbers.add(Integer.parseInt(s));
|
|
27
|
+ }
|
|
28
|
+ for(Integer i : numbers) {
|
|
29
|
+ for(int j = 0; j < 5; j++) {
|
|
30
|
+ if(i == dicePlayer.getCup()[j].getValue()) {
|
|
31
|
+ dicePlayer.getCup()[j].roll();
|
|
32
|
+ break;
|
|
33
|
+ }
|
|
34
|
+ }
|
|
35
|
+ }
|
23
|
36
|
}
|
24
|
37
|
|
25
|
38
|
/**
|
|
@@ -44,26 +57,83 @@ public class Yahtzee extends DiceGame implements Game{
|
44
|
57
|
}
|
45
|
58
|
|
46
|
59
|
public void StartRound() {
|
47
|
|
- for(Dice d : dicePlayer.getCup()) {
|
48
|
|
- d.roll();
|
49
|
|
- }
|
50
|
|
- dicePlayer.printCup();
|
51
|
60
|
|
52
|
|
- //roundRoutine();
|
|
61
|
+ for(int i = 0; i < ScoreSheet.getSize(); i++) {
|
|
62
|
+ for (Dice d : dicePlayer.getCup()) {
|
|
63
|
+ d.roll();
|
|
64
|
+ }
|
|
65
|
+ dicePlayer.printCup();
|
53
|
66
|
|
54
|
|
- }
|
55
|
|
-
|
56
|
|
- public void roundRoutine(){
|
|
67
|
+ roundRoutine();
|
|
68
|
+ recordingScore();
|
|
69
|
+ }
|
57
|
70
|
|
58
|
|
- //ask if they want to score, or roll again?
|
|
71
|
+ }
|
59
|
72
|
|
60
|
|
- //roll again if requested
|
|
73
|
+ public void recordingScore() {
|
|
74
|
+ System.out.println("Which row would you like to apply your turn to on the scoresheet?.\n" +
|
|
75
|
+ "Remember you can only use each row once!");
|
|
76
|
+ dicePlayer.getScoreSheet().printScoreCard();
|
|
77
|
+
|
|
78
|
+ int choice = scanner.nextInt();
|
|
79
|
+ ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
|
|
80
|
+ switch(choice) {
|
|
81
|
+ case 1: row = ScoreSheet.ROW.ACES;
|
|
82
|
+ break;
|
|
83
|
+ case 2: row = ScoreSheet.ROW.TWOS;
|
|
84
|
+ break;
|
|
85
|
+ case 3: row = ScoreSheet.ROW.THREES;
|
|
86
|
+ break;
|
|
87
|
+ case 4: row = ScoreSheet.ROW.FOURS;
|
|
88
|
+ break;
|
|
89
|
+ case 5: row = ScoreSheet.ROW.FIVES;
|
|
90
|
+ break;
|
|
91
|
+ case 6: row = ScoreSheet.ROW.SIXES;
|
|
92
|
+ break;
|
|
93
|
+ case 7: row = ScoreSheet.ROW.THREEOFAKIND;
|
|
94
|
+ break;
|
|
95
|
+ case 8: row = ScoreSheet.ROW.FOUROFAKIND;
|
|
96
|
+ break;
|
|
97
|
+ case 9: row = ScoreSheet.ROW.FULLHOUSE;
|
|
98
|
+ break;
|
|
99
|
+ case 10: row = ScoreSheet.ROW.SMALLSTRAIGHT;
|
|
100
|
+ break;
|
|
101
|
+ case 11: row = ScoreSheet.ROW.LARGESTRAIGHT;
|
|
102
|
+ break;
|
|
103
|
+ case 12: row = ScoreSheet.ROW.YAHTZEE;
|
|
104
|
+ break;
|
|
105
|
+ case 13: row = ScoreSheet.ROW.CHANCE;
|
|
106
|
+ break;
|
|
107
|
+ }
|
|
108
|
+ dicePlayer.getScoreSheet().setRow(row, dicePlayer.getCup());
|
|
109
|
+ }
|
61
|
110
|
|
62
|
|
- //continue to roll until no more rolls are left
|
63
|
111
|
|
64
|
|
- //ask user how they would like to score
|
|
112
|
+ public void roundRoutine(){
|
65
|
113
|
|
66
|
|
- //calculate the users score
|
|
114
|
+ for(int i = 0; i < 2; i++) {
|
|
115
|
+ System.out.println("Would you like to:\n1. Roll all dice again.\n2. Roll some dice again.\n3.Stop rolling and score.");
|
|
116
|
+ int choice = scanner.nextInt();
|
|
117
|
+
|
|
118
|
+ switch (choice) {
|
|
119
|
+ case 1:
|
|
120
|
+ for (Dice d : dicePlayer.getCup()) {
|
|
121
|
+ d.roll();
|
|
122
|
+ }
|
|
123
|
+ dicePlayer.printCup();
|
|
124
|
+ break;
|
|
125
|
+
|
|
126
|
+ case 2:
|
|
127
|
+ System.out.println("Which numbers would you like to reroll?");
|
|
128
|
+ String diceToRoll = scanner.next();
|
|
129
|
+ reRoll(diceToRoll);
|
|
130
|
+ dicePlayer.printCup();
|
|
131
|
+ break;
|
|
132
|
+
|
|
133
|
+ case 3:
|
|
134
|
+ break;
|
|
135
|
+ }
|
|
136
|
+ }
|
67
|
137
|
|
68
|
138
|
}
|
69
|
139
|
}
|