Question: create simple Yahtzee game in java Console Non GUI Use requiremnts below to create program public yahtzee(){ //This constructor will initialize your 5 x 3

create simple Yahtzee game in java Console Non GUI Use requiremnts below to create program public yahtzee(){ //This constructor will initialize your 5 x 3 array and set it with empty values, in this case 0 

Functions

Main

This function will call the menu.

Menu

The menu will prompt the user if they want to play the game or not. At the completion of a game it will ask if they want to play another round.

public static void menu(){ }

Start Game

This function will reset the score to zero, the number of rounds played to 0 and begin iterating through the rounds until the playRound function returns false;

Clear Array

At the end of each round you will want to set the values in the array back to 0.

Roll

Generate X random numbers (0 to 5 numbers) with a value range of 1 to 6 and place them in the last slots of the array. X will be determined by how many numbers were held in the preceding roll. If everything was held, no numbers will be generated or if no values were held, then you generate an entirely new set of numbers).

Note we are using the last slots of the array because our hold will place numbers up front first, so we start inserting after the slots we know are "held".

This function needs to be aware of what set of rolls it is on, if its the second roll, it needs to place values in the second row.

Hold

This will create a loop asking the user for which values to hold. It will only accept numbers 1 to 5 or the letter q. Once q is selected it will copy the selected values to the next row in the array BUT it will place them sequentially in the slots starting at 0 (this will make your life easier, trust me). Then it will return a value for the number of values held.

Play Round

This function will be called at the start of each round.

It will start by clearnig the array of current values.

Then it will let the user roll 3 times and hold after the first 2 rolls. What is left after the final roll is what the user is scored on.

At the end of the round it will increment the round counter by 1. If 10 rounds have been completed, it will return false otherwise it will return true.

Score Hand

This function will take the final row of numbers and score it based upon basic Yahtzee rules. To keep the logic simple, we will allow the program to choose the best score and regardless of whether the user has scored it before, allow that score. Note these scores are N simplified for this program.

3 of a kind - Sum of all the dice + 5

4 of a kind - Sum of all the dice + 10

full house (2 matching dice AND 3 matching dice) - 25 pts

small straight (4 dice in consecutive sequence) - 30 pts

large straight (all dice in consecutive sequence) - 40 pts

Yahtzee (all dice match) - 50 pts

Chance (anything) - Sum of all the dice

HINT- for scoring, it might help to order your array sequentially before attempting to logic out the score.

must be able to freeze the die user would like to hold. not re roll.

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!