Simple Rock Paper Scissors Game(Java)
Simple Rock Paper Scissors game with JAVA language :
Code:
import java.util.Random;
import java.util.Scanner;
// Rock Paper Scissor game in java
// Sk Elaf Ahmed
public class RockPaper {
public static void main(String[] args) {
//Rock = 0 Paper = 1 Scissor = 2
Scanner sc = new Scanner(System.in);
int playerScore = 0, compScore = 0;
for(int i =0; i<3; i++){
System.out.println("Enter a number Rock = 0 Paper = 1 Scissor = 2");
int userIn = sc.nextInt();
Random random = new Random();
int comIn = random.nextInt(3);
System.out.println("You choose " + userIn);
System.out.println("Computer choose " + comIn);
if(comIn == userIn){
System.out.println("Draw, no one wins, both scores are same");
}
else if(comIn==0 && userIn==1 || comIn== 2 && userIn == 0 || userIn== 2 && comIn== 1 ){
playerScore += 1;
System.out.println("You win, great job");
} else {
compScore += 1;
System.out.println("Computer win, try hard buddy");
}
}
if(compScore>playerScore){
System.out.println("Computer win this time!");
}
else if(compScore==playerScore){
System.out.println("No one wins this time!");
}
else{
System.out.println("You win, great work!");
}
sc.close();
}
}
Comments
Post a Comment