C. Program Description for Developers

Our code starts with the main menu. Which asks the user if they want to play the game.

It then moves into a large while loop that is used to complete the upper section of the Yahtzee scorecard. it loops five times to allow the user to fill all five of the sections. First, we created an array that generates 5 random numbers between 1 and 6 that are then displayed to the user using images of dice that correspond to the randomly generated numbers.

The reroll process first asks if the user wants to reroll any of their dice using input commands. These are asked for all five dice and the user must specify using yes or no as these are assigned to 1 and 0 and the program interprets those with a 1 as ones that need to be replaced. The specified dice are replaced by another randomly generated array using the listed numbers. This process is repeateted once more for the third reroll.

For scoring, we have a prompt that asks the user to select a category for the upper section. This is done by creating an array that is added to every category that the user selects. Before starting over this array is summed up and that added to a new variable before looping up to 5 times.

After looping five times all of the roles from the upper section are totaled and added to a new variable that will be used for the final score.

For the lower section, we used the any function that can determine if a specified condition in an array is true. This is done for all of the categories in the lower section and once the program determines which score will give the user the highest score it prints that result.

The program finally sums the upper section and the lower section and prints the user’s total score.

 

 

 

Variables:

  1. Yes – This equals 1 so the user can answer questions in a yes or no format rather than a 1 or 0
  2. No – This equals 0 so the user can answer questions in a yes or no format rather than a 1 or 0
  3. Menu – Ask the user if they would like to play the game
  4. finishUp – this is for totaling the upper section after all categories have been filled
  5. full – this is used to end the loop of the upper section
  6. role – picks five random numbers between 1 and 6 to roll the dice
  7. reference – this is to copy the roles so we can troubleshoot the program to make sure values are changing correctly
  8. rerole – asks the user if they want to reroll any dice
  9. role2 – picks up to five random numbers between 1 and 6 to roll the dice for the second reroll
  10. NR1 – asks the user if they want to reroll dice 1
  11. NR2 – asks the user if they want to reroll dice 2
  12. NR3 – asks the user if they want to reroll dice 3
  13. NR4 – asks the user if they want to reroll dice 4
  14. NR5 – asks the user if they want to reroll dice 5
  15. role3 – picks up to five random numbers between 1 and 6 to roll the dice for the third reroll
  16. total – sum of the numbers in the reference array
  17. up – this is an array that is used to see what categories dice meet
  18. Aces – This is for scoring the aces category
  19. Twos – This is for scoring the twos category
  20. Threes – This is for scoring the threes category
  21. Fours – This is for scoring the fours category
  22. Fives – This is for scoring the fives category
  23. Sixes – This is for scoring the sixes category
  24. upScore – prompts the user to select one of the listed categories
  25. lowScore – this is the total of the lower sections score
  26. gameScore – this is the overall game score