Yahtzee Coding Assignment in C

This assignment requires coding a Yahtzee game in C. The instructions provide step by step guidance and figure examples. To complete this assignment, a previous Yahtzee code is required which will be attached. Ultimately, you will have to change and build on the previous code and make sure the tests run smoothly. I will provide the previous Yahtzee code copied below as I am not able to include the file. Attached I provided the step by step instructions. 

ps: this is in C language 





#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#include <string.h>// constants or macros#define


RULES 1#define

GAME 2#define

EXIT 3#define

ROLLS 3#define

CATEGORIES 13#define

DICE 5#define

ONE 1#define

TWO 2#define

THREE 3#define

FOUR 4#define

FIVE 5#define

SIX 6#define

THREEKIND 7#define

FOURKIND 8#define

FULLHOUSE 9#define

SMSTRAIGHT 10#define L

GSTRAIGHT 11#define

YAHTZEE 12#define

CHANCE 13#define

TURNS 13// function prototypesvoid

gameRules();void

displayExplicitDice();

void clearScreen();

int displayGameMenu();

void displayRandomDice();

int rollDie();

void initializeDice(int dice[]);

void playGame();

void displayDice(int dice[]);

void resetKeep(int keep[]);

void rollDice(int dice[],

              int keep[]);// main functionint

main(){    // while loop control variable

    int play = 1;    // seed the random function

    srand ((unsigned int) time (NULL));    // continue to loop until the player quits or the game ends

    while (play)

    {      switch (displayGameMenu())

        {      case RULES:

                // call function

                gameRules

                gameRules();

                break;

            case GAME:

// call function clearScreen()

                clearScreen();

     displayRandomDice();

                // call function play

            playGame();

            break;

            case EXIT:

            printf ("Thank you for playing!\n");                play = 0;

            break;

            default:

            printf ("Incorrect option, hit enter and try again\n");

            char enter;

            scanf("%c", &enter );

            break;

                

        }

        

    }    // program executed successfully

    return 0;}

// gameRules function displays the Yahtzee and rules of the game

void gameRules (){printf ("\t\t\t\tLET'S PLAY YAHTZEE!!! \n\n");

    printf ("RULES OF THE GAME:\n");

    printf ("\t1. The scorecard used for Yahtzee is composed of an upper section and a lower section.\n");

    printf ("\t2. A total of 13 scoring combinations are divided amongst the sections. \n");

    printf ("\t3. The upper section consists of boxes that are scored by summing the value of the dice matching the faces of the box.\n");

    printf ("\t4. 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. \n");

    printf ("\t5. 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.\n");

    printf ("\t6. If the sum of the scores in the upper section is greater than or equal to 63, then 35 more points are added \n");

    printf ("\tto the players overall score as a bonus. The lower section contains a number of poker like combinations.\n");}// function displayExplicitDice displays a hardcoded version of a rolled dice


void displayExplicitDice()


{

    printf("|---------------------------------------|\n");

    printf("|       |       |       |       |       |\n");

    printf("|   1   |   2   |   3   |   4   |   5   |\n");

    printf("|       |       |       |       |       |\n");

    printf("|---------------------------------------|\n");

    

}

// function displayRandomDice displays a randomly generated dice for three rolls

void displayRandomDice()

{

    // looping variable

    int roll;

    int die1;

    int die2;

    int die3;

    int die4;

    int die5;

    for(roll = 0; roll < ROLLS; roll++)

    {

        die1 = rollDie();

        die2 = rollDie();

        die3 = rollDie();

        die4 = rollDie();

        die5 = rollDie();

        printf("|---------------------------------------|\n");

        printf("|       |       |       |       |       |\n");

        printf("|   %d   |   %d   |   %d   |   %d   |   %d   |\n", die1, die2, die3, die4, die5);

        printf("|       |       |       |       |       |\n");

        printf("|---------------------------------------|\n");

        

    }

    

}


//clears the screen

void clearScreen()

{

    printf("\n\t\t\t\tHit <ENTER> to continue!\n");

    char enter;

    scanf("%c", &enter );

    // send the clear screen command Windows

    // system("cls");

    system("clear");

    

}

// presents a menu to the playerint

displayGameMenu()

