Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a simple Yahtzee game in Java(NO GUI -console only). -It should also record top scores in a txt.file that displays when user starts game

Create a simple Yahtzee game in Java(NO GUI -console only).

-It should also record top scores in a txt.file that displays when user starts game and if they get a highscore it saves the score number and the score hand they got back into the txt file.

- have an additional file to store play data from the last 10 games.will be called score.dat" and will store a summary of the play from previous games

Requirements

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 freexze the die user would like to hold. not re roll.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions

Question

LO5 Illustrate the steps in developing a base pay system.

Answered: 1 week ago