forked from kant003/JavaPracticeHacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRPSGame.java
98 lines (84 loc) · 2.9 KB
/
RPSGame.java
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
import java.util.*;
public class RPSGame {
static void startthegame()
{
Random rand = new Random();
Scanner sc= new Scanner(System.in);
List<String> list = new ArrayList<String>();
list.add("Rock");
list.add("Paper");
list.add("Scissors");
int userscore=0,botscore=0;
String userchoice, botchoice, nextgamechoice;
boolean play = false;
boolean playagain=true;
while (playagain == true) {
play=true;
userscore=0; botscore=0;
while(play == true) {
System.out.println("Enter your choice");
userchoice = sc.nextLine();
botchoice = list.get(rand.nextInt(list.size()));
//System.out.println("User choice: "+userchoice);
//System.out.println("Bot choice: "+botchoice);
A:
if(userchoice.equals("Rock") && botchoice.equals("Paper"))
botscore+=1;
else if(userchoice.equals("Rock") && botchoice.equals("Scissors"))
userscore+=1;
else if(userchoice.equals("Paper") && botchoice.equals("Rock"))
userscore+=1;
else if(userchoice.equals("Paper") && botchoice.equals("Scissors"))
botscore+=1;
else if(userchoice.equals("Scissors") && botchoice.equals("Rock"))
botscore+=1;
else if(userchoice.equals("Scissors") && botchoice.equals("Paper"))
userscore+=1;
/*else if( !userchoice.equals("Rock") && !userchoice.equals("Paper") && !userchoice.equals("Scissors") )
{
System.out.println("Enter your choice again");
userchoice = sc.nextLine();
continue A;
}*/
else if(userchoice.equals("Stop"))
play = false;
}
System.out.println();
System.out.println("Computer score: "+botscore);
System.out.println("Your score: "+ userscore);
System.out.println();
if(botscore > userscore) {
System.out.println("Computer has won the game");
System.out.println("I hope you knock on wood next time!");
}
else if(userscore > botscore)
System.out.println("You won! Congratulations");
else if(userscore == botscore)
System.out.println("Its a tie!!");
System.out.println();
System.out.println("If you would like to play again, enter 'YES' otherwise enter 'NO'");
nextgamechoice = sc.nextLine();
if(nextgamechoice.equals("NO"))
playagain=false;
}
System.out.println("Thank you for playing, we hope to see you again soon");
System.out.println("Bye!");
System.exit(0);
}
public static void main(String args[])
{
Random rand = new Random();
Scanner sc= new Scanner(System.in);
Gamemanual obj = new Gamemanual();
String usermanualchoice;
System.out.println("Welcome to Rock Paper Scissors Game!");
System.out.println("Once if you start the game you cannot stop it!");
System.out.println("If you would like to refer user manaul enter 'YES' else 'NO'");
System.out.println();
usermanualchoice = sc.nextLine();
if(usermanualchoice.equals("YES"))
obj.refermanual();
else
startthegame();
}
}