-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayGame.java
More file actions
175 lines (165 loc) · 3.4 KB
/
PlayGame.java
File metadata and controls
175 lines (165 loc) · 3.4 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*Sudipti Dantuluri
* 10.1.2021
* PlayGame.java
* The program uses scanner and Math.random() to finish playing the games*/
import java.util.Scanner; //Import library
import java.util.concurrent.ThreadLocalRandom;
public class PlayGame
{
public static void main (String [] args)
{
PlayGame msp = new PlayGame();
msp.runner();
}
int dice;
int cards = 0;
public PlayGame()
{
}
public PlayGame(int num)
{
dice = num;
}
public PlayGame(boolean bool)
{
cards = 2; //black jack(2 cards)
}
public PlayGame(boolean bool, boolean pk)
{
cards = 5; //poker (5 cards)
}
public void runner()
{
Scanner runner = new Scanner(System.in); //Opens the Scanner
System.out.print("\n\n\n");
System.out.print("Would you like to play Dice(1), Black Jack(2), or Poker(3)? ");
int gameSelected = runner.nextInt();
if (gameSelected==1)
{
System.out.print("How many dice? (max:6): ");
int numberofDice = runner.nextInt();
PlayGame pg2 = new PlayGame(numberofDice);
pg2.diceGame();
}
else if (gameSelected==2)
{
PlayGame pg3 = new PlayGame(true);
pg3.blackJack(); //what if pg3.poker?
}
else
{
PlayGame pg4 = new PlayGame(true,true);
pg4.poker();
}
}
public void diceGame()
{
for(int i=0; i<dice; i++)
{
System.out.printf("%d ", (int)(Math.random()*dice)+1);
}
System.out.printf("\n");
}
public void blackJack()
{
int card = 0;
int your_total = 0;
int dealer_total = 0;
System.out.printf("Here are your 2 cards: ");
for(int i=0; i<cards; i++)
{
card = (int)(Math.random()*13)+1;
your_total += card;
if (card==1)
{
System.out.printf("A ");
}
else if (card==11)
{
System.out.printf("J ");
}
else if (card==12)
{
System.out.printf("Q ");
}
else if (card==13)
{
System.out.printf("K ");
}
else
{
System.out.printf("%d ", card);
}
}
System.out.printf("\n");
System.out.printf("Dealers: ");
for(int i=0; i<cards; i++)
{
card = (int)(Math.random()*13)+1;
dealer_total += card;
if (card==1)
{
System.out.printf("A ");
}
else if (card==11)
{
System.out.printf("J ");
}
else if (card==12)
{
System.out.printf("Q ");
}
else if (card==13)
{
System.out.printf("K ");
}
else
{
System.out.printf("%d ", card);
}
}
System.out.printf("\n");
if (your_total > dealer_total)
{
System.out.printf("You win!\n");
}
else if (your_total < dealer_total)
{
System.out.printf("Dealer wins!\n");
}
else
{
System.out.printf("Standoff\n");
}
}
public void poker()
{
int card = 0;
System.out.printf("Here are your 5 cards: ");
for(int i=0; i<cards; i++)
{
card = (int)(Math.random()*13)+1;
if (card==1)
{
System.out.printf("A ");
}
else if (card==11)
{
System.out.printf("J ");
}
else if (card==12)
{
System.out.printf("Q ");
}
else if (card==13)
{
System.out.printf("K ");
}
else
{
System.out.printf("%d ", card);
}
}
System.out.printf("\n");
}
}