rock paper scissors

 Make a simple game of rock paper scissors where you can paly against bots and submit on riteshregmi85@gmail.com I will give you a credit on your account.


You can also submit this project on the comment. This is a super easy project which is for super beginner. and one more things don't use GUI on it make it simple. And run on the black screen.
If you don't do this project please complete it first and see the result. If you don't do that is will impact you performance.

Easy one

package com.ritesh;

import java.util.Random;
import java.util.Scanner;

public class r_s_p {
public static void main(String[] args) {

int R=0; //phase 1
int P=1; //assining the value of integer
int S=2;

Scanner sc=new Scanner(System.in); //phase 2
Random number=new Random();


System.out.println("0 for Rock"); //phase 3
System.out.println("1 for paper");
System.out.println("2 for scissor ");


byte user= sc.nextByte();
int computer=number.nextInt(3); //phase 4


if(user==computer)
{
System.out.println("The game is tie");
}
else if((user==R&&computer==S)||(user==P&&computer==R)||(user==S&&computer==P))
{
System.out.println("You won the match");
}
else if((computer==R&&user==S)||(computer==P&&user==R)||(computer==S&&user==P))
{
System.out.println("You loose the match");
}
else
System.out.println("Invalid input please try again");
}
}


Difficult One

package com.ritesh;

import java.util.Random;
import java.util.Scanner;

class Game2 {

public static final String ROCK = "R";
public static final String PAPER = "P";
public static final String SCISSORS = "S";

/**
* Get the game Result
* */
public static void getResult(String usersMove, String computersMove) {

System.out.println("Computer's move is: " + computersMove);

if (usersMove.equals(computersMove))
System.out.println("It's a tie!");
else if (usersMove.equals(ROCK))
{
if (computersMove.equals(SCISSORS))
System.out.println("You win!! Rock crushes scissors.");
else if (computersMove.equals(PAPER))
System.out.println("You lose!! Paper eats rock.");
}
else if (usersMove.equals(PAPER))
{
if (computersMove.equals(ROCK))
System.out.println("You win!! Paper eats rock.");
else if (computersMove.equals(SCISSORS))
System.out.println("You lose!! Scissor cuts paper.");
}
else if (usersMove.equals(SCISSORS))
{
if (computersMove.equals(PAPER))
System.out.println("You win!! Scissor cuts paper.");
else if (computersMove.equals(ROCK))
System.out.println("You lose!! Rock breaks scissors.");
}
else
System.out.println("Invalid user input.");
}
/**
* Get Computer's move
* */
public static String getComputersMove(){
int computersNum;
String computersMove="";
Random random = new Random();
computersNum = random.nextInt(3) + 1;
if (computersNum == 1)
computersMove = ROCK;
else if (computersNum == 2)
computersMove = PAPER;
else if (computersNum == 3)
computersMove = SCISSORS;

return computersMove;
}
/**
* Get User's move
* */

public static String getUsersMove(){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your play: ");
String input = scanner.next().toUpperCase();
return input;
}

/**
* Main method
* */
public static void main(String[] args) {
System.out.println( "Rock, Paper, Scissors!\n"
+ "Please enter a move.\n"
+"Rock = R, Paper= P, and Scissors = S.\n");

String userInput = getUsersMove();
if (userInput.equals(PAPER) || userInput.equals(ROCK) || userInput.equals(SCISSORS))
getResult(userInput, getComputersMove());
else
System.out.println("Invalid Input " + userInput);
}
}



Comments