-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrapsProject.java
More file actions
90 lines (90 loc) · 3.49 KB
/
crapsProject.java
File metadata and controls
90 lines (90 loc) · 3.49 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
83
84
85
86
87
88
89
90
//Project Name: Game of Craps
//Date: 12/6/2018
//Name: Adam Mason
/* Project Description
test
*/
import java.util.Scanner;
import java.util.Random;
public class crapsProject
{
public static void main(String [] args)
{
//Initialize Random number and Scanner
Scanner scan = new Scanner(System.in);
Random rand = new Random();
//Initialize Variables
char progRun = 'p';
int diceSum, point, rollCounter, currentBet = 0;
int playerBalance = 1000;
//Greet player and ask for name
System.out.print("Welcome to Adam's casino! Please enter your name to get started:");
String playerName = scan.nextLine();
System.out.println();
while( progRun == 'p' )
{
currentBet = -1;
while(currentBet <= 0 || currentBet > playerBalance)
{
System.out.print("Enter a bet from your $" + playerBalance + " balance: ");
currentBet = scan.nextInt();
}
if( progRun == 'p')
{
//Set roll count to 1, get new diceSum and print
playerBalance -= currentBet;
rollCounter = 1;
diceSum = rand.nextInt(11) + 2;
System.out.print("Roll 1: " + playerName + " rolls a " + diceSum + ". ");
if ( diceSum == 2 || diceSum == 3 || diceSum == 12 )
System.out.println("You lost!");
else if ( diceSum == 7 || diceSum == 11 )
{
System.out.println("You won $" + (currentBet * 2) + "!");
playerBalance += currentBet * 2;
}
else
{
//If diceSum does not make player win or lose set point equal to diceSum
point = diceSum;
System.out.print( "The point becomes " + point );
//Roll until you get to break statement and break out
while(true)
{
//Set roll count and diceSum
rollCounter++;
diceSum = rand.nextInt(11) + 2;
System.out.print("\nRoll " + rollCounter + ": " + playerName + " rolls a " + diceSum + ". ");
//Check if player lost or got the point, and then break
if (diceSum == 7)
{
System.out.println("You lost!");
break;
}
else if (diceSum == point)
{
System.out.println("You won $" + (currentBet * 2) + "!");
playerBalance += currentBet * 2;
break;
}
}
}
}
if(playerBalance <= 0)
{
System.out.println("You're broke!");
break;
}
progRun = ' ';
while(progRun != 'p' && progRun != 'q')
{
System.out.print("Would you like to (p)lay or (q)uit?: ");
scan.nextLine();
progRun = scan.nextLine().toLowerCase().charAt(0);
System.out.println();
}
}
System.out.println("Goodbye, " + playerName + "!");
}
}
//End-of-file