-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlaying_Hand_Cricket_Against_Computer.java
More file actions
executable file
·281 lines (242 loc) · 10.8 KB
/
Playing_Hand_Cricket_Against_Computer.java
File metadata and controls
executable file
·281 lines (242 loc) · 10.8 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import java.io.*;
public class Playing_Hand_Cricket_Against_Computer
{
public static void main(String args[]) throws IOException
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String name; // to accept the player's name;
int aa; // converting the random real number generated by 'rr' into a random whole
// number run for the computer;
int ii; // used in for loops;
int bb; // to accept the player's number;
double rr; // to generate a random real number;
int cheat; // to end the game if wrong input is entered; to keep a check whilst the game is
// running as to whether the game has ended or not;
int score1; // to store the latest runs scored by the player;
int score2; // to store the latest runs scored by the computer;
int c; // used in for loops to create a specific design;
int choice; // used to decide whether the game needs to be ended or restarted;
int infinity = 1; // used to keep the game running until the player decides to end the game;
/*
* After referring to all the comments mentioned above,
* you must be able to understand the working of this program as it is very
* easy.
* If you find it complicated,
* feel free to visit www.theadarshmehta.in
* and contact The Adarsh Mehta.
* Have fun!
*/
while (infinity > 0) {
name = " ";
aa = 0;
ii = 0;
bb = 0;
rr = 0;
cheat = 0;
score1 = 0;
score2 = 0;
c = 0;
choice = 0;
infinity = 1;
System.out.println("=======================");
System.out.println("| WELCOME TO THE GAME |");
System.out.println("=======================");
System.out.println("");
System.out.print("Enter Your Name: ");
name = br.readLine();
for (c = 0; c <= 2; c++) {
System.out.println("====================================");
}
System.out.println("Hello " + name + ",");
System.out.println(".");
System.out.println("WELCOME TO THE CRICKET-MANIA");
System.out.println(".");
System.out.println("Instructions:");
System.out.println(".");
System.out.println("This Game Is Similar To The Hand-Cricket Game Played By Kids.");
System.out.println(".");
System.out.println("There Is No Limit On The Number Of Balls.");
System.out.println(".");
System.out.println("You Will First Bat. Enter Any Number From 1 To 10.");
System.out.println(".");
System.out.println("Enter The Numbers Carefully Without Making Any Mistake.");
System.out.println(".");
System.out.println("If The Number Entered By The Computer Is Same As The Number Entered By You,");
System.out.println("You Will Be Declared As Out.");
System.out.println(".");
System.out.println("Your Final Score Will Be The Sum Of The Numbers You Entered Before Getting Out.");
System.out.println(".");
System.out.println("After Getting Out, You Will Have To Bowl.");
System.out.println(".");
System.out.println("Try To Enter A Number Similar To The Number Entered By The Computer.");
System.out.println(".");
System.out.println(
"If The Sum Of Numbers Entered By The Computer Becomes More Than Your Score, It Will Win.");
System.out.println(".");
System.out.println("But If You Enter A Number Same As The Number Entered By The Computer, You Can Win!");
System.out.println(".");
for (c = 0; c <= 2; c++) {
System.out.println("====================================");
}
System.out.println("YOU ARE BATTING:");
for (c = 0; c <= 2; c++) {
System.out.println("====================================");
}
for (ii = 1; ii > 0; ii++) {
System.out.println("");
System.out.print("Enter Your Number: ");
bb = Integer.parseInt(br.readLine());
rr = ((Math.random()) * 10);
rr = rr + 1;
aa = (int) (rr);
System.out.println("");
System.out.println("Computer's Number: " + aa);
System.out.println("");
System.out.println("**********");
System.out.println("");
if (bb == aa) {
System.out.println(" ");
System.out.println("HOWZATTT!!!!!!");
System.out.println(" ");
System.out.println("################");
System.out.println("################");
System.out.println("YOUR FINAL SCORE = " + score1);
System.out.println("################");
System.out.println("################");
System.out.println(" ");
break;
}
else if (bb > 0 && bb <= 10) {
score1 = score1 + bb;
} else if (bb > 10 || bb <= 0) {
for (c = 0; c <= 2; c++) {
System.out.println("====================================");
}
System.out.println("You have either tried to cheat or entered a wrong input. Game Over!");
cheat++;
break;
}
System.out.println("Your Current Score Is " + score1);
System.out.println("");
System.out.println("**********");
}
for (c = 0; c <= 2; c++) {
if (cheat > 0) {
break;
}
System.out.println("====================================");
}
for (c = 0; c < 1; c++) {
if (cheat > 0) {
break;
}
System.out.println("YOU ARE BOWLING:");
}
for (c = 0; c <= 2; c++) {
if (cheat > 0) {
break;
}
System.out.println("====================================");
}
for (ii = 1; ii > 0; ii++) {
if (cheat > 0) {
break;
}
System.out.println("");
System.out.print("Enter Your Number: ");
bb = Integer.parseInt(br.readLine());
rr = ((Math.random()) * 10);
rr = rr + 1;
aa = (int) (rr);
System.out.println("");
System.out.println("Computer's Number: " + aa);
System.out.println("");
System.out.println("**********");
System.out.println("");
if (aa == bb) {
System.out.println(" ");
System.out.println("COMPUTER IS OUTT!!!!");
System.out.println(" ");
System.out.println("################");
System.out.println("################");
System.out.println("COMPUTER'S FINAL SCORE = " + score2);
System.out.println("################");
System.out.println("################");
System.out.println(" ");
break;
}
else if (bb > 0 && bb <= 10) {
score2 = score2 + aa;
} else if (bb > 10 || bb <= 0) {
for (c = 0; c <= 2; c++) {
System.out.println("====================================");
}
System.out.println("You have either tried to cheat or entered a wrong input. Game Over!");
cheat++;
break;
}
if (score2 > score1) {
System.out.println(" ");
System.out.println("THE COMPUTER HAS SCORED MORE THAN YOUU!!!");
System.out.println(" ");
System.out.println("################");
System.out.println("################");
System.out.println("COMPUTER'S FINAL SCORE = " + score2);
System.out.println("################");
System.out.println("################");
System.out.println(" ");
break;
}
System.out.println("Computer's Current Score Is " + score2);
System.out.println("");
System.out.println("**********");
}
for (c = 0; c <= 2; c++) {
if (cheat > 0) {
break;
}
System.out.println("====================================");
}
for (ii = 0; ii < 1; ii++) {
if (cheat > 0) {
break;
}
System.out.println(" ");
System.out.println("################");
System.out.println("################");
System.out.println("YOUR FINAL SCORE = " + score1);
System.out.println("COMPUTER'S FINAL SCORE = " + score2);
System.out.println("################");
System.out.println("################");
System.out.println(" ");
if ((score1) > (score2)) {
System.out.println("Congratulations " + name + "!! You Have Defeated The Almighty, Computer!!");
}
else if ((score1) < (score2)) {
System.out.println("Sorry " + name + ", But The Computer Has Defeated You..!");
}
else {
System.out.println("It's a Tie..! :(");
}
}
for (c = 0; c <= 2; c++) {
System.out.println("====================================");
}
System.out.println("");
System.out.println("Enter 1 To Play This Game Again.");
System.out.println("");
System.out.println("Enter 0 Or Any Other Number To Quit.");
choice = Integer.parseInt(br.readLine());
System.out.println("");
if (choice == 1) {
System.out.print('\f');
}
else {
System.out.print('\f');
System.out.println("Good Bye!");
break;
}
}
}
}