{

    int select = 0;

    do

    {

        printf ("\n\n\t\t\t\tLET'S PLAY YAHTZEE!!! \n\n");

        printf ("%d. Display Game Rules\n", RULES);

        printf ("%d. Start a game of Yahtzee\n", GAME);

        printf ("%d. Exit\n", EXIT);

        scanf ("%d", &select);

        

    }

    while ((select < RULES) && (select > EXIT));

    return select;

    

}

// randomly rolls a die

int rollDie(){

int dieValue = 0;

    dieValue = rand () % 6 + 1;

    return dieValue;}

void initializeDice(int dice[DICE])

{

    int die;

    for(die = 0; die < DICE; die++)

    {

        dice[die] = 0;

        

    }

    

}

void playGame()

{    int roll;

    int turn;

    int dice[DICE];

    int keep[DICE];

    // continue to loop until game is over

    for(turn = 0; turn < TURNS; turn++)

    {

        int current = turn + 1;

        printf("Turn %d of game\n\n", current);

        // for each turn reset the keep[] and dice arrays

        initializeDice(dice);

        // one turn

        for(roll = 0; roll < ROLLS; roll++)

        {

            resetKeep(keep);

            printf("Rolling the dice...\n");

            rollDice(dice, keep);

            displayDice(dice);

            

        }

        

    }

    

}

void displayDice(int dice[DICE])

{

    int die;

    char enter;

    printf("+-------+ +-------+ +-------+ +-------+ +-------+\n");

    printf("|       | |       | |       | |       | |       |\n");

    for(die = 0; die < DICE; die++)

    {

    printf("|   %d   | ", dice[die]);    }

    printf("\n");    printf("|       | |       | |       | |       | |       |\n");

    printf("+-------+ +-------+ +-------+ +-------+ +-------+\n");

    scanf ("%c", &enter);

    

}

void resetKeep(int keep[DICE])

{    int die;

    // loop through the five dice

    for(die = 0; die < DICE; die++)

    {

        // set each die to 0 meaning false

        keep[die] = 0;    }

    

}

void rollDice(int dice[DICE],

              int keep[DICE])

{

    int die;

    // loop through the five dice

    for(die = 0; die < DICE; die++)

    {

        // only roll dice that have not been selected to keep

        if(keep[die] == 0)

        {            dice[die] = rollDie();

            

        }

        

    }

    

}

Get Help With a similar task to - Yahtzee Coding Assignment in C

Login to view and/or buy answers.. or post an answer
Additional Instructions:

