Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.59 KB | None | 0 0
  1. package dicegames;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SpilPig {
  6.  
  7.     private Die die;
  8.     private int playerOneScore = 0;
  9.     private int playerTwoScore = 0;
  10.     private int player = 1;
  11.     private int rollScore;
  12.     private int scoreHolder;
  13.     private String decider;
  14.     Scanner scan = new Scanner(System.in);
  15.  
  16.     public SpilPig() {
  17.         die = new Die();
  18.     }
  19.  
  20.     public void playerSelector() {
  21.         System.out
  22.         .println("Who starts? Enter 1 for player one, enter 2 for player two");
  23.  
  24.         player = scan.nextInt();
  25.         scan.nextLine();
  26.     }
  27.  
  28.     public void takeTurn() {
  29.  
  30.         while (playerOneScore <= 100 && playerTwoScore <= 100) {
  31.             if (player == 1) {
  32.  
  33.                 System.out.println("player one: do you want to roll?");
  34.                 decider = scan.nextLine();
  35.  
  36.                 if (decider.equals("y")) {
  37.  
  38.                     die.roll();
  39.                     rollScore = die.getFaceValue();
  40.                     if (rollScore != 1) {
  41.                         playerOneScore += rollScore;
  42.                         System.out.println("your roll is: " + rollScore
  43.                                 + ", and your total score is: "
  44.                                 + playerOneScore);
  45.                     } else {
  46.                         rollScore = 0;
  47.                         scoreHolder += playerOneScore;
  48.                         playerOneScore = 0;
  49.                         System.out
  50.                         .println("your rolled a 1, and the turn is yielded to player two. your total score is: "
  51.                                 + scoreHolder
  52.                                 + ", and your score is: "
  53.                                 + playerOneScore);
  54.                         player = 2;
  55.  
  56.                     }
  57.  
  58.                 } else {
  59.                     player = 2;
  60.                     scoreHolder += playerOneScore;
  61.                 }
  62.             } else if (player == 2) {
  63.                 System.out.println("player two: do you want to roll?");
  64.                 decider = scan.nextLine();
  65.  
  66.                 if (decider.equals("y")) {
  67.                     die.roll();
  68.                     rollScore = die.getFaceValue();
  69.                     if (rollScore != 1) {
  70.  
  71.                         playerTwoScore += rollScore;
  72.                         System.out.println("your roll is: " + rollScore
  73.                                 + ", and your score this round is: "
  74.                                 + playerTwoScore);
  75.                     } else {
  76.                         rollScore = 0;
  77.                         scoreHolder += playerTwoScore;
  78.                         playerTwoScore = 0;
  79.                         System.out
  80.                         .println("your rolled a 1, and the turn is yielded to player one. your total score is: "
  81.                                 + scoreHolder
  82.                                 + ", and your score this round is: "
  83.                                 + playerTwoScore);
  84.                         player = 1;
  85.  
  86.                     }
  87.  
  88.                 } else {
  89.                     player = 1;
  90.                     scoreHolder += playerTwoScore;
  91.                 }
  92.  
  93.             } else {
  94.                 System.out
  95.                 .println("Enter 1 for player one, enter 2 for player two, or 3 to quit the game");
  96.                 player = scan.nextInt();
  97.  
  98.             }
  99.  
  100.         }
  101.  
  102.         if (playerOneScore >= 100) {
  103.             System.out.println("player one has won");
  104.         } else if (playerTwoScore >= 100) {
  105.             System.out.println("player two has won");
  106.         } else {
  107.             System.out.println("No winners");
  108.         }
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement