-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathRockPaperSiscorGame.java
More file actions
112 lines (82 loc) · 3.97 KB
/
Copy pathRockPaperSiscorGame.java
File metadata and controls
112 lines (82 loc) · 3.97 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
103
104
105
106
107
108
109
110
111
112
package code;
import java.util.Random;
import java.util.Scanner;
public class RockPaperSiscorGame {
public static void main(String[] args) {
String playerWhichMoves = "";
String computerWhichMoves = "";
// Storing scores
int playerScore = 0;
int computerScore = 0;
//Storing winner
String winner = "";
// Generating Random number for computer moves
Random randomNumber = new Random();
// Making scanner number for user input
Scanner sc = new Scanner(System.in);
// Some Line To Display First
System.out.println("Welcome to Rock-Paper-Siscor");
System.out.println("This game is repeat for five time");
System.out.println("Select your moves as per option");
System.out.println("0: Rock");
System.out.println("1: Paper");
System.out.println("2: Siscor");
System.out.println("Enter Your Move");
//Repeating Game For Five Time So Winner Is Clear
for(int i = 0; i <= 5; i++) {
// Taking user input in playerMoves
int playerMoves = sc.nextInt();
// Checking input is valid or not
if(playerMoves > 2 || playerMoves < 0){
System.out.println("invalid move");
return;
}
// Taking random number in computerMoves
int computerMoves = randomNumber.nextInt(2);
// Showing which moves taken by Player and Computer
if(playerMoves == 0){
playerWhichMoves = "Your move is Rock";
}
else if(playerMoves == 1){
playerWhichMoves = "Your move is Paper";
}
else if(playerMoves == 2){
playerWhichMoves = "Your move is Siscor";
}
if(computerMoves == 0){
computerWhichMoves = "Computer move is Rock";
}
else if(computerMoves == 1){
computerWhichMoves = "Computer move is Paper";
}
else if(computerMoves == 2){
computerWhichMoves = "Computer move is Siscor";
}
// Checking Winner
if(playerMoves == computerMoves){
winner = "Tie";
}
else if(playerMoves == 0 && computerMoves == 2 || playerMoves == 2 && computerMoves == 1 || playerMoves == 1 && computerMoves == 0){
winner = "You are winner";
playerScore += 1;
}else {
winner = "Computer is winner";
computerScore += 1;
}
System.out.println(playerWhichMoves);
System.out.println(computerWhichMoves);
System.out.println(winner);
System.out.println(playerScore);
System.out.println(computerScore);
}
// checking final winner
if(playerScore == computerScore){
System.out.println("The game is tie between computer and you");
}
if(playerScore > computerScore){
System.out.println("Final Winner is you");
}else{
System.out.println("Final Winner is you");
}
}
}