Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define DICE_SIDES 6
- void print_round(int CurrentRound, int sum);
- int check_sum(int CurrentRound, int *diceRolls, int *allSum);
- void run_game();
- void roll_multiple_dice(int dice, int *diceRolls);
- int prompt_user();
- void print_round(int CurrentRound, int sum) {
- }
- int check_sum(int CurrentRound, int *diceRolls, int *allSum) {
- /* Declare & Initialize Sum Variables */
- int onesSum = 0, twosSum = 0, threesSum = 0, foursSum = 0, fivesSum = 0, sixesSum = 0, bonusSum = 0,
- onepairSum = 0, twopairSum = 0, threekindSum = 0, fourkindSum = 0,smallstraightSum = 0,
- largestraightSum = 0, fullhouseSum = 0, chanceSum = 0, yatzySum = 0;
- /* Declare Dice Sides Array */
- int dicesidesArray[6] = {0};
- /* Declare Iteration Variable */
- int i;
- switch(CurrentRound) {
- case 1:
- for (i = 0; i < sizeof(diceRolls)/sizeof(int); i++) {
- if (diceRolls[i] == 1) {
- onesSum++;
- }
- }
- *allSum += onesSum;
- return onesSum;
- break;
- case 2:
- for (i = 0; i < sizeof(diceRolls)/sizeof(int); i++) {
- if (diceRolls[i] == 2) {
- twosSum++;
- }
- }
- *allSum += twosSum;
- return twosSum;
- break;
- case 3:
- for (i = 0; i < sizeof(diceRolls)/sizeof(int); i++) {
- if (diceRolls[i] == 3) {
- threesSum++;
- }
- }
- *allSum += threesSum;
- return threesSum;
- break;
- case 4:
- for (i = 0; i < sizeof(diceRolls)/sizeof(int); i++) {
- if (diceRolls[i] == 4) {
- foursSum++;
- }
- }
- *allSum += foursSum;
- return foursSum;
- break;
- case 5:
- for (i = 0; i < sizeof(diceRolls)/sizeof(int); i++) {
- if (diceRolls[i] == 5) {
- fivesSum++;
- }
- }
- *allSum += fivesSum;
- return fivesSum;
- break;
- case 6:
- for (i = 0; i < sizeof(diceRolls)/sizeof(int); i++) {
- if (diceRolls[i] == 6) {
- sixesSum++;
- }
- }
- *allSum += sixesSum;
- return sixesSum;
- break;
- case 7:
- if (*allSum > 62) {
- bonusSum = 50;
- *allSum += 50;
- }
- return bonusSum;
- break;
- case 8:
- for (i = 0; i > sizeof(diceRolls)/sizeof(int); i++) {
- if (diceRolls[i] == 1) {
- dicesidesArray[0]++;
- } else if (diceRolls[i] == 2) {
- dicesidesArray[1]++;
- } else if (diceRolls[i] == 3) {
- dicesidesArray[2]++;
- } else if (diceRolls[i] == 4) {
- dicesidesArray[3]++;
- } else if (diceRolls[i] == 5) {
- dicesidesArray[4]++;
- } else if (diceRolls[i] == 6) {
- dicesidesArray[5]++;
- }
- }
- break;
- case 9:
- break;
- case 10:
- break;
- case 11:
- break;
- case 12:
- break;
- case 13:
- break;
- case 14:
- break;
- case 15:
- break;
- case 16:
- break;
- default:
- break;
- }
- }
- void run_game() {
- /* Prompt for number of dice */
- int dice = prompt_user();
- /* Declare Sum Variables (Initialize allSum) */
- int onesSum, twosSum, threesSum, foursSum, fivesSum, sixesSum, bonusSum,
- onepairSum, twopairSum, threekindSum, fourkindSum,smallstraightSum,
- largestraightSum, fullhouseSum, chanceSum, yatzySum, allSum = 0;
- /* Enum round declaration */
- enum round{ones = 1, twos, threes, fours, fives, sixes, bonus, onepair, twopair,
- threekind, fourkind, smallstraight, largestraight, fullhouse, chance, yatzy};
- /* Initialize Round Variable */
- enum round CurrentRound = ones;
- /* Allocate Memory Size to Dynamic Array */
- int *diceRolls = malloc(dice * sizeof(int));
- switch(CurrentRound) {
- case ones:
- roll_multiple_dice(dice, diceRolls);
- onesSum = check_sum(ones, diceRolls, &allSum);
- print_round(CurrentRound, onesSum);
- case twos:
- roll_multiple_dice(dice, diceRolls);
- twosSum = check_sum(twos, diceRolls, &allSum);
- print_round(CurrentRound, twosSum);
- case threes:
- roll_multiple_dice(dice, diceRolls);
- threesSum = check_sum(threes, diceRolls, &allSum);
- print_round(CurrentRound, threesSum);
- case fours:
- roll_multiple_dice(dice, diceRolls);
- foursSum = check_sum(fours, diceRolls, &allSum);
- print_round(CurrentRound, foursSum);
- case fives:
- roll_multiple_dice(dice, diceRolls);
- fivesSum = check_sum(fives, diceRolls, &allSum);
- print_round(CurrentRound, fivesSum);
- case sixes:
- roll_multiple_dice(dice, diceRolls);
- sixesSum = check_sum(sixes, diceRolls, &allSum);
- print_round(CurrentRound, onesSum);
- case bonus:
- roll_multiple_dice(dice, diceRolls);
- bonusSum = check_sum(bonus, diceRolls, &allSum);
- print_round(CurrentRound, bonusSum);
- case onepair:
- roll_multiple_dice(dice, diceRolls);
- onepairSum = check_sum(onepairSum, diceRolls, &allSum);
- print_round(CurrentRound, onepairSum);
- case twopair:
- roll_multiple_dice(dice, diceRolls);
- twopairSum = check_sum(twopair, diceRolls, &allSum);
- print_round(CurrentRound, twopairSum);
- case threekind:
- roll_multiple_dice(dice, diceRolls);
- threekindSum = check_sum(threekind, diceRolls, &allSum);
- print_round(CurrentRound, threekindSum);
- case fourkind:
- roll_multiple_dice(dice, diceRolls);
- fourkindSum = check_sum(fourkind, diceRolls, &allSum);
- print_round(CurrentRound, fourkindSum);
- case smallstraight:
- roll_multiple_dice(dice, diceRolls);
- smallstraightSum = check_sum(smallstraight, diceRolls, &allSum);
- print_round(CurrentRound, smallstraightSum);
- case largestraight:
- roll_multiple_dice(dice, diceRolls);
- largestraightSum = check_sum(largestraight, diceRolls, &allSum);
- print_round(CurrentRound, largestraightSum);
- case fullhouse:
- roll_multiple_dice(dice, diceRolls);
- fullhouseSum = check_sum(fullhouse, diceRolls, &allSum);
- print_round(CurrentRound, fullhouseSum);
- case chance:
- roll_multiple_dice(dice, diceRolls);
- chanceSum = check_sum(chance, diceRolls, &allSum);
- print_round(CurrentRound, chanceSum);
- case yatzy:
- roll_multiple_dice(dice, diceRolls);
- yatzySum = check_sum(yatzy, diceRolls, &allSum);
- print_round(CurrentRound, yatzySum);
- default:
- break;
- }
- }
- int prompt_user() {
- int dice;
- printf("Enter number of Dice: ");
- scanf(" %d", &dice);
- return dice;
- }
- void roll_multiple_dice(int dice, int *diceRolls) {
- int i;
- for (i = 0; i < dice; i++) {
- diceRolls[i] = (rand() % DICE_SIDES) + 1;
- }
- }
- int main() {
- /* Seed Rand */
- srand(time(NULL));
- /* Game Controller */
- run_game();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment