-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandCricket.txt
328 lines (293 loc) · 13.9 KB
/
handCricket.txt
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
import java.io.*;
import java.util.Scanner;
public class handCricket//Developed by Shadow Corps(@umbraDominum)
{
public static int toss()
{
Scanner sc = new Scanner(System.in);
String temp="",temp1="";
int HEADS = 1;
int TAILS = 0;
double randomChoice = Math.random();
System.out.println("NOW, it is the time for toss,Enter \"HEADS\" or \"TAILS\" :");
String input = sc.next();
if(randomChoice>=0.5 && randomChoice<=1)
temp = "HEADS";
else if(randomChoice<=0.5 && randomChoice>=0)
temp = "TAILS";
if(temp.equalsIgnoreCase(input))
{
System.out.println("YOU WIN !!!!");
System.out.println("WHAT IS YOUR CHOICE : \"BATTING\" OR \"BOWLING\"");
temp1 = sc.next();
if(temp1.equalsIgnoreCase("batting")){return(1);} else {return(0);}
}
else
{ System.out.println("SORRY,YOU LOSE :(");
return((int)Math.random());}
}
public static int bat() throws IOException
{
Scanner sc = new Scanner(System.in);
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
int temp1;
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 i; // 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;
name=" ";
aa=0;
i=0;
bb=0;
rr=0;
cheat=0;
score1=0;
score2=0;
c=0;
choice=0;
System.out.println("YOU ARE BATTING:");
for(c=0;c<=2;c++) { System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); }
for(i=1;i>0;i++)
{
System.out.println("");
System.out.print("Enter Your Number: ");
bb=Integer.parseInt(br.readLine());
rr=((Math.random())*6);
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("OUT!!!!!!");
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<=6) { score1=score1+bb; } else if(bb>6||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("**********");
}
return(score1);
}
public static int ball() throws IOException
{
Scanner sc = new Scanner(System.in);
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
int temp1;
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 i; // 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;
name=" ";
aa=0;
i=0;
bb=0;
rr=0;
cheat=0;
score1=0;
score2=0;
c=0;
System.out.println("YOU ARE BOWLING:");
for(c=0;c<=2;c++) { System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); }
for(i=1;i>0;i++)
{
System.out.println("");
System.out.print("ENTER YOUR NUMBER: ");
bb=Integer.parseInt(br.readLine());
rr=((Math.random())*6);
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("OUT!!!!!!");
System.out.println(" ");
System.out.println("#################");
System.out.println("#################");
System.out.println("COMPUTER'S FINAL SCORE = "+score1);
System.out.println("#################");
System.out.println("#################");
System.out.println(" ");
break;
}
else if(bb>0&&bb<=6) { score1=score1+aa; } else if(bb>6||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("COMPUTER'S CURRENT SCORE IS : "+score1);
System.out.println("");
System.out.println("**********");
}
return(score1);
}
public static void main(String args[])throws IOException
{
Scanner sc = new Scanner(System.in);
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
int temp1;
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 i; // 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 runs scored by the player;
int score2; // to store the 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;
while(infinity>0)
{
name=" ";
aa=0;
i=0;
bb=0;
rr=0;
cheat=0;
score1=0;
score2=0;
c=0;
choice=0;
infinity=1;
System.out.println("* * * * * * * * * ***** ***** * ******* * * ******* *****");
System.out.println("* * * * * * * * * * * * * * * * * *");
System.out.println("***** ******** * * * * * * ****** * * *** ***** *");
System.out.println("* * * * * * * * * * * * * * * * * *");
System.out.println("* * * * * * * ***** * * * ******* * * ******* *");
System.out.println();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("| WELCOME TO THE HAND CRICKET 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("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("Instructions:");
System.out.println(".");
System.out.println("You Will Play According to the Toss. Enter Any Number From 1 To 6.");
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(".");
temp1 = toss();
for(c=0;c<=2;c++)
{
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
if(temp1==1)
{
score1 = bat();
score2 = ball();
}
else{
score2 = ball();
score1 = bat();}
for(i=0;i<1;i++) { 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..!.BETTER LUCK NEXT TIME!!:(");
}
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;
}
}
}
}