-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathRPS.java
79 lines (66 loc) · 2.42 KB
/
RPS.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
import java.util.*;
import java.util.Random;
public class RPS {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
Random random = new Random();
int cpu_score = 0;
int player_score = 0;
while (true) {
int computer = random.nextInt(3);
String cpu_choice = "";
if (computer == 0) {
cpu_choice += "rock";
}
else if (computer == 1) {
cpu_choice += "paper";
}
else {
cpu_choice += "scissor";
}
System.out.println("Please enter your choice");
System.out.println("Enter rock || paper || scissor || end ||");
String player = sc.next();
if (player.equals(cpu_choice)) {
System.out.println("It's Draw");
}
else if (player.equals("rock")) {
if (cpu_choice.equals("paper")) {
System.out.println("CPU Wins...");
cpu_score += 1;
}
else {
System.out.println("Player Wins...");
player_score += 1;
}
}
else if (player.equals("paper")) {
if (cpu_choice.equals("rock")) {
System.out.println("Player Wins...");
player_score += 1;
}
else {
System.out.println("CPU Wins...");
cpu_score += 1;
}
}
else if (player.equals("scissor")) {
if (cpu_choice.equals("paper")) {
System.out.println("Player Wins...");
player_score += 1;
}
else {
System.out.println("CPU Wins...");
cpu_score += 1;
}
}
else if (player.equals("end")) {
System.out.println("The final scores are as follows : ");
System.out.println("CPU Score : "+ cpu_score);
System.out.println("Player Score : " + player_score);
System.out.println("Thanks for playing my game.");
break;
}
}
}
}