Guest User

Untitled

a guest
Nov 15th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define DICE_SIDES 6
  5.  
  6. void print_round(int CurrentRound, int sum);
  7. int check_sum(int CurrentRound, int *diceRolls, int *allSum);
  8. void run_game();
  9. void roll_multiple_dice(int dice, int *diceRolls);
  10. int prompt_user();
  11.  
  12. void print_round(int CurrentRound, int sum) {
  13.  
  14. }
  15.  
  16. int check_sum(int CurrentRound, int *diceRolls, int *allSum) {
  17.     /* Declare & Initialize Sum Variables */
  18.     int onesSum = 0, twosSum = 0, threesSum = 0, foursSum = 0, fivesSum = 0, sixesSum = 0, bonusSum = 0,
  19.         onepairSum = 0, twopairSum = 0, threekindSum = 0, fourkindSum = 0,smallstraightSum = 0,
  20.         largestraightSum = 0, fullhouseSum = 0, chanceSum = 0, yatzySum = 0;
  21.  
  22.     /* Declare Dice Sides Array */
  23.     int dicesidesArray[6] = {0};
  24.  
  25.     /* Declare Iteration Variable */
  26.     int i;
  27.  
  28.     switch(CurrentRound) {
  29.         case 1:
  30.         for (i = 0; i < sizeof(diceRolls)/sizeof(int); i++) {
  31.             if (diceRolls[i] == 1) {
  32.                 onesSum++;
  33.             }
  34.         }
  35.  
  36.         *allSum += onesSum;
  37.         return onesSum;
  38.         break;
  39.  
  40.         case 2:
  41.         for (i = 0; i < sizeof(diceRolls)/sizeof(int); i++) {
  42.             if (diceRolls[i] == 2) {
  43.                 twosSum++;
  44.             }
  45.         }
  46.  
  47.         *allSum += twosSum;
  48.         return twosSum;
  49.         break;
  50.  
  51.         case 3:
  52.         for (i = 0; i < sizeof(diceRolls)/sizeof(int); i++) {
  53.             if (diceRolls[i] == 3) {
  54.                 threesSum++;
  55.             }
  56.         }
  57.  
  58.         *allSum += threesSum;
  59.         return threesSum;
  60.         break;
  61.  
  62.         case 4:
  63.         for (i = 0; i < sizeof(diceRolls)/sizeof(int); i++) {
  64.             if (diceRolls[i] == 4) {
  65.                 foursSum++;
  66.             }
  67.         }
  68.  
  69.         *allSum += foursSum;
  70.         return foursSum;
  71.         break;
  72.  
  73.         case 5:
  74.         for (i = 0; i < sizeof(diceRolls)/sizeof(int); i++) {
  75.             if (diceRolls[i] == 5) {
  76.                 fivesSum++;
  77.             }
  78.         }
  79.  
  80.         *allSum += fivesSum;
  81.         return fivesSum;
  82.         break;
  83.  
  84.         case 6:
  85.         for (i = 0; i < sizeof(diceRolls)/sizeof(int); i++) {
  86.             if (diceRolls[i] == 6) {
  87.                 sixesSum++;
  88.             }
  89.         }
  90.  
  91.         *allSum += sixesSum;
  92.         return sixesSum;
  93.         break;
  94.  
  95.         case 7:
  96.         if (*allSum > 62) {
  97.             bonusSum = 50;
  98.             *allSum += 50;
  99.         }
  100.         return bonusSum;
  101.         break;
  102.  
  103.         case 8:
  104.        
  105.         for (i = 0; i > sizeof(diceRolls)/sizeof(int); i++) {
  106.             if (diceRolls[i] == 1) {
  107.                 dicesidesArray[0]++;
  108.             } else if (diceRolls[i] == 2) {
  109.                 dicesidesArray[1]++;
  110.             } else if (diceRolls[i] == 3) {
  111.                 dicesidesArray[2]++;
  112.             } else if (diceRolls[i] == 4) {
  113.                 dicesidesArray[3]++;
  114.             } else if (diceRolls[i] == 5) {
  115.                 dicesidesArray[4]++;
  116.             } else if (diceRolls[i] == 6) {
  117.                 dicesidesArray[5]++;
  118.             }
  119.         }
  120.  
  121.         break;
  122.  
  123.         case 9:
  124.  
  125.         break;
  126.  
  127.         case 10:
  128.  
  129.         break;
  130.  
  131.         case 11:
  132.  
  133.         break;
  134.  
  135.         case 12:
  136.  
  137.         break;
  138.  
  139.         case 13:
  140.  
  141.         break;
  142.  
  143.         case 14:
  144.  
  145.         break;
  146.  
  147.         case 15:
  148.  
  149.         break;
  150.  
  151.         case 16:
  152.  
  153.         break;
  154.  
  155.         default:
  156.  
  157.         break;
  158.     }
  159. }
  160.  
  161. void run_game() {
  162.     /* Prompt for number of dice */
  163.     int dice = prompt_user();
  164.  
  165.     /* Declare Sum Variables (Initialize allSum) */
  166.     int onesSum, twosSum, threesSum, foursSum, fivesSum, sixesSum, bonusSum,
  167.         onepairSum, twopairSum, threekindSum, fourkindSum,smallstraightSum,
  168.         largestraightSum, fullhouseSum, chanceSum, yatzySum, allSum = 0;
  169.  
  170.     /* Enum round declaration */
  171.     enum round{ones = 1, twos, threes, fours, fives, sixes, bonus, onepair, twopair,
  172.     threekind, fourkind, smallstraight, largestraight, fullhouse, chance, yatzy};
  173.  
  174.     /* Initialize Round Variable */
  175.     enum round CurrentRound = ones;
  176.  
  177.     /* Allocate Memory Size to Dynamic Array */
  178.     int *diceRolls = malloc(dice * sizeof(int));
  179.  
  180.     switch(CurrentRound) {
  181.         case ones:
  182.         roll_multiple_dice(dice, diceRolls);
  183.         onesSum = check_sum(ones, diceRolls, &allSum);
  184.         print_round(CurrentRound, onesSum);
  185.  
  186.         case twos:
  187.         roll_multiple_dice(dice, diceRolls);
  188.         twosSum = check_sum(twos, diceRolls, &allSum);
  189.         print_round(CurrentRound, twosSum);
  190.  
  191.         case threes:
  192.         roll_multiple_dice(dice, diceRolls);
  193.         threesSum = check_sum(threes, diceRolls, &allSum);
  194.         print_round(CurrentRound, threesSum);
  195.  
  196.         case fours:
  197.         roll_multiple_dice(dice, diceRolls);
  198.         foursSum = check_sum(fours, diceRolls, &allSum);
  199.         print_round(CurrentRound, foursSum);
  200.  
  201.         case fives:
  202.         roll_multiple_dice(dice, diceRolls);
  203.         fivesSum = check_sum(fives, diceRolls, &allSum);
  204.         print_round(CurrentRound, fivesSum);
  205.  
  206.         case sixes:
  207.         roll_multiple_dice(dice, diceRolls);
  208.         sixesSum = check_sum(sixes, diceRolls, &allSum);
  209.         print_round(CurrentRound, onesSum);
  210.  
  211.         case bonus:
  212.         roll_multiple_dice(dice, diceRolls);
  213.         bonusSum = check_sum(bonus, diceRolls, &allSum);
  214.         print_round(CurrentRound, bonusSum);
  215.  
  216.         case onepair:
  217.         roll_multiple_dice(dice, diceRolls);
  218.         onepairSum = check_sum(onepairSum, diceRolls, &allSum);
  219.         print_round(CurrentRound, onepairSum);
  220.  
  221.         case twopair:
  222.         roll_multiple_dice(dice, diceRolls);
  223.         twopairSum = check_sum(twopair, diceRolls, &allSum);
  224.         print_round(CurrentRound, twopairSum);
  225.  
  226.         case threekind:
  227.         roll_multiple_dice(dice, diceRolls);
  228.         threekindSum = check_sum(threekind, diceRolls, &allSum);
  229.         print_round(CurrentRound, threekindSum);
  230.  
  231.         case fourkind:
  232.         roll_multiple_dice(dice, diceRolls);
  233.         fourkindSum = check_sum(fourkind, diceRolls, &allSum);
  234.         print_round(CurrentRound, fourkindSum);
  235.  
  236.         case smallstraight:
  237.         roll_multiple_dice(dice, diceRolls);
  238.         smallstraightSum = check_sum(smallstraight, diceRolls, &allSum);
  239.         print_round(CurrentRound, smallstraightSum);
  240.  
  241.         case largestraight:
  242.         roll_multiple_dice(dice, diceRolls);
  243.         largestraightSum = check_sum(largestraight, diceRolls, &allSum);
  244.         print_round(CurrentRound, largestraightSum);
  245.  
  246.         case fullhouse:
  247.         roll_multiple_dice(dice, diceRolls);
  248.         fullhouseSum = check_sum(fullhouse, diceRolls, &allSum);
  249.         print_round(CurrentRound, fullhouseSum);
  250.  
  251.         case chance:
  252.         roll_multiple_dice(dice, diceRolls);
  253.         chanceSum = check_sum(chance, diceRolls, &allSum);
  254.         print_round(CurrentRound, chanceSum);
  255.  
  256.         case yatzy:
  257.         roll_multiple_dice(dice, diceRolls);
  258.         yatzySum = check_sum(yatzy, diceRolls, &allSum);
  259.         print_round(CurrentRound, yatzySum);
  260.  
  261.         default:
  262.  
  263.         break;
  264.     }
  265. }
  266.  
  267. int prompt_user() {
  268.     int dice;
  269.     printf("Enter number of Dice: ");
  270.     scanf(" %d", &dice);
  271.     return dice;
  272. }
  273.  
  274. void roll_multiple_dice(int dice, int *diceRolls) {
  275.     int i;
  276.     for (i = 0; i < dice; i++) {
  277.        diceRolls[i] = (rand() % DICE_SIDES) + 1;
  278.     }
  279. }
  280.  
  281. int main() {
  282.     /* Seed Rand */
  283.     srand(time(NULL));
  284.  
  285.     /* Game Controller */
  286.     run_game();
  287.  
  288.     return 0;
  289. }
Advertisement
Add Comment
Please, Sign In to add comment