|
@@ -3,46 +3,26 @@ 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{
|
|
6
|
+public class Yahtzee extends DiceGame implements Game, Gamble{
|
7
|
7
|
|
8
|
|
- private Dice[] cup;
|
9
|
8
|
DicePlayer dicePlayer;
|
10
|
9
|
private Scanner scanner = new Scanner(System.in);
|
|
10
|
+ int betAmount = 0;
|
11
|
11
|
|
12
|
12
|
public Yahtzee(Player player) {
|
13
|
13
|
this.dicePlayer = new DicePlayer(player);
|
14
|
14
|
}
|
15
|
15
|
|
16
|
|
- public void compareScore(DicePlayer player1, DicePlayer player2){
|
17
|
|
-
|
18
|
|
- player1.getScoreSheet().getTotalScore();
|
|
16
|
+ public int getBid() {
|
|
17
|
+ return betAmount;
|
19
|
18
|
}
|
20
|
19
|
|
21
|
|
- public void reRoll(String diceToRoll){
|
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
|
|
- }
|
|
20
|
+ public void setBid(int bid) {
|
|
21
|
+ this.betAmount = bid;
|
36
|
22
|
}
|
37
|
23
|
|
38
|
|
- /**
|
39
|
|
- * implemented from 'Game'
|
40
|
|
- */
|
41
|
|
- public void Quit() {
|
42
|
24
|
|
43
|
|
- }
|
44
|
|
-
|
45
|
|
- public void StartGame() {
|
|
25
|
+ public void startGame() {
|
46
|
26
|
Dice dice1 = new Dice();
|
47
|
27
|
Dice dice2 = new Dice();
|
48
|
28
|
Dice dice3 = new Dice();
|
|
@@ -54,14 +34,25 @@ public class Yahtzee extends DiceGame implements Game{
|
54
|
34
|
dicePlayer.getCup()[2] = dice3;
|
55
|
35
|
dicePlayer.getCup()[3] = dice4;
|
56
|
36
|
dicePlayer.getCup()[4] = dice5;
|
|
37
|
+
|
|
38
|
+ System.out.println("How much would you like to bet on this game?");
|
|
39
|
+ int betAmount = scanner.nextInt();
|
|
40
|
+ setBid(betAmount);
|
|
41
|
+ bet(betAmount);
|
|
42
|
+
|
|
43
|
+ startRound();
|
|
44
|
+ System.out.println("You scored " + dicePlayer.getScoreSheet().getTotalScore() + " points.");
|
|
45
|
+ payout();
|
|
46
|
+ //Return to console.
|
57
|
47
|
}
|
58
|
48
|
|
59
|
|
- public void StartRound() {
|
|
49
|
+ public void startRound() {
|
60
|
50
|
|
61
|
51
|
for(int i = 0; i < ScoreSheet.getSize(); i++) {
|
62
|
52
|
for (Dice d : dicePlayer.getCup()) {
|
63
|
53
|
d.roll();
|
64
|
54
|
}
|
|
55
|
+ System.out.println("You rolled:");
|
65
|
56
|
dicePlayer.printCup();
|
66
|
57
|
|
67
|
58
|
roundRoutine();
|
|
@@ -70,13 +61,77 @@ public class Yahtzee extends DiceGame implements Game{
|
70
|
61
|
|
71
|
62
|
}
|
72
|
63
|
|
|
64
|
+ public void roundRoutine(){
|
|
65
|
+
|
|
66
|
+ giveOptions();
|
|
67
|
+ giveOptions();
|
|
68
|
+
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+ public void giveOptions() {
|
|
72
|
+ int choice = 0;
|
|
73
|
+ System.out.println("Would you like to:\n1. Roll all dice again.\n2. Roll some dice again.\n3. Stop rolling and score.");
|
|
74
|
+
|
|
75
|
+ Scanner in = new Scanner(System.in);
|
|
76
|
+ choice = in.nextInt();
|
|
77
|
+
|
|
78
|
+ switch (choice) {
|
|
79
|
+ case 1:
|
|
80
|
+ for (Dice d : dicePlayer.getCup()) {
|
|
81
|
+ d.roll();
|
|
82
|
+ }
|
|
83
|
+ System.out.println("You rolled:");
|
|
84
|
+ dicePlayer.printCup();
|
|
85
|
+ System.out.println();
|
|
86
|
+ break;
|
|
87
|
+
|
|
88
|
+ case 2:
|
|
89
|
+ System.out.println("Which numbers would you like to reroll? List the numbers separated by spaces.");
|
|
90
|
+ Scanner in2 = new Scanner(System.in);
|
|
91
|
+ String diceToRoll = in2.next();
|
|
92
|
+ reRoll(diceToRoll);
|
|
93
|
+ System.out.println("You rolled:");
|
|
94
|
+ dicePlayer.printCup();
|
|
95
|
+ break;
|
|
96
|
+
|
|
97
|
+ case 3:
|
|
98
|
+ break;
|
|
99
|
+ }
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ public void reRoll(String diceToRoll){
|
|
103
|
+
|
|
104
|
+ String[] numbersString = diceToRoll.replace(",", "").split(" ");
|
|
105
|
+ ArrayList<Integer> numbers = new ArrayList<>();
|
|
106
|
+ for(String s: numbersString) {
|
|
107
|
+ numbers.add(Integer.parseInt(s));
|
|
108
|
+ }
|
|
109
|
+ for(Integer i : numbers) {
|
|
110
|
+ for(int j = 0; j < 5; j++) {
|
|
111
|
+ if(i == dicePlayer.getCup()[j].getValue()) {
|
|
112
|
+ dicePlayer.getCup()[j].roll();
|
|
113
|
+ break;
|
|
114
|
+ }
|
|
115
|
+ }
|
|
116
|
+ }
|
|
117
|
+ }
|
|
118
|
+
|
73
|
119
|
public void recordingScore() {
|
|
120
|
+
|
|
121
|
+ boolean validEntry = true;
|
|
122
|
+ int choice = 13;
|
|
123
|
+ ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
|
|
124
|
+
|
|
125
|
+ while(validEntry) {
|
74
|
126
|
System.out.println("Which row would you like to apply your turn to on the scoresheet?.\n" +
|
75
|
127
|
"Remember you can only use each row once!");
|
|
128
|
+ System.out.println();
|
76
|
129
|
dicePlayer.getScoreSheet().printScoreCard();
|
|
130
|
+ System.out.println();
|
|
131
|
+
|
|
132
|
+ Scanner scanner2 = new Scanner(System.in);
|
|
133
|
+ choice = scanner2.nextInt();
|
77
|
134
|
|
78
|
|
- int choice = scanner.nextInt();
|
79
|
|
- ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
|
80
|
135
|
switch(choice) {
|
81
|
136
|
case 1: row = ScoreSheet.ROW.ACES;
|
82
|
137
|
break;
|
|
@@ -105,35 +160,47 @@ public class Yahtzee extends DiceGame implements Game{
|
105
|
160
|
case 13: row = ScoreSheet.ROW.CHANCE;
|
106
|
161
|
break;
|
107
|
162
|
}
|
108
|
|
- dicePlayer.getScoreSheet().setRow(row, dicePlayer.getCup());
|
|
163
|
+ if (dicePlayer.getScoreSheet().getScore(row) == null) {
|
|
164
|
+ validEntry = false;
|
|
165
|
+ } else {
|
|
166
|
+ System.out.println("Error, you have already filled that row");
|
|
167
|
+ }
|
109
|
168
|
}
|
110
|
169
|
|
|
170
|
+ dicePlayer.getScoreSheet().setRow(row, dicePlayer.getCup());
|
|
171
|
+ System.out.println();
|
|
172
|
+ dicePlayer.getScoreSheet().printScoreCard();
|
|
173
|
+ }
|
111
|
174
|
|
112
|
|
- public void roundRoutine(){
|
113
|
|
-
|
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;
|
|
175
|
+ @Override
|
|
176
|
+ public void bet(int betAmount) {
|
|
177
|
+ dicePlayer.getPlayer().changeBalance(betAmount);
|
|
178
|
+ }
|
132
|
179
|
|
133
|
|
- case 3:
|
134
|
|
- break;
|
135
|
|
- }
|
|
180
|
+ @Override
|
|
181
|
+ public void payout() {
|
|
182
|
+ int score = dicePlayer.getScoreSheet().getTotalScore();
|
|
183
|
+ int payOut = 0;
|
|
184
|
+ if(score == 1575) {
|
|
185
|
+ payOut = getBid() * 100;
|
|
186
|
+ } else if (score > 1000) {
|
|
187
|
+ payOut = getBid() * 20;
|
|
188
|
+ } else if (score > 500) {
|
|
189
|
+ payOut = getBid() * 10;
|
|
190
|
+ } else if (score > 400) {
|
|
191
|
+ payOut = getBid() * 5;
|
|
192
|
+ } else if (score > 300) {
|
|
193
|
+ payOut = getBid() * 2;
|
|
194
|
+ } else if (score > 200) {
|
|
195
|
+ payOut = getBid();
|
|
196
|
+ } else {
|
|
197
|
+ payOut = 0;
|
136
|
198
|
}
|
|
199
|
+ dicePlayer.getPlayer().changeBalance(payOut);
|
|
200
|
+ System.out.println("You won $" + payOut);
|
|
201
|
+ }
|
137
|
202
|
|
|
203
|
+ public void quit() {
|
|
204
|
+ //Return to console
|
138
|
205
|
}
|
139
|
206
|
}
|