Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C programing language: Design the Yahtzee game with functions that you see fi

ID: 3674763 • Letter: I

Question

In C programing language:

Design the Yahtzee game with functions that you see fit. I recommend that you start with a structure chart and determine sub-problems and functions accordingly. You must also take advantage of applying pointers, output parameters, and/or arrays! Your Yahtzee game must also implement the following algorithm:

(1) (5 pts) Print a game menu for Yahtzee with the following options:

            1. Print game rules

            2. Start a game of Yahtzee

            3. Exit

(2) (5 pts) Get a menu option from the user; clear the screen

(3) (10 pts) If option 1 is entered, then print the game rules stated above and repeat step (1)

     otherwise if option 2 is entered, then continue on to step (4); player 1 starts the game

     otherwise if option 3 is entered, then print a goodbye message and quit the program

     otherwise repeat step (1)

(4) (5 pts) Ask the player to hit any key to continue on to roll the five dice

(5) (5 pts) Roll the five dice and display the face values of each die; enumerate each die with

     a number 1 - 5; add 1 to the total number of rolls for this round

(6) (10 pts) If the total number of rolls for this round is less than three,

         then ask the player (Y/N) if he/she wants to use the roll for one of the game combinations

     otherwise a combination must be selected.

            1. Sum of 1's        7. Three-of-a-kind

            2. Sum of 2's        8. Four-of-a-kind

            3. Sum of 3's        9. Full house

            4. Sum of 4's        10. Small straight

            5. Sum of 5's        11. Large straight

            6. Sum of 6's        12. Yahtzee

                        13. Chance

(7) (15 pts) If the number of rolls is three or "yes" is entered, then save the combination and it may not be selected again in the future

          (Note: The selection of the combination must be verified. If the user selects full house, but does not have one, then your

           must assign 0 points for the combination);

          continue on to step (8); clear the screen

     otherwise if "no" is entered, ask the user which dice to re-roll (1 - 5); re-roll the selected die or dice; clear the screen;

         repeat step (6)

     otherwise repeat step (6)

(8) (5 pts) Alternate players

(9) (10 pts) If each player has rolled for the round, then increment the round number

         if the round number is equal to 14, then continue on to step (10)

         otherwise repeat step (4)

     otherwise repeat step (4)

(10) (5 pts) If the total score in the upper section is greater than or equal to 63 for a player, then add 35 points to the total score

(11) (5 pts) Print the scores for both players and print the winner

(12) (5 pts) Repeat step (1)

The Rules of Yahtzee:

The scorecard used for Yahtzee is composed of two sections. A upper section and a lower section. A total of thirteen boxes or thirteen scoring combinations are divided amongst the sections. The upper section consists of boxes that are scored by summing the value of the dice matching the faces of the box. If a player rolls four 3's, then the score placed in the 3's box is the sum of the dice which is 12. Once a player has chosen to score a box, it may not be changed and the combination is no longer in play for future rounds. If the sum of the scores in the upper section is greater than or equal to 63, then 35 more points are added to the players overall score as a bonus. The lower section contains a number of poker like combinations. See the table provided below:

Name

Combination

Score

Three-of-a-kind

Three dice with the same face

Sum of all face values on the 5 dice

Four-of-a-kind

Four dice with the same face

Sum of all face values on the 5 dice

Full house

One pair and a three-of-a-kind

25

Small straight

A sequence of four dice

30

Large straight

A sequence of five dice

40

Yahtzee (think five-of-a-kind)

Five dice with the same face

50

Chance

May be used for any sequence of dice; this is the catch all combination

Sum of all face values on the 5 dice

Name

Combination

Score

Three-of-a-kind

Three dice with the same face

Sum of all face values on the 5 dice

Four-of-a-kind

Four dice with the same face

Sum of all face values on the 5 dice

Full house

One pair and a three-of-a-kind

25

Small straight

A sequence of four dice

30

Large straight

A sequence of five dice

40

Yahtzee (think five-of-a-kind)

Five dice with the same face

50

Chance

May be used for any sequence of dice; this is the catch all combination

Sum of all face values on the 5 dice

Explanation / Answer

