-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheCrapsGame.java
More file actions
83 lines (79 loc) · 3.43 KB
/
TheCrapsGame.java
File metadata and controls
83 lines (79 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package Practice.Game;
import java.security.SecureRandom;
import java.util.Scanner;
public class TheCrapsGame {
private static final SecureRandom randomNumbers = new SecureRandom();
private enum Status {CONTINUE, WON, LOST}
static Scanner input = new Scanner(System.in);
public static int game() {
int die1 = 1 + randomNumbers.nextInt(6);
int die2 = 1 + randomNumbers.nextInt(6);
int sum = die1 + die2;
System.out.printf("Player rolled %d + %d = %d%n", die1, die2, sum);
return sum;
}
public static void play() {
DiceGame.deposit(-100) ;
int point = 0;
int spin;
Status gameStatus;
int sumOfDice = game();
switch (sumOfDice) {
case 2, 12 -> {
gameStatus = Status.WON;
break;
}
case 5, 6, 9, 10 -> {
gameStatus = Status.LOST;
break;
}
default -> {
gameStatus = Status.CONTINUE;
point = sumOfDice;
break;
}
}
if (gameStatus == Status.CONTINUE) {
System.out.println("Your point is: " + point);
System.out.println("\nNOW TO WIN YOU HAVE TO ROLL a 2 or a " + point);
System.out.print("press 1 to continue or 0 to exit game -> ");
int cont = input.nextInt();
if (cont == 0) {
System.exit(3);
} else {
play();
if (game() == point || game() == 2) {
System.out.println("____JACKPOT!!!____");
} else {
System.out.println("try again");
}
}
}
else if (gameStatus == Status.LOST) {
System.out.println("\n ____You Loss____ ");
// System.out.printf("%nName: %s Age: %d Balance: %,.1fNGN%n",
// DiceGame.getName(), DiceGame.getAge(), DiceGame.getBalance());
// System.out.print("press any key to play again or 0 to exit game -> ");
// int cont = input.nextInt();
// if (cont == 0) {
// System.exit(2);
// } else {
// play();
// }
}
else {
System.out.println("\n ____JACKPOT!!!____ ");
DiceGame.deposit(300);
// System.out.printf("%nName: %s Age: %d Balance: %,.1fNGN%n",
// DiceGame.getName(), DiceGame.getAge(), DiceGame.getBalance());
// System.out.print("press any key to play again or 0 to exit game -> ");
// int cont = input.nextInt();
// if (cont == 0) {
// System.exit(1);
// }
// else {
// play();
// }
}
}
}