Please help writing the following game in C and describe steps taken . Thank you
ID: 3728087 • Letter: P
Question
Please help writing the following game in C and describe steps taken . Thank you
Develop and implement an interactive two-player Yahtzee game. Yahtzee is a dice game that was invented by Milton Bradley and Edwin S. Lowe in 1956. The challenge of the game is to outduel the other player by scoring the most points. Points are obtained by rolling five 6-sided die across thirteen rounds. During each round, each player may roll the dice up to three times to make one of the possible scoring combinations. Once a combination has been achieved by the player, it may not be used again in future rounds, except for the Yahtzee combination may be used as many times as the player makes the combination. Each scoring combination has different point totals. Some of these totals are achieved through the accumulation of points across rolls and some are obtained as fixed sequences of values 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. Ifa player rolls four3'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 ree-of-a- Four-of-a-kind Full house Small straight Large straight Yahtzee (think five-of-a-kind) Chance Combination Three dice with the same face Four dice with the same face One pair and a three-of-a-kind A sequence of four dice A sequence of five dice Score Sum of all face values on the 5 dice Sum of all face values on the 5 dice 25 30 40 Five dice with the same face 50 May be used for any sequence of dice Sum of all face values on the 5 dice this is the catch all combination For this assignment you are required to define, at a minimum, the some similar functions to the provided below: void startNewGame (void) void setupGameBoard (void)i void rol!Dices (Dices dices) ; void chooseDiceToHold (Dices myDices) ; void printMessageBox (Message myMessage) void updateScoreBoard (ScoreBoard myScoreBoard, int category, int score) void computeCategoryScore (Dices myDices, int category, int score) void chooseCategory (Category myCategory)i void printGameRules (void) void printGoodbye (void) int chooseMenuItem (void); void printMainScreen (void);Explanation / Answer
Code
main.c
#include "function.h"
int main (void)
{
int choice = 1, die1 = 0, die2 = 0, die3 = 0, die4 = 0, die5 = 0, die_value = 0, press = 0, roll = 0, count = 0, combination = 0, menu = 0, number = 0;
char yes = '', no = '';
int two = 0, three = 0, four = 0, five = 0, six = 0
srand ((unsigned int) time (NULL));
while (choice)
{
switch (game_menu())
{
case RULES:
game_rules ();
system("PAUSE");
break;
case GAME:
run_game (die1, die2, die3, die4, die5);
break;
case EXIT:
printf ("Goodbye. ");
choice = 0;
break;
default:
printf ("Illegal option. ");
break;
}
return 0;
}
}
Function.h
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define RULES 1
#define GAME 2
#define EXIT 3
#define ONE 4
#define NOT_ONE 0
#define TWO 5
#define NOT_TWO 0
#define THREE 6
#define NOT_THREE 0
#define FOUR 7
#define NOT_FOUR 0
#define FIVE 8
#define NOT_FIVE 0
#define SIX 9
#define NOT_SIX 0
#define THREE_KIND 10
#define NOT_THREE_KIND 0
#define FOUR_KIND 11
#define NOT_FOUR_KIND 0
#define SMALL 12
#define NOT_SMALL 0
#define LARGE 13
#define NOT_LARGE 0
#define FULL 14
#define NOT_FULL 0
#define CHANCE 15
#define NOT_CHANCE 0
#define YAHTZEE 16
#define NOT_YAHTZEE 0
int game_menu (void);
void game_rules (void);
int roll_die (void);
int run_game (int die1, int die2, int die3, int die4, int die5);
int get_sum_one (int die1, int die2, int die3, int die4, int die5);
int get_sum_two (int die1, int die2, int die3, int die4, int die5);
int get_sum_three (int die1, int die2, int die3, int die4, int die5);
int get_sum_four (int die1, int die2, int die3, int die4, int die5);
int get_sum_five (int die1, int die2, int die3, int die4, int die5);
int get_sum_six (int die1, int die2, int die3, int die4, int die5);
int calculate_three_kind (int die1, int die2, int die3, int die4, int die5);
int get_four_of_a_kind (int die1, int die2, int die3, int die4, int die5);
int get_small_straight (int die1, int die2, int die3, int die4, int die5);
int get_large_straight (int die1, int die2, int die3, int die4, int die5);
int get_full_house (int die1, int die2, int die3, int die4, int die5);
int get_chance (int die1, int die2, int die3, int die4, int die5);
int get_yahtzee (int die1, int die2, int die3, int die4, int die5);
int choose_combination (int yahtzee, int chance, int full_house, int large_straight, int small_straight, int four_of_a_kind, int three_of_a_kind, int sum_one, int sum_two, int sum_three, int sum_four, int sum_five, int sum_six);
Function.c
#include "function.h"
int game_menu (void)
{
int choose = 0;
do {
system ("cls");
printf ("Yahtzee ");
printf ("%d. Print Game Rules. ", RULES);
printf ("%d. Start a game of Yahtzee. ", GAME);
printf ("%d. Exit ", EXIT);
scanf ("%d", &choose);
} while ((choose < RULES) && (choose > EXIT));
return choose;
}
void game_rules (void)
{
printf ("The scorecard used for Yahtzee is composed of two sections. A upper section and a lower section. ");
printf ("A total of thirteen boxes or thirteen scoring combinations are divided amongst the sections. ");
printf ("The upper section consists of boxes that are scored by summing the value of the dice matching the faces of the box. ");
printf ("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. ");
printf ("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. ");
printf ("If the sum of the scores in the upper section is greater than or equal to 63, then 35 more points are added ");
printf ("to the players overall score as a bonus. The lower section contains a number of poker like combinations. ");
}
int roll_die (void)
{
int die_value = 0;
die_value = rand () % 6 + 1;
return die_value;
}
int run_game (int die1, int die2, int die3, int die4, int die5)
{
int press = 0, roll = 0, number = 0, game = 0;
char yes = '', no = '';
do
{
printf (" Press any key in order to role the dice!!");
scanf ("%d", &press);
die1 = roll_die (1);
printf ("Die 1: %d ",die1);
die2 = roll_die (2);
printf ("Die 2: %d ",die2);
die3 = roll_die (3);
printf ("Die 3: %d ",die3);
die4 = roll_die (4);
printf ("Die 4: %d ",die4);
die5 = roll_die (5);
printf ("Die 5: %d ",die5);
roll++;
}while (press != press);
printf ("That is roll number %d ", roll);
while (roll < 3)
{
printf ("Would you like to use this role for a game combination?(press Y for yes or N for no) ");
scanf (" %c %c", &yes,& no);
if ((yes == 'y')||(yes == 'Y'))
{
printf("What combination would you like to use? ");
printf("(Press the number of the combination you would like to use.) ");
printf("%d. Sum of 1's. ", ONE);
printf("%d. Sum of 2's. ", TWO);
printf("%d. Sum of 3's. ", THREE);
printf("%d. Sum of 4's. ", FOUR);
printf("%d. Sum of 5's. ", FIVE);
printf("%d. Sum of 6's. ", SIX);
printf("%d. Three of a Kind. ", THREE_KIND);
printf("%d. Four of a Kind. ", FOUR_KIND);
printf("%d. Full House. ", FULL);
printf("%d. Small Straight. ", SMALL);
printf("%d. Large Straight. ", LARGE);
printf("%d. Yahtzee. ", YAHTZEE);
printf("%d. Chance ", CHANCE);
scanf("%d", &number);
}
else if ((no == 'n')||(no == 'N'))
{
printf("Would you like to keep any of the dice you just rolled? (press Y for yes and N for no) ");
scanf(" %c %c", &yes, &no);
if ((yes == 'y')||(yes == 'Y'))
{
printf ("Please enter the die number you would like to save.");
}
else
{
return 0;
}
}
}
while (roll == 3)
{
printf ("What combination would you like to use?");
printf("What combination would you like to use? ");
printf("(Press the number of the combination you would like to use.) ");
printf("%d. Sum of 1's. ", ONE);
printf("%d. Sum of 2's. ", TWO);
printf("%d. Sum of 3's. ", THREE);
printf("%d. Sum of 4's. ", FOUR);
printf("%d. Sum of 5's. ", FIVE);
printf("%d. Sum of 6's. ", SIX);
printf("%d. Three of a Kind. ", THREE_KIND);
printf("%d. Four of a Kind. ", FOUR_KIND);
printf("%d. Full House. ", FULL);
printf("%d. Small Straight. ", SMALL);
printf("%d. Large Straight. ", LARGE);
printf("%d. Yahtzee. ", YAHTZEE);
printf("%d. Chance ", CHANCE);
scanf("%d", &number);
}
}
If any queries please get back to me
Thank you