Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- /**
- *
- */
- /**
- * @author keith
- *
- */
- public class pigGame2_18034383 {
- /**
- * @param args
- */
- public static void main(String[] args) {
- int humanRoll = 0;
- int computerRoll = 0;
- int currentRollTotal = 0;
- int totalHumanAll = 0;
- int totalComputerAll = 0;
- String rollAgain = null;
- String playAgain = "yes";
- String computerTurn = "no";
- String humanTurn = "yes";
- Scanner keyboard = new Scanner(System.in);
- Random randomNumbers = new Random();
- while ( ("yes").equals(playAgain) )
- {
- while ( ("yes").equals(humanTurn) )
- {
- humanRoll = randomNumbers.nextInt(5)+1;
- System.out.println( "Your current score is: " + totalHumanAll);
- System.out.println( "The Computer's"
- + " current score is: " + totalComputerAll);
- System.out.println("The total rolled "
- + "this turn is: " + currentRollTotal);
- System.out.println("Your previous roll is: " + humanRoll );
- if (humanRoll == 1)
- {
- System.out.println("You rolled a 1 therefore"
- + " it is the computer's turn now");
- humanTurn = "no";
- computerTurn = "yes";
- break;
- }
- System.out.println("Would you like to roll again or hold?(yes/hold): " );
- while ( !("yes").equals(rollAgain) || !("hold").equals(rollAgain) );
- {
- System.out.println("Please re-enter if you would like to "
- + "roll again or hold(yes/hold): " );
- rollAgain = keyboard.nextLine();
- humanTurn = "yes";
- }
- }
- if ( totalHumanAll>100 )
- {
- System.out.println( "The winner is the player "
- + "with " + totalHumanAll + "points" + "while the "
- + "computer scored " + totalComputerAll + " points" );
- computerTurn = "no";
- System.out.println("Would you like to play again?(yes/no): ");
- playAgain =keyboard.nextLine();
- while ( !("yes").equals(playAgain) || !("no").equals(playAgain) );
- {
- System.out.println("Please re-enter if you would you like"
- + " to play again?(yes/no): ");
- playAgain =keyboard.nextLine();
- }
- }
- while ( ("yes").equals(computerTurn) )
- {
- computerRoll = randomNumbers.nextInt(5)+1;
- if ( computerRoll == 1 )
- {
- currentRollTotal = 0;
- break;
- }
- totalComputerAll = totalComputerAll + currentRollTotal;
- if ( totalComputerAll>=20)
- {
- computerTurn = "no";
- humanTurn = "yes";
- }
- }
- if (totalComputerAll>100)
- {
- System.out.println( "The winner is the computer "
- + "with " + totalComputerAll + "points" + "while you "
- + "scored " + totalHumanAll + " points" );
- humanTurn = "no";
- System.out.println("Would you like to play again?(yes/no): ");
- playAgain =keyboard.nextLine();
- while ( !("yes").equals(playAgain) || !("no").equals(playAgain) );
- {
- System.out.println("Please re-enter if you would you like"
- + " to play again?(yes/no): ");
- playAgain =keyboard.nextLine();
- }
- }
- }
- keyboard.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement