|
@@ -37,7 +37,7 @@ public class Craps extends DiceGame implements Gamble {
|
37
|
37
|
}
|
38
|
38
|
|
39
|
39
|
public void placeBet() {
|
40
|
|
- this.bet = console.getIntegerInput("Enter your bet");
|
|
40
|
+ this.bet = console.integerInputSameLine("Enter your bet: ");
|
41
|
41
|
}
|
42
|
42
|
|
43
|
43
|
public void evaluateBet(Player player, long payout) {
|
|
@@ -46,39 +46,23 @@ public class Craps extends DiceGame implements Gamble {
|
46
|
46
|
|
47
|
47
|
public void play(CrapsPlayer currentPlayer) {
|
48
|
48
|
placeBet();
|
|
49
|
+
|
49
|
50
|
promptEnterKey("roll dice");
|
50
|
|
- int sum = rollDie(2); // roll two dice, store sum in sum field.
|
|
51
|
+
|
|
52
|
+ int sum = rollDie(2);
|
|
53
|
+
|
51
|
54
|
console.println("Your roll sum equals: " + sum);
|
|
55
|
+
|
52
|
56
|
if (sum == 7 || sum == 11) {
|
53
|
|
- console.println("\n*********");
|
54
|
|
- console.println("YOU WIN!");
|
55
|
|
- console.println("*********\n");
|
56
|
|
- evaluateBet(currentPlayer.getP(), bet*2);
|
|
57
|
+ evalWin(currentPlayer.getP());
|
57
|
58
|
} else if (sum == 2 || sum == 3 || sum == 12) {
|
58
|
|
- console.println("\n*********");
|
59
|
|
- console.println("YOU LOSE!");
|
60
|
|
- console.println("*********\n");
|
61
|
|
- evaluateBet(currentPlayer.getP(), -(bet*2));
|
|
59
|
+ evalLoss(currentPlayer.getP());
|
62
|
60
|
} else {
|
63
|
61
|
int point = sum;
|
64
|
62
|
do {
|
65
|
|
- console.println("\n--------------------");
|
66
|
|
- console.println("Point to roll for: " + point);
|
67
|
|
- console.println("--------------------");
|
68
|
|
- promptEnterKey("roll again");
|
|
63
|
+ printRollAgain(point);
|
69
|
64
|
sum = rollDie(2);
|
70
|
|
- console.println("You rolled a " + sum);
|
71
|
|
- if (sum == 7) {
|
72
|
|
- console.println("\n*********");
|
73
|
|
- console.println("YOU LOSE!");
|
74
|
|
- console.println("*********\n");
|
75
|
|
- evaluateBet(currentPlayer.getP(), -bet);
|
76
|
|
- } else if (sum == point) {
|
77
|
|
- console.println("\n*********");
|
78
|
|
- console.println("YOU WIN!");
|
79
|
|
- console.println("*********\n");
|
80
|
|
- evaluateBet(currentPlayer.getP(), bet);
|
81
|
|
- }
|
|
65
|
+ evalReRoll(currentPlayer, sum , point);
|
82
|
66
|
} while (sum != point && sum != 7);
|
83
|
67
|
}
|
84
|
68
|
}
|
|
@@ -89,6 +73,33 @@ public class Craps extends DiceGame implements Gamble {
|
89
|
73
|
}
|
90
|
74
|
}
|
91
|
75
|
|
|
76
|
+ public void printRollAgain(int point){
|
|
77
|
+ console.println("\n--------------------");
|
|
78
|
+ console.println("Point to roll for: " + point);
|
|
79
|
+ console.println("--------------------");
|
|
80
|
+ promptEnterKey("roll again");
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+ public void evalReRoll(CrapsPlayer currentPlayer, int sum, int point){
|
|
84
|
+ console.println("You rolled a " + sum);
|
|
85
|
+ if (sum == 7) {
|
|
86
|
+ evalLoss(currentPlayer.getP());
|
|
87
|
+ } else if (sum == point) {
|
|
88
|
+ evalWin(currentPlayer.getP());
|
|
89
|
+ }
|
|
90
|
+ }
|
|
91
|
+
|
|
92
|
+ public void evalLoss(Player player){
|
|
93
|
+ console.println("\n*********\nYOU LOSE!\n*********\n");
|
|
94
|
+ evaluateBet(player, -bet);
|
|
95
|
+ }
|
|
96
|
+ public void evalWin(Player player){
|
|
97
|
+ console.println("\n*******************************\n" +
|
|
98
|
+ "WINNER WINNER CHICKEN DINNER!\n" +
|
|
99
|
+ "*******************************\n");
|
|
100
|
+ evaluateBet(player, bet);
|
|
101
|
+ }
|
|
102
|
+
|
92
|
103
|
public void greetPlayer(Player playa){
|
93
|
104
|
console.println("Ok " + playa.getName() + ", you're up...\n");
|
94
|
105
|
}
|