0% found this document useful (0 votes)
5 views6 pages

Number 123

The document is a Java program for a Rock, Paper, Scissors game that allows players to choose between multiplayer and computer modes. It includes a main menu for mode selection, game options, and tracks wins, losses, and ties. The program features loops for continuous play and handles user input for game choices and results.

Uploaded by

nutwjdf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Number 123

The document is a Java program for a Rock, Paper, Scissors game that allows players to choose between multiplayer and computer modes. It includes a main menu for mode selection, game options, and tracks wins, losses, and ties. The program features loops for continuous play and handles user input for game choices and results.

Uploaded by

nutwjdf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

/*==============================================

Naguit, Hurjay Ali D.


Rock Paper and Scissors
10 / 07 / 2024

================================================*/
import java.io.*;

public class Rock_Paper_Scissors


{
public static void mainMenu(){
System.out.println("Rock, Paper, Scissors");
System.out.println("---------------------");
System.out.println("Choose Mode:");
System.out.println("1. Multiplayer");
System.out.println("2. Verus Computer");
System.out.println("3. Exit Program");
System.out.println("-----------------");;
}

public static void menu()


{
System.out.println("Rock, Paper, Scissors");
System.out.println("---------------------");
System.out.println("Choose Mode:");
System.out.println("1. Easy");
System.out.println("2. Intermediate");
System.out.println("3. Impossible");
System.out.println("4. Check Standing");
System.out.println("5. Close Program");
System.out.println("--------------------");
} // // menu

public static void game(int matchNumber){


System.out.println("\n-----------------");
System.out.println("Match No. " + matchNumber);
System.out.println("\nOptions");
System.out.println("1. Rock");
System.out.println("2. Paper");
System.out.println("3. Scissors");
System.out.println("4. Back");
System.out.println("-----------------");
}

public static void main(String[] args)throws IOException


{
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
// Point p1 = new Point();
// p1.x = 1;
int matchNumber=1;

do
{
mainMenu();
System.out.print("Choice: ");
String Choice_ = br.readLine();
byte choice_ = Byte.parseByte(Choice_);
System.out.print("\n");1
if (choice_==1)
{

String Player1, Player2;


int player1, player2;

String[] RPS = {"Rock", "Paper", "Scissors"};


do{
game(matchNumber);
System.out.print("Player1 (1-4): ");
Player1 = br.readLine();
player1 = Integer.parseInt(Player1);
if (player1==4)
{
System.out.print("\n");
break;
}
System.out.print("Player2 (1-4): ");
Player2 = br.readLine();
player2 = Integer.parseInt(Player2);

if (player2==4)
{
System.out.print("\n");
break;
}

if (player1<1 || player1>4 || player2<1 || player2>4 )


{
System.out.println("Invalid");
}

else
{
if(player1==player2)
{
System.out.println("Player 1: "+RPS[player1-1]);
System.out.println("Player 2: "+RPS[player2-1]);
System.out.println("It's a tie!");

else if(player1==1 && player2==2)


{
System.out.println("Player 1: "+RPS[player1-1]);
System.out.println("Player 2: "+RPS[player2-1]);
System.out.println("Winner : Player 2");

else if(player1==2 && player2==1)


{
System.out.println("Player 1: "+RPS[player1-1]);
System.out.println("Player 2: "+RPS[player2-1]);
System.out.println("Winner : Player 1");
}
else if(player1==2 && player2==3)
{
System.out.println("Player 1: "+RPS[player1-1]);
System.out.println("Player 2: "+RPS[player2-1]);
System.out.println("Winner : Player 2");
}

else if(player1==3 && player2==2)


{
System.out.println("Player 1: "+RPS[player1-1]);
System.out.println("Player 2: "+RPS[player2-1]);
System.out.println("Winner : Player 1");
}

else if(player1==3 && player2==1)


{
System.out.println("Player 1: "+RPS[player1-1]);
System.out.println("Player 2: "+RPS[player2-1]);
System.out.println("Winner : Player 2");
}

else if(player1==1 && player2==3)


{
System.out.println("Player 1: "+RPS[player1-1]);
System.out.println("Player 2: "+RPS[player2-1]);
System.out.println("Winner : Player 1");
}
matchNumber++;
}

}while(true);

} // if choice_ == 1

else if (choice_==2)
{
matchNumber=1;
String Choice;
byte choice;
int totalWin=0,totalLose=0,totalTie=0;
do{
menu();
System.out.print("Choice(1-5): ");
Choice = br.readLine();
choice = Byte.parseByte(Choice);

if (choice>0 && choice<5)


{
switch (choice)
{
case 1 :
String Option;
int option;
do
{
game(matchNumber);
System.out.print("Option (1-4): ");
Option = br.readLine();
option = Integer.parseInt(Option);
if (option==1)
{
System.out.println("You chose: Rock");
System.out.println("Computer : Scissors");
}

else if (option==2)
{
System.out.println("You chose: Paper");
System.out.println("Computer : Rock");
}

else if (option==3)
{
System.out.println("You chose: Rock");
System.out.println("Computer : Scissors");
}
else break;
System.out.println("You win!");
totalWin++;
matchNumber++;
} while (true); // do
break;

case 2 :
do{
boolean checkWinner = true;
boolean checkTie = false;
int computerMove = (int)(Math.random() * 3)+1;
String[] RPS = {"Rock", "Paper", "Scissors"};

game(matchNumber);
System.out.print("Option (1-4): ");
Option = br.readLine();
option = Integer.parseInt(Option);

if (option<1 || option>4)
{
System.out.println("Invalid");
}
else if (option==4)
{
break;
}
else
{
if(option==computerMove)
{
System.out.println("You chose: "+RPS[option-1]);
System.out.println("Computer : "+RPS[option-1]);
System.out.println("It's a tie!");
checkTie=true;
}

else if(option==1 && computerMove==2)


{
System.out.println("You chose: "+RPS[option-1]);
System.out.println("Computer : "+RPS[computerMove-1]);
checkWinner=false;
}

else if(option==2 && computerMove==1)


{
System.out.println("You chose: "+RPS[option-1]);
System.out.println("Computer : "+RPS[computerMove-1]);
checkWinner=true;
}

else if(option==2 && computerMove==3)


{
System.out.println("You chose: "+RPS[option-1]);
System.out.println("Computer : "+RPS[computerMove-1]);
checkWinner=false;
}

else if(option==3 && computerMove==2)


{
System.out.println("You chose: "+RPS[option-1]);
System.out.println("Computer : "+RPS[computerMove-1]);
checkWinner=true;
}

else if(option==3 && computerMove==1)


{
System.out.println("You chose: "+RPS[option-1]);
System.out.println("Computer : "+RPS[computerMove-1]);
checkWinner=false;
}

else if(option==1 && computerMove==3)


{
System.out.println("You chose: "+RPS[option-1]);
System.out.println("Computer : "+RPS[computerMove-1]);
checkWinner=true;
}

if(checkTie==false)
{
if(checkWinner)
{
System.out.println("You win");
totalWin++;
}
else
{
System.out.println("You lose");
totalLose++;
}
} // if not tie
} // else
matchNumber++;
} while(true);
break;

case 3 :
do
{
game(matchNumber);
System.out.print("Option (1-4): ");
Option = br.readLine();
option = Integer.parseInt(Option);

if (option==1)
{
System.out.println("You chose: Rock");
System.out.println("Computer : Paper");
}

else if (option==2)
{
System.out.println("You chose: Paper");
System.out.println("Computer : Scissors");
}

else if (option==3)
{
System.out.println("You chose: Rock");
System.out.println("Computer : Paper");
}
else break;

System.out.println("You lose!");
totalLose++;
matchNumber++;
} while (true); // do
break;

case 4 :
System.out.println("Standing");
System.out.println("Total number of wins : "+totalWin);
System.out.println("Total number of loses: "+totalLose);
if(matchNumber>1)matchNumber--;
break;

default :
System.out.println("Invalid Option.");
break;

} // switch
} // if main
else break;

System.out.printf("\n");
matchNumber++;
} while(true);
} // else if 2

else if(choice_==3)break;
else System.out.println("Invalid");

} while (true);
} // main

} // class

You might also like