Question: #include #include #include dicegame.h int main ( ) { srand ( time ( NULL ) ) ; / / Initialize the srand ( )
#include
#include
#include "dicegame.h
int main
srandtimeNULL; Initialize the srand to start the random generator
int p p; Initialize the player and player points to
int rounds; Initialize all other required variables
printfEnter the number of rounds: ;
scanfd &rounds; scanf the user for the number of rounds to run the game
Call printPlayerPoints function to print the initial player points which will be
Determine the starting player randomly
Set up the loop to go through all the rounds one at a time
for
Call the corresponding functions to get the information for this round type, dice, points
Print round number
Print current player
Call printRoundInfo to print the round information
MAIN GAME LOGIC
Write code here to get the main game logic using branches
Success: Playerodd player is the current player and the dice rolled is odd
OR Playereven player is the current player and the dice rolled is even.
Current player gains the points, based on the type of the round see above The current players turn continues in the next round.
Failure: Playerodd player is the current player and the dice rolled is even
OR Playereven player is the current player and the dice rolled is odd.
Current player incurs penalty of the same number of points, based on the type of the round see above In the next round, the current player is changed to the other player.
Call printPlayerPoints to print the player information at the end of the round
printf
Game Over!
;
Compare the final points for player and player
Print the winner as the one with higher points
Return from the main function to end the program successfully
return ;
Game Rules:
The user selects the number of rounds to be run. Each dice round consists of values:
o Dice value of the dice rolled. It is a random number between
o Points value associated with the round. It is a random number from in multiples of random number between
o Type the type of the round. There are types of rounds:
REGULAR keep the points equal to the number of points as calculated above using a random number generator.
BONUS replace points to be equal to
DOUBLE update points to be equal to DOUBLE the number of points as calculated above using a random number generator.
Probability of the round types:
for BONUS, for DOUBLE and for REGULAR
The game consists of two players & The game starts with one player at random.
For each round, one of the following cases can occur:
o Success: Playerodd player is the current player and the dice rolled is odd
OR Playereven player is the current player and the dice rolled is even.
Current player gains the points, based on the type of the round see above The current players turn continues in the next round.
o Failure: Playerodd player is the current player and the dice rolled is even
OR Playereven player is the current player and the dice rolled is odd.
Current player incurs penalty of the same number of points, based on the type of the round see above In the next round, the current player is changed to the other player.
At the end of all rounds, the player with the highest points wins the game.
Task : Complete the main.c
Download the attached main.c
Follow the instructions written in the comments in the main function. The main is the driver of the program. It calls the functions below to play the game.
Task create and write dicegame.h
Include the header guard in the correct format.
Create an enum named ROUNDTYPE to identify the three round types:
o BONUS, DOUBLE, REGULAR
Write all the function prototypes see Task below.
Task create and write dicegame.c
Write the following functions that uses the game rules described above:
int getRandomNumber int min, int max This function computes a random number between min and max, inclusive, and returns it
ROUNDTYPE getRoundType This function decides the type of the round based on the probability values mentioned in game rules for BONUS, for DOUBLE and for REGULAR HINT: Use the getRandomNumber function to generate a random number between through and use this value for probability.
int getRoundPoints ROUNDTYPE roundType This function calculates and return the points associated with the given round type, based on the rules mentioned above. You will need to call the getRandomNumber function to generate the points randomly.
void printPlayerPoints int p int p
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
