Question: Write java program for dice game Pig for 2 players. Game Rules The rules to the (dice) game of Pig: You will need 2 dice.
Write java program for dice game Pig for 2 players. Game Rules The rules to the (dice) game of Pig: You will need 2 dice. a. The players each take turns rolling two die. b. A player scores the sum of the two dice thrown (unless the roll contains a 1): If a single number 1 is thrown on either die, the score for that whole turn is lost (referred to as Pigged Out). A 1 on both dice is scored as 25. c. During a single turn, a player may roll the dice as many times as they desire. The score for a single turn is the sum of the individual scores for each dice roll. d. The first player to reach the goal score wins unless a player scores higher subsequently in the same round. Therefore, everyone in the game must have the same number of turns. Execution and User Input This program is quite interactive with the user(s) and will take in the following information: The program will prompt for the number of points the game will be played to (1-100). Once a valid goal score has been entered the game will roll the dice for the first player by randomly selecting the valid values 1 thru 6 for each of the two dice. The score will be displayed and the player will be prompted to continue their turn by rolling the die again (unless they have pigged out by rolling a single 1). The player will have the option of continuing or ending the turn by entering y for Yes. When Player 1 completes their turn, Player 2 will engage the exact same way. At the conclusion of both players turns the total score for each will be compared to the goal score to determine if the game has ended. If the goal score has not been reached, then the game continues with both players taking their turn in sequence. Once one or both of the players reaches the goal score the game ends and the results are displayed. The game may end in a tie. At the conclusion of a game, the program will prompt whether a new game shall be played: y for Yes. Requirements
Generally, user input must not be case sensitive. The project must consist of the following classes. o Class EntryPoint: contains the main method and instantiation of the GameController class; o Class GameController: Manages the flow of 2-player game play. The players must have the option to play as many games as desired. The user must supply a valid maximum score. After the goal score is reached by at least one player, the winner and winning score must be displayed. Will show total scores after each round of rolls. o Class PigDice: Holds the state of a set of dice for a player. Scoring must be correct for all combinations of dice. o Class Die: Represents a standard, fair, 6-sided die. Simulates a die being rolled. The face value of the die can be observed without rolling. Specifications Die class Provides all functionality for random number generation and access of the rolled face value. Must provide an overloaded constructor that, for testing purposes, takes a random number seed. For testing and submission, use 5 and 10 as seeds to the random number generator. EntryPoint class Contains the main method. It declares and allocates a GameController object and invokes the play method. GameController class Method play contains the central game control logic. Use of additional private methods must be used for modularization. o For example, since the play method controls the game logic, a private method takeTurn (which takes the keyboard Scanner and a PigDice object) should call a method that takes a turn for a single player. o A second private method would maintain functionality to acquire the valid goal score. PigDice Class This class (1) maintains the Player Pig score for the round, (2) maintains and saves the total Pig score for a player, and (3) provides functionality related to rolling and scoring die. The following methods discuss that functionality in more detail. Method currentTotal returns the current total integer score for a game of Pig. Method currentRound returns the current integer score for a round. Method rollDice simulates rolling two die. Method evaluate computes the rolled score and adds to the current round score. Method lastRoll acquires a formatted string describing the values of the last dice roll. Method save will (1) add the current round score to the total score and (2) clear the current round score, and (3) return the complete round score. Method piggedOut returns true / false whether the last roll contained a 1 and ended the roll. Additional private methods used for modularization: o Method singleOneRolled returns true / false whether one of the two die resulted in a 1. o Method doubleOnesRolled returns true / false whether both die rolled a 1.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