public void InitializeRandomRoll( int nSeed ) { DateTime aTime = new DateTime(1000); aTime = DateTime.Now; nSeed += (int)(aTime.Millisecond); RandomPick = new Random(nSeed); } private bool m_bHoldState = false; public bool HoldState { get { return m_bHoldState; } set { m_bHoldState = value; } } public void Roll() { // If the dice is not held, roll it if( !HoldState ) { RollNumber = RandomPick.Next(1,7); this.Invalidate(); } } public void DrawDot( Graphics g, Point p ) { SolidBrush myBrush; if( HoldState ) { myBrush = new SolidBrush( Color.Red ); } else { myBrush = new SolidBrush( Color.Black ); } g.FillEllipse( myBrush, p.X, p.Y, dotWidth, dotWidth ); myBrush.Dispose(); } public int AddUpDice( int DieNumber, Dice[] myDice ) { int Sum = 0; for( int i = 0; i < 5; i++ ) { if( myDice[i].RollNumber == DieNumber ) { Sum += DieNumber; } } return Sum; } public int CalculateThreeOfAKind( Dice[] myDice ) { int Sum = 0; bool ThreeOfAKind = false; for( int i = 1; i 2 ) ThreeOfAKind = true; } } if( ThreeOfAKind ) { for( int k = 0; k < 5; k++ ) { Sum += myDice[k].RollNumber; } } return Sum; } public int CalculateFullHouse( Dice[] myDice ) { int Sum = 0; int[] i = new int[5]; i[0] = myDice[0].RollNumber; i[1] = myDice[1].RollNumber; i[2] = myDice[2].RollNumber; i[3] = myDice[3].RollNumber; i[4] = myDice[4].RollNumber; Array.Sort(i); if( (((i[0] == i[1]) && (i[1] == i[2])) && // Three of a Kind (i[3] == i[4]) && // Two of a Kind (i[2] != i[3])) || ((i[0] == i[1]) && // Two of a Kind ((i[2] == i[3]) && (i[3] == i[4])) && // Three of a Kind (i[1] != i[2])) ) { Sum = 25; } return Sum; } public int CalculateLargeStraight( Dice[] myDice ) { int Sum = 0; int[] i = new int[5]; i[0] = myDice[0].RollNumber; i[1] = myDice[1].RollNumber; i[2] = myDice[2].RollNumber; i[3] = myDice[3].RollNumber; i[4] = myDice[4].RollNumber; Array.Sort(i); if( ((i[0] == 1) && (i[1] == 2) && (i[2] == 3) && (i[3] == 4) && (i[4] == 5)) || ((i[0] == 2) && (i[1] == 3) && (i[2] == 4) && (i[3] == 5) && (i[4] == 6)) ) { Sum = 40; } return Sum; } public int CalculateSmallStraight( Dice[] myDice ) { int Sum = 0; int[] i = new int[5]; i[0] = myDice[0].RollNumber; i[1] = myDice[1].RollNumber; i[2] = myDice[2].RollNumber; i[3] = myDice[3].RollNumber; i[4] = myDice[4].RollNumber; Array.Sort(i); // Problem can arise hear, if there is more than one of the same number, so // we must move any doubles to the end for( int j = 0; j < 4; j++ ) { int temp = 0; if( i[j] == i[j+1] ) { temp = i[j]; for( int k = j; k < 4; k++ ) { i[k] = i[k+1]; } i[4] = temp; } } if( ((i[0] == 1) && (i[1] == 2) && (i[2] == 3) && (i[3] == 4)) || ((i[0] == 2) && (i[1] == 3) && (i[2] == 4) && (i[3] == 5)) || ((i[0] == 3) && (i[1] == 4) && (i[2] == 5) && (i[3] == 6)) || ((i[1] == 1) && (i[2] == 2) && (i[3] == 3) && (i[4] == 4)) || ((i[1] == 2) && (i[2] == 3) && (i[3] == 4) && (i[4] == 5)) || ((i[1] == 3) && (i[2] == 4) && (i[3] == 5) && (i[4] == 6)) ) { Sum = 30; } return Sum; } public int CalculateYahtzee( Dice[] myDice ) { int Sum = 0; for( int i = 1; i 4 ) Sum = 50; } } return Sum; } public int AddUpChance( Dice[] myDice ) { int Sum = 0; for( int i = 0; i < 5; i++ ) { Sum += myDice[i].RollNumber; } return Sum; } private int ScoreCount = 0; if( ScoreCount == 14 ) { DialogResult result; // Displays the MessageBox. result = MessageBox.Show( "Your Score is " + TotalScore.Text + ". Would You like to play again?", "End Of Game", MessageBoxButtons.YesNo, MessageBoxIcon.Question ); if( result == DialogResult.Yes ) { // Reset Everything . . . } else { this.Close(); } }