package class8_3_Elevens; // MSOE. Dr. Yoder. 28 October 2015. import class8_2_Elevens.Die; // Use your Die from Lab7 in the place of class8_2_Elevens.Die. // It follows the UML diagram defined in that lab. /** * This class represents a player -- human or computer * in the game. * * The player holds two dice, and remembers the value last rolled on each die. * * The individual player will automatically win by rolling 11, * and automatically lose by rolling more than 11. * These conditions can be checked with isMidgameWinner() and isMidgameLoser(). * At the end of the game, this player's total score also needs to be higher * than the opponent to win the game. */ public class Player { private int playerRoll1; //the roll of the player's six-sided die private int playerRoll2; //the roll of the player's ten-sided die private Die playerDie1 = new Die(); //the six-sided die private Die playerDie2 = new Die(10); //the ten-sided die private String playerName; //the player's name /** * Create a new player * @param playerName the name to display for this player. Should start with a capital letter */ public Player(String playerName) { this.playerName = playerName; } /** * Compute the sum of the player's two dice. * @return the sum of the dice. */ public int getTotal() { return playerRoll1 + playerRoll2; } /** * Determine if player has guaranteed a win by rolling 11. * @return true if player's score is 11. */ public boolean isMidgameWinner() { return getTotal() == 11; } /** * Determine if player has already lost by rolling past 11 * @return true if player's total is greater than 11. */ public boolean isMidgameLooser() { return getTotal() > 11; } /** * Display the results of a roll */ public void displayRolls() { System.out.println(playerName+" rolled " + playerRoll1 + " on the six-sided die, and " + playerRoll2 + " on the ten-sided die for a total of " + getTotal()); } /** * Roll the dice the first time and display the results. */ public void initialRoll() { playerRoll1 = playerDie1.roll(); playerRoll2 = playerDie2.roll(); displayRolls(); } /** * Re roll one of the player's two dice * @param numDie The number of the die to re-roll. 1 - six-sided. 2 - ten-sided. */ public void reRollOneDie(int numDie) { Die dieToReroll; if(numDie == 1) { dieToReroll = playerDie1; } else { dieToReroll = playerDie2; } int playerRoll = dieToReroll.roll(); if(numDie == 1) { playerRoll1 = playerRoll; } else { playerRoll2 = playerRoll; } displayRolls(); } }