Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class waterFireGrass {
- public static void main(String[] args) {
- Scanner k = new Scanner(System.in);
- Random r = new Random();
- int p1 = 0, p2 = 0, set = 0, gameLoop = 0, aiChoice = 0, playerChoice = 0;
- while(gameLoop == 0){
- gameLoop = 0;
- playerChoice = 0;
- while(playerChoice < 1 || playerChoice >3 ){
- System.out.println("Choose Water(1), Fire(2) Grass(3)");
- playerChoice = k.nextInt();
- }
- aiChoice = r.nextInt(3) + 1;
- if(playerChoice == 1 && aiChoice == 2){
- System.out.println("You chose Water and beat the computers Fire");
- p1++;
- set++;
- }
- else if(playerChoice == 1 && aiChoice == 3){
- System.out.println("You chose Water and lost to the computers Grass");
- p2++;
- set++;
- }
- else if(playerChoice == 2 && aiChoice == 1){
- System.out.println("You chose Fire and lost to the computers Water");
- p2++;
- set++;
- }
- else if(playerChoice == 2 && aiChoice == 3){
- System.out.println("You chose Fire and beat the computers Grass");
- p1++;
- set++;
- }
- else if(playerChoice == 3 && aiChoice == 1){
- System.out.println("You chose Grass and beat the computers Water");
- p1++;
- set++;
- }
- else if(playerChoice == 3 && aiChoice == 2){
- System.out.println("You chose Grass and lost to the computers Fire");
- p2++;
- set++;
- }
- else if(playerChoice == aiChoice){
- System.out.println("You both chose the same thing");
- }
- else
- System.out.println("Error");
- do{
- if(set == 5 ){
- if(p1 > p2)
- System.out.println("You won " + p1 + "\nThe computer won " + p2 + "\n You are the winner!");
- else
- System.out.println("You won " + p1 + "\nThe computer won " + p2 + "\n The computer is the winner!");
- System.out.println("Would you like to play again? 0 = Yes, 1 = No");
- gameLoop = k.nextInt();
- set = 0;
- p2 = 0;
- p1 = 0;
- }
- }while(gameLoop >1 || gameLoop < 0);
- }
- k.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement