Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dicegames;
- import java.util.Scanner;
- public class SpilPig {
- private Die die;
- private int playerOneScore = 0;
- private int playerTwoScore = 0;
- private int player = 1;
- private int rollScore;
- private int scoreHolder;
- private String decider;
- Scanner scan = new Scanner(System.in);
- public SpilPig() {
- die = new Die();
- }
- public void playerSelector() {
- System.out
- .println("Who starts? Enter 1 for player one, enter 2 for player two");
- player = scan.nextInt();
- scan.nextLine();
- }
- public void takeTurn() {
- while (playerOneScore <= 100 && playerTwoScore <= 100) {
- if (player == 1) {
- System.out.println("player one: do you want to roll?");
- decider = scan.nextLine();
- if (decider.equals("y")) {
- die.roll();
- rollScore = die.getFaceValue();
- if (rollScore != 1) {
- playerOneScore += rollScore;
- System.out.println("your roll is: " + rollScore
- + ", and your total score is: "
- + playerOneScore);
- } else {
- rollScore = 0;
- scoreHolder += playerOneScore;
- playerOneScore = 0;
- System.out
- .println("your rolled a 1, and the turn is yielded to player two. your total score is: "
- + scoreHolder
- + ", and your score is: "
- + playerOneScore);
- player = 2;
- }
- } else {
- player = 2;
- scoreHolder += playerOneScore;
- }
- } else if (player == 2) {
- System.out.println("player two: do you want to roll?");
- decider = scan.nextLine();
- if (decider.equals("y")) {
- die.roll();
- rollScore = die.getFaceValue();
- if (rollScore != 1) {
- playerTwoScore += rollScore;
- System.out.println("your roll is: " + rollScore
- + ", and your score this round is: "
- + playerTwoScore);
- } else {
- rollScore = 0;
- scoreHolder += playerTwoScore;
- playerTwoScore = 0;
- System.out
- .println("your rolled a 1, and the turn is yielded to player one. your total score is: "
- + scoreHolder
- + ", and your score this round is: "
- + playerTwoScore);
- player = 1;
- }
- } else {
- player = 1;
- scoreHolder += playerTwoScore;
- }
- } else {
- System.out
- .println("Enter 1 for player one, enter 2 for player two, or 3 to quit the game");
- player = scan.nextInt();
- }
- }
- if (playerOneScore >= 100) {
- System.out.println("player one has won");
- } else if (playerTwoScore >= 100) {
- System.out.println("player two has won");
- } else {
- System.out.println("No winners");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement