Advertisement
Guest User

karel

a guest
Jun 30th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.05 KB | None | 0 0
  1. import java.util.*;
  2. public class waterFireGrass {
  3.  
  4.     public static void main(String[] args) {
  5.        
  6.         Scanner k = new Scanner(System.in);
  7.         Random r = new Random();
  8.         int p1 = 0, p2 = 0, set = 0, gameLoop = 0, aiChoice = 0, playerChoice = 0;
  9.         while(gameLoop == 0){
  10.            
  11.             gameLoop = 0;      
  12.             playerChoice = 0;
  13.            
  14.             while(playerChoice < 1 || playerChoice >3 ){
  15.                 System.out.println("Choose Water(1), Fire(2) Grass(3)");
  16.                 playerChoice = k.nextInt();
  17.        
  18.             }
  19.            
  20.              aiChoice = r.nextInt(3) + 1;
  21.        
  22.             if(playerChoice == 1 && aiChoice == 2){
  23.                 System.out.println("You chose Water and beat the computers Fire");
  24.                 p1++;
  25.                 set++;
  26.             }
  27.             else if(playerChoice == 1 && aiChoice == 3){
  28.                 System.out.println("You chose Water and lost to the computers Grass");
  29.                 p2++;
  30.                 set++;
  31.             }
  32.             else if(playerChoice == 2 && aiChoice == 1){
  33.                 System.out.println("You chose Fire and lost to the computers Water");
  34.                 p2++;
  35.                 set++;
  36.             }
  37.             else if(playerChoice == 2 && aiChoice == 3){
  38.                 System.out.println("You chose Fire and beat the computers Grass");
  39.                 p1++;
  40.                 set++;
  41.             }
  42.             else if(playerChoice == 3 && aiChoice == 1){
  43.                 System.out.println("You chose Grass and beat the computers Water");
  44.                 p1++;
  45.                 set++;
  46.             }
  47.             else if(playerChoice == 3 && aiChoice == 2){
  48.                 System.out.println("You chose Grass and lost to the computers Fire");
  49.                 p2++;
  50.                 set++;
  51.             }
  52.             else if(playerChoice == aiChoice){
  53.                 System.out.println("You both chose the same thing");
  54.                
  55.             }
  56.             else
  57.                 System.out.println("Error");
  58.        
  59.             do{
  60.                 if(set == 5 ){
  61.                     if(p1 > p2)
  62.                         System.out.println("You won " + p1 + "\nThe computer won " + p2 + "\n You are the winner!");
  63.                    
  64.                     else
  65.                         System.out.println("You won " + p1 + "\nThe computer won " + p2 + "\n The computer is the winner!");
  66.  
  67.                     System.out.println("Would you like to play again? 0 = Yes, 1 = No");
  68.                         gameLoop = k.nextInt();
  69.                        
  70.                     set = 0;
  71.                     p2 = 0;
  72.                     p1 = 0;
  73.                 }      
  74.             }while(gameLoop >1 || gameLoop < 0);
  75.         }
  76.        
  77.         k.close();
  78.     }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement