Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.12 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4.  
  5. /**
  6.  *
  7.  */
  8.  
  9. /**
  10.  * @author keith
  11.  *
  12.  */
  13. public class pigGame2_18034383 {
  14.  
  15.     /**
  16.      * @param args
  17.      */
  18.     public static void main(String[] args) {
  19.        
  20.         int humanRoll = 0;
  21.         int computerRoll = 0;  
  22.         int currentRollTotal = 0;
  23.         int totalHumanAll = 0;
  24.         int totalComputerAll = 0;
  25.         String rollAgain = null;
  26.         String playAgain = "yes";  
  27.         String computerTurn = "no";
  28.         String humanTurn = "yes";
  29.         Scanner keyboard = new Scanner(System.in);
  30.         Random randomNumbers = new Random();
  31.        
  32.         while ( ("yes").equals(playAgain) )
  33.         {
  34.             while ( ("yes").equals(humanTurn) )
  35.             {
  36.                 humanRoll = randomNumbers.nextInt(5)+1;
  37.                 System.out.println( "Your current score is: " + totalHumanAll);
  38.                 System.out.println( "The Computer's"
  39.                         + " current score is: " + totalComputerAll);
  40.                 System.out.println("The total rolled "
  41.                                 + "this turn is: " + currentRollTotal);            
  42.                 System.out.println("Your previous roll is: " + humanRoll );
  43.                
  44.                 if (humanRoll == 1)
  45.                 {
  46.                     System.out.println("You rolled a 1 therefore"
  47.                             + " it is the computer's turn now");
  48.                     humanTurn = "no";
  49.                     computerTurn = "yes";
  50.                     break;
  51.                 }
  52.                
  53.                 System.out.println("Would you like to roll again or hold?(yes/hold): " );
  54.                
  55.                 while ( !("yes").equals(rollAgain) || !("hold").equals(rollAgain) );
  56.                 {                  
  57.                     System.out.println("Please re-enter if you would like to "
  58.                             + "roll again or hold(yes/hold): " );
  59.                     rollAgain = keyboard.nextLine();
  60.                     humanTurn = "yes";
  61.                 }
  62.             }
  63.            
  64.             if ( totalHumanAll>100 )
  65.             {
  66.                 System.out.println( "The winner is the player "
  67.                         + "with " + totalHumanAll + "points" + "while the "
  68.                         + "computer scored " + totalComputerAll + " points" );
  69.                 computerTurn = "no";
  70.                
  71.                 System.out.println("Would you like to play again?(yes/no): ");
  72.                 playAgain =keyboard.nextLine();            
  73.                 while ( !("yes").equals(playAgain) || !("no").equals(playAgain) );
  74.                 {
  75.                     System.out.println("Please re-enter if you would you like"
  76.                             + " to play again?(yes/no): ");
  77.                     playAgain =keyboard.nextLine();
  78.                 }
  79.             }
  80.            
  81.             while ( ("yes").equals(computerTurn) )
  82.             {
  83.                 computerRoll = randomNumbers.nextInt(5)+1;
  84.                
  85.                 if ( computerRoll == 1 )
  86.                 {
  87.                     currentRollTotal = 0;  
  88.                     break;
  89.                 }
  90.                
  91.                 totalComputerAll = totalComputerAll + currentRollTotal;
  92.                
  93.                 if ( totalComputerAll>=20)
  94.                 {
  95.                     computerTurn = "no";
  96.                     humanTurn = "yes";
  97.                 }              
  98.             }          
  99.            
  100.            
  101.             if (totalComputerAll>100)
  102.             {
  103.                 System.out.println( "The winner is the computer "
  104.                         + "with " + totalComputerAll + "points" + "while you "
  105.                         + "scored " + totalHumanAll + " points" );
  106.                
  107.                 humanTurn = "no";
  108.                
  109.                 System.out.println("Would you like to play again?(yes/no): ");
  110.                 playAgain =keyboard.nextLine();
  111.                 while ( !("yes").equals(playAgain) || !("no").equals(playAgain) );
  112.                 {
  113.                     System.out.println("Please re-enter if you would you like"
  114.                             + " to play again?(yes/no): ");
  115.                     playAgain =keyboard.nextLine();                
  116.                 }
  117.             }          
  118.         }  
  119.         keyboard.close();
  120.     }  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement