Skip to content

Commit ee4a9ec

Browse files
add: Snake water gun game project in Java
1 parent cf5e05d commit ee4a9ec

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

snakeWaterGun.java

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import java.util.Scanner;
2+
import java.util.Random;
3+
4+
public class Mini_Project {
5+
6+
public static void main(String[] args) {
7+
Scanner sc=new Scanner(System.in);
8+
Random rand=new Random();
9+
int com=rand.nextInt(100);
10+
System.out.println("Enter the number of matches,You want to Play");
11+
int match=sc.nextInt();
12+
int won=0;
13+
int loose=0;
14+
int draw=0;
15+
for(int i=0;i<match;i++) {
16+
System.out.println("Please enter s for snake,g for gun or w for water");
17+
char v = sc.next().charAt(0);
18+
System.out.println("You have entered: "+v);
19+
if(v=='s'|| v=='g' || v=='w'){
20+
21+
//System.out.println("The computer has selected:"+com);
22+
{
23+
24+
if(com<33) //Selected Snake
25+
{ com=115;
26+
char s=(char)com;
27+
System.out.println("Computer has choose: "+s);
28+
if(s==v)
29+
{
30+
System.out.println("The match has drawn");
31+
draw++;
32+
}
33+
else if(v==103)
34+
{
35+
System.out.println("You won the match:)");
36+
won++;
37+
}
38+
else if(v==119)
39+
{
40+
System.out.println("You loose the match:(");
41+
loose++;
42+
}
43+
}
44+
45+
else if(com>33 &com<66) //Selected Gun g=103, s=115, w=119
46+
{ com=103;
47+
char g=(char)com;
48+
System.out.println("Computer has choose: "+g);
49+
if(g==v)
50+
{
51+
System.out.println("The match has drawn");
52+
draw++;}
53+
else if(v==115)
54+
{
55+
System.out.println("You loose the match:(");
56+
loose++;}
57+
else if(v==119)
58+
{
59+
System.out.println("You won the match:)");
60+
won++;}
61+
}
62+
else if (com>66) //Selected Water
63+
{ com=119;
64+
char w=(char)com;
65+
System.out.println("Computer has choose: "+w);
66+
if(w==v)
67+
{
68+
System.out.println("The match has drawn");
69+
draw++;}
70+
else if(v==103)
71+
{
72+
System.out.println("You loose the match:(");
73+
loose++;}
74+
else if(v==115)
75+
{
76+
System.out.println("You won the match:)");
77+
won++;}
78+
}
79+
80+
81+
}
82+
83+
}
84+
else
85+
System.out.println("Please Enter the valid input");
86+
}
87+
System.out.println("********************************");
88+
System.out.println("STATATICS :)");
89+
System.out.println("You Won :"+won);
90+
System.out.println("You loose :"+loose);
91+
System.out.println("Drawn :"+draw);
92+
System.out.println("********************************");}}

0 commit comments

Comments
 (0)