Question: Here is a dice game that I need to complete for my CS class. Game Rules The game supports a single player using five dice.

Here is a dice game that I need to complete for my CS class.

Game Rules

The game supports a single player using five dice.

each game consists of thirteen rounds

each round consists of one, two or three rolls

player rolls all five dice at the start of each round

player may choose a subset of dice (1 or more) and roll a second time (optional). You hold dice by clicking on them and they become highlighted. You can only roll unselected (not highlighted) dice.

player may choose a subset of dice (1 or more) and roll a third time (optional)

player may stop at any time after the first, second, or third roll and select the most appropriate scoring category. Player may have to take a zero if no category is satisfied.

each scoring category can be selected once, and only once

player may start a new game at any time by selecting File -> New Game

player may quit at any time by selecting the File -> Quit

Scoring Categories

Dice values do not need to appear in a particular order to qualify for any category.

Singles (sum of all dice with specified value of 1 through 6)

Three-of-a-kind (25 pts)

Full House (35 pts) is a pair and three-of-a-kind such as 2 2 4 4 4

Four-of-a-kind (40 pts)

Small Straight uses four of the dice (30 pts) such as 1 2 3 4 or 2 3 4 5 or 3 4 5 6

Large Straight uses five dice (45 pts) such as 2 3 4 5 6 or 1 2 3 4 5

Five-of-a-kind (50 pts)

Chance (total of all dice)

Bonus if the total from the left column (Singles) is 63 or higher (35 pts)

Step 1: Create a New BlueJ Project

Step 2: Use Existing GVdie

Rather than writing your own Die class, we are providing a completed class for you. Create a new class in BlueJ called GVdie and delete all of the provided code. Cut and paste the provided code from (GVdie.java) into the newly created class. It should compile with no errors. Do not make any changes to this code. You only need to use the following methods, but you are encouraged to read the source code to see how it works.

private GVdie d1; // declare a GVdie

d1 = new GVdie(); // instantiate a GVdie

d1.roll(); // roll the die (1 6)

int val = d1.getValue(); // check current value

d1.setBlank(); // set face to blank (value to 0)

d1.setHeld(true); // mark die as selected

if(d1.isHeld()) // check if die is selected

Step 3: Create a class called PokerDice

Instance Variables

A class should contain several instance variables (section 5.1). Some instance members will not change after given an initial value. It is good practice to define these as final and use ALL CAPS for the names (section 11.1). Provide appropriate names and data types for each of the private instance variables:

an ArrayList of GVdie.

integers to keep track of the score, number of rolls, and number of rounds

an array of seven integers used by the helper methods

declare public final static members for each of the scoring categories. These need to be public and static to support testing.

public final static int FULL_HOUSE = 35;

Constructor

A constructor is a special method with the same name as the class and generally initializes the fields to appropriate starting values. Refer to sections 5.6 and 5.7.

public PokerDice ( ) - instantiate the ArrayList and fill it with five GVdie. Remember to instantiate each GVdie before you add it to the ArrayList. Instantiate the array of seven integers. Invoke the resetGame() method to initialize the instance variables.

Accessor Methods (10 pts)

An accessor method does not modify class fields. The names for these methods, which simply return the current value of a field, often begin with the prefix get.

public int getScore ( ) - return the current score.

public boolean okToRoll ( ) - return true if it is legal to roll the dice. Otherwise, return false. There are only three rolls per round.

public boolean gameOver ( ) - return true if the game is over because all rounds have been completed. Otherwise, return false.

public ArrayList getDice ( ) - return the ArrayList of GVdie. This method is only one line of code and is invoked by the GUI so that it can display the game's dice.

Helper Methods (10 pts)

Designated as private, a helper method is designed to be used by other methods within the class. Good practice is to make methods private unless they need to be public. Refer to section 5.5.

private void tallyDice( ) this private helper method supports the other methods. Update the array of integers to tally the number of 1s, 2s, 3s, 4s, 5s and 6s for the current dice. Index zero of the array is not used. Remember to clear the array first.

// clears the array

for (int i=1; i

tally[i] = 0;

// update tally for each Die

//assuming the name of the ArrayList of GVdie is: myDice

for (GVdie d : myDice){

tally[d.getValue()]++;

}

private boolean hasStraight(int length) this private helper method supports other methods. First, invoke the tallyDice() method. Then, determine if the set of dice contains a sequence of length numbers. The method should work for any length up to the number of dice. Return true or false. Do not update the scores at this point.

private boolean hasMultiples(int count) this private helper method supports other methods. First, invoke the tallyDice() method. Return true if there are count, or more, identical values. Otherwise, return false. We use this method to check for three, four and five of a kind. Do not update the scores at this point.

private boolean hasStrictPair() this private helper method supports other methods. First, invoke the tallyDice() method. Then, determine if the set of dice contains a pair of any numbers (but only a pair). Return true or false. Do not update the scores at this point.

private void nextRound() this private helper method prepares for the next round by incrementing the round counter, setting rolls count to zero, setting all dice to blank and unselected. Each one of the scoring methods will invoke the nextRound() method.

Mutator Methods (35 pts)

A mutator method performs tasks that may modify class fields. Refer to section 5.5.

public void resetGame( ) - set instance variables to zero and all dice to blank. Make sure no dice are held.

public void rollDice( ) increment the number of rolls and roll each of the dice that are not currently held.

public void checkThreeOfAKind( ) - update the score if the dice currently include a three of a kind. Invoke the hasMultiples(3) method to determine if the category is achieved. Afterwards, invoke the nextRound() method. Note, a four-of-a-kind and five-of-a-kind also qualify as a three-of-a-kind.

public void checkFullHouse( ) - update the score if the dice currently include a full house. Invoke the hasMultiples(3) and hasStrictPair() methods to determine if the category is achieved. Afterwards, invoke the nextRound() method to prepare for the next round. Note, a five-of-a-kind also qualifies as a full house.

public void checkSmallStraight( ) - update the score if the dice currently include a small straight. Use the hasStraight(4) method to determine if the category is achieved. Afterwards, invoke nextRound() to prepare for the next round. Note, a large straight also qualifies as a small straight.

public void checkLargeStraight( ) - update the score if the dice currently include a large straight. Use the hasStraight(5) method to determine if the category is achieved. Afterwards, invoke nextRound() to prepare for the next round.

public void checkFourOfAKind( ) - update the score if the dice currently include a four-of-a-kind. Invoke the hasMultiples(4) method to determine if the category is achieved. Afterwards, invoke nextRound() to prepare for the next round. Note, a five-of-a-kind also qualifies as a four-of-a-kind.

public void checkFiveOfAKind( ) - update the score if the dice currently include a five of a kind. Invoke the hasMultiples(5) method to determine if the category is achieved. Afterwards, invoke nextRound() to prepare for the next round.

public void checkSingles(int val) - update the score by adding all dice with the value of val. For example, three 4s will increase the score by 12 and five 1s will increase the score by 5. Afterwards, invoke nextRound() to prepare for the next round.

public void checkChance( ) - update the score with the sum of all dice. Afterwards, invoke nextRound() to prepare for the next round.

Bonus Score (5 pts)

Add a feature for the game to keep track of the total score for the left column (Singles). Add an instance member as needed. Player earns a bonus of 35 points if left column total exceeds 62.

public int getBonusScore () return 35 or 0 as appropriate

update the getScore()method- before returning the score, invoke the getBonusScore() method and add the bonus points to the score of the game.

Update the checkSingles(int val) method to update the score for the left column (Singles) by adding all dice with the value of val. For example, three 4s will increase the score for the left column by 12 and five 1s will increase the score by 5.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!