University of Central Florida COP 3223 Into to Programming in C 4 Assignment 4 Due, Wednesday, July 8, 2020 for maximum 100 Thursday, July 9, 2020 for maximum 90 Friday, July 10, 2020 for maximum 80 Saturday, July 11, 2020 for maximum 70 Deliverables  To complete this assignment you must submit your yahtzee4.c to Webcourses. Project description This project will require students to randomly roll a set of five Yahtzee dice, allow the player to select dice to reroll up to two times, and select the category to score the dice. Students will have to work through a series of programming implementations to complete the project. The project will include the use of primitive data type variables, arrays, user defined functions, and functions from the C library. Assignment Naming Convention It is highly recommended that for each iteration of the project students copy the previous assignment and rename it for additional functionality. The purpose of this implementation is two-fold. First, if there is a grading discrepancy, students have evidence that their source code worked as designed respective to what the grading rubric required. Second, the current implementation of Webcourses automatically renames a student’s assignment submission. The first submission would be “yahtzee.c”, the second submission automatically gets renamed to “yahtzee-1.c”, the third submission automatically gets renamed to “yahtzee-2.c”, etc… and causes concern for students. Assignment Scope 1. Create a C source code file 2. Declare global constants/macros 3. Add new functions 4. Add new function prototypes 5. Use arrays locally 6. Pass arrays to functions as arguments 7. For loops 8. Nested for loops 9. While loops 10. Nested while loops 11. Enumerations 12. Two-dimensional arrays 13. Pointers 14. String tokenizer 15. Function fgets 16. Compile and run a file 17. Submit to Webcourses References Source code examples in Webcourses 1. constants.c 2. decisionMaking.c 3. looping.c 4. operators.c 5. functions.c 6. random.c 7. arrays.c 8. preVersusPostIncrement.c 9. enumerations.c 10. pointers.c 11. strings.c 12. inputOutput.c Tasks Activity yahtzee.c 1. Copy C source code file yahtzee3.c as yahtzee4.c 1. Write preprocessor command to include library string.h 2. Define global constants or macros for the following a. COLS as value 2 b. COL as value 1 c. ZERO as value 0 3. Declare an enumeration named scores with values a. one b. two c. three d. four e. five f. six g. threekind h. fourkind i. fullhouse j. smstraight k. lgstraight l. yahtzee m. chance 4. Write the function declaration or prototype for function initializeScores (hint: it is the same function signature of the function with a semi-colon at the end) 5. Write the function declaration or prototype for function selectCategory 6. Write the function declaration or prototype for function selectDice 7. Write the function declaration or prototype for function updateScores 8. Write the function declaration or prototype for function displayScoreCard 9. Write the function declaration or prototype for function displayUpperSection 10. Write the function declaration or prototype for function displayLowerSection 11. Update function playGame to do the following a. Declare two-dimensional array scoreCard, size thirteen by two, use constants for sizes, data type int to store the scores b. Declare variable category, data type int to store user’s selected category for scoring dice c. Before the outer for loop, call function initializeScores passing 2d array scorecard as an argument d. Move function call resetKeep to before the inner for loop versus inside the for loop e. After function call displayDice write an if statement checking if the current roll is less than two, use a constant, if true, do the following i. Call function selectDice passing as arguments arrays dice and keep f. After the inner for loop for rolling but still inside the outer for loop for number of turns do the following i. Set variable category equal to function call selectCategory ii. Call function updateScores passing arguments 2d array scorecard and variable category iii. Call function displayScoreCard passing argument 2d array scorecard 12. Update function displayDice to comment out the function call to scanf 13. Write the function initializeScores to do the following a. Return type void b. Parameter list includes i. int 2d array named scorecard with size of thirteen by two, be sure to use the constants c. Declare variable row, data type int, for a looping variable d. Declare variable col, data type int, for a looping variable e. Write a nested for loop that does the following i. Outer for loop starts at value zero, loops thirteen times ii. Inner for loop starts at value zero, loops two times iii. Write an if statement to check if the value of the inner looping variable is zero (i.e. first column) 1. if true, set the value of the current element in the 2d array equal to the outer for loop variable 2. else, set the value of the current element in the 2d array equal to zero 14. Write the function selectCategory to do the following a. Return type int b. Empty parameter list c. Declare variable select, data type int, for a storing user selection d. Write a series of printf statements to display the user’s options similar to figure 5 e. Call function scanf store the user’s selection in variable select f. Return variable select 15. Write the function selectDice to do the following a. Return type void b. Parameter list includes i. int array named dice with size of five, be sure to use the constant DICE ii. int array named keep with size of five, be sure to use the constant DICE c. Declare variables i. die, data type int, initialized to zero ii. data, data type array of char, size ten iii. value, data type char pointer iv. valid, data type int, initialize to zero as a looping control variable d. Call function resetKeep passing parameter keep as an argument e. Write a printf statement to prompt the user to select dice to keep, similar to figure 3 f. Call function fgets to store the user’s input into char array data g. Set pointer value equal to function call strtok passing as arguments char array data and an explicit space as the delimiter h. Write a while loop to continue looping based on the condition that variable value is not equal to null i. Set variable valid equal to zero ii. Write a nested while loop to continue looping based on the condition that variable valid is false 1. Write a switch condition evaluating pointer value (don’t forget to dereference the pointer!), the case labels should be evaluated based on a character (not integer) 1, 2, 3, 4, 5; for each case label do the following a. Display to the screen which die the user selected to keep similar to figure 4 b. Set the associated element in the array keep to the value of 1 to indicate true c. Set variable valid to the value of 1 to indicate true d. Be sure to include a default case for invalid data iii. After the inner while loop but still inside the outer while loop call function strtok passing arguments NULL and an explicit space 16. Write function updateScore to do the following a. Return type void b. Parameter list includes i. int 2d array scorecard, sized thirteen by two ii. int variable category c. Write a switch conditional to evaluate parameter category, case labels should compare to constants/macros defined for each category; each case label should do the following i. Write a printf statement to inform the user which category is being scored, reference figure 7 for suggested output 17. Write function displayScoreCard to do the following a. Return type void i. Parameter list includes int 2d array scoreCard, sized thirteen by two b. Calls function printf to display the first line of the output, see figure 8 c. Calls function displayUpperSection, passing as an argument parameter scorecard d. Calls function displayLowerSection, passing as an argument parameter scorecard e. Calls a series of printf functions to display the last two total rows of the score card, see figure 9 18. Write function displayUpperSection to do the following a. Return type void i. Parameter list includes int 2d array scoreCard, sized thirteen by two b. Call a series of printf functions to display the scores stored in parameter scoreCard, see figure 10, use the enumeration members to reference each row of the 2d array and constant/macro COL for the column of the array 19. Write function displayLowerSection to do the following a. Return type void i. Parameter list includes int 2d array scoreCard, sized thirteen by two b. Call a series of printf functions to display the scores stored in parameter scoreCard, see figure 11, use the enumeration members to reference each row of the 2d array and constant/macro COL for the column of the array Yahtzee executable Test Case 1 Test Case 1 passes Test Case 2 Test Case 2 passes Test Case 3 Test Case 3 passes Test Case 4 Test Case 4 passes Test Case 5 Test Case 5 passes Test Case 6 Test Case 6 passes Test Case 7 Test Case 7 passes Test Case 8 Test Case 8 passes Source compiles with no errors Source runs with no errors Source includes comments Perform the following test cases Test Cases Action Expected outcome Test Case 1 Run executable Regression testing; when the executable runs, the output in the command prompt should look like Figure 1 Game menu function output Test Case 2 User enters value 1 Regression testing; the output in the command prompt should look like Figure 2 Rules function output Test Case 3 User enters value 2 The output in the command prompt should look similar Figure 3 Prompt user to select dice to keep Test Case 4 Roll 1, User hits the <Enter> key The output in the command prompt should look similar Figure 4 User selected dice are displayed to screen Test Case 5 Roll 2, User hits the <Enter> key The second roll should ONLY change values for dice that were NOT selected. The output in the command prompt should look similar Figure 5 Unselected dice are rerolled Test Case 6 Roll 3, User hits the <Enter> key The third roll should ONLY change values for dice that were NOT selected. The output in the command prompt should look similar Figure 5 Unselected dice are rerolled Test Case 7 User enters an integer to indicate which category to score their dice The output in the command prompt should look similar to Figure 7 Output in function updateScores The user’s score card should display to the command prompt and be similar to Figure 12 Score card Test Case 8 User enters value 3 at the main menu Regression testing; the output in the command prompt should look similar to Figure 13 Exit selection output Figure 1 Game menu function output Figure 2 Game rules screen function output Figure 3 Prompt user to select dice to keep in function keepDice Figure 4 User selected dice are displayed to screen Figure 5 Unselected dice are rerolled Figure 6 Function select category output Figure 7 Output in function updateScores Figure 8 Display first line of scorecard Figure 9 Display last two sections of scorecard Figure 10 Display upper section of scorecard Figure 11 Display lower section of scorecard Figure 12 Score card Figure 13 Exit selection output

Related Questions

Similar orders to Yahtzee Coding Assignment in C
12
Views
0
Answers
Final Arduino Project MIAE 215
Please follow all of the instructions for the final project (MIAE 215 Arduino Project) that are posted in the uploaded files. To complete the Final Arduino project you will have to also do some parts of Assignment 3 which has also been uploaded...
15
Views
0
Answers
C program with graphing and such
Hello! I am in dire need of help, please pm me if you can help me on my C programming assignment and let me know . Thank you so much!!!!!!!!!!!!!!!!!!!!!!!...
14
Views
0
Answers
encrypting and decrypting a text
encrypt and decrypt a text using many tools and formulas given. other codes have been provided too. a skeleton code is provided. a lot of reading is involved to understand project...
88
Views
0
Answers
Two C++ Tasks, using set and get, class and member function
1.) Modify class Account, to provide a member function called withdraw, which can make withdraws without over drafting account. If there is not an available amount in the account for withdrawal, return statement "withdraw amount exceeded account balance". ...