Admin
Investor Persona
File name: rps4.java
Display Results:
[1] Rock
[2] Paper
[3] Scissor
Input:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
As this project show you a simple game, I implement a Computer AI that will allow him to randomize a number from 1-3. Therefore, it is up for the user to choose.
Once the User chooses, it then tries to measure the conditions programmed and display the result.
- Code:
import java.io.*;
import java.util.*;
public class rps4{
public static void main(String[] args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int choice;
Random r=new Random();
int x=0;
do{
System.out.println("Choose: ");
System.out.println("[1] Rock");
System.out.println("[2] Paper");
System.out.println("[3] Scissor");
System.out.println(" ");
choice = Integer.parseInt(br.readLine());
int ai=r.nextInt(4);
if((choice==1)&&(ai==2)){
System.out.println("Player vs Computer");
System.out.println(" Rock :: Paper");
System.out.println(" ");
System.out.println("You Lose!");
}
else if((choice==1)&&(ai==3)){
System.out.println(" Player vs Computer ");
System.out.println(" Rock :: Scissor ");
System.out.println(" ");
System.out.println("You Win!");
}
else if((choice==2)&&(ai==3)){
System.out.println(" Player vs Computer");
System.out.println(" Paper :: Scissor");
System.out.println(" ");
System.out.println("You Lose");
}
else if((choice==3)&&(ai==1)){
System.out.println(" Player vs Computer ");
System.out.println(" Scissor :: Rock ");
System.out.println(" ");
System.out.println("You Lose!");
}
else if((choice==3)&&(ai==2)){
System.out.println(" Player vs Computer ");
System.out.println(" Scissor :: Paper ");
System.out.println(" ");
System.out.println("You Win!");
}
else if((choice==2)&&(ai==1)){
System.out.println(" Player vs Computer ");
System.out.println(" Paper :: Rock ");
System.out.println(" ");
System.out.println("You Win");
}
else if((choice==1)&&(ai==1)){
System.out.println(" Player VS Computer ");
System.out.println(" Rock :: Rock ");
System.out.println("It's Draw!!");
}
else if((choice==2)&&(ai==2)){
System.out.println(" Player vs Computer");
System.out.println(" Paper :: Paper");
System.out.println(" ");
System.out.println("It's Draw!!");
}
else {
System.out.println(" Player vs Computer");
System.out.println(" Scissor :: Scissor");
System.out.println(" ");
System.out.println("It's Draw!!");
}
x++;} while(x<=3);
}
}
Display Results:
[1] Rock
[2] Paper
[3] Scissor
Input:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
As this project show you a simple game, I implement a Computer AI that will allow him to randomize a number from 1-3. Therefore, it is up for the user to choose.
Once the User chooses, it then tries to measure the conditions programmed and display the result.
No Comment.