-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSimpleHandCricketGame.java
More file actions
102 lines (98 loc) · 2.07 KB
/
SimpleHandCricketGame.java
File metadata and controls
102 lines (98 loc) · 2.07 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
package fin;
import java.util.*;
public class cric2 {
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int p1t,p2t,p1,p2,to;
to=(int)Math.random();
boolean toss = (to>0.5) ? true : false ;
System.out.println("use numbers 1,2,3,4,5,6");
p1t=p2t=0;
p1=p2=0;
if(toss)
{
System.out.println("You have to bat first");
while(true)
{
System.out.println("enter your number");
p1=sc.nextInt();
p2=(int)(6*(Math.random()));
System.out.println("Computer chooses : " + p2);
if(p1==p2)
{
System.out.println("End of The innings.Your total = "+ p1t);
break;
}
else
p1t=p1t+p1;
}
while(true)
{
System.out.println("enter your number");
p1=sc.nextInt();
p2=(int)(6*Math.random());
System.out.println("Computer chooses : " + p2);
if(p1==p2)
{
System.out.println("End of The innings.computer's total = "+ p2t);
break;
}
else if(p2t>p1t)
break;
else
p2t=p2t+p2;
}
}
if(!toss)
{
System.out.println("You have to bowl first");
while(true)
{
System.out.println("enter your number");
p1=sc.nextInt();
if(p1>6)
{
System.out.println("enter correct number");
continue;
}
p2=(int)(6*(Math.random()))+1;
System.out.println("Computer chooses : " + p2);
if(p1==p2)
{
System.out.println("End of The innings.Computer's total = "+ p2t);
break;
}
else
p2t=p2t+p2;
}
while(true)
{
System.out.println("enter your number");
p1=sc.nextInt();
p2=(int)(6*Math.random())+1;
if(p1>6)
{
System.out.println("enter correct number");
continue;
}
System.out.println("Computer chooses : " + p2);
if(p1==p2)
{
System.out.println("End of The innings.Your total = "+ p1t);
break;
}
else if(p1t>p2t)
break;
else
p1t=p1t+p1;
}
}
if(p1t>p2t)
System.out.println("You won the game");
else if(p2t>p1t)
System.out.println("Computer won the game");
else
System.out.println("Match drawn");
}
}