Commit 83bc981e authored by Chris's avatar Chris
Browse files

some small refactor changes

parent 737dcd55
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
#include "graphics.h"
#include "utils.h"

const int NUM_DICE = 5;
const unsigned int NUM_DICE = 5;
const int SCORE_UNSCORED = -1;

void roll_and_print(game_context *ctx, unsigned int *out_dice_values, unsigned int animation_seconds) {
@@ -70,7 +70,7 @@ void clear_held_values(game_context *ctx) {

unsigned int calculate_score(struct scorecard_st *scorecard, char *scoring_selection) {
    // discern score action based on the scoring selection

    return 0;
}

void initialize_scorecard(struct scorecard_st *scorecard) {
@@ -90,7 +90,7 @@ void initialize_scorecard(struct scorecard_st *scorecard) {
            = SCORE_UNSCORED;
}

unsigned int scorecard_is_not_full(struct scorecard_st *scorecard) {
unsigned int can_continue_playing(struct scorecard_st *scorecard) {
    return scorecard->aces == SCORE_UNSCORED
           || scorecard->twos == SCORE_UNSCORED
           || scorecard->threes == SCORE_UNSCORED
+2 −2
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
#ifndef DICELOGIC_H
#define DICELOGIC_H

extern const int NUM_DICE;
extern const unsigned int NUM_DICE;
extern const int SCORE_UNSCORED;

//const unsigned int MAX_TURNS = 3;
@@ -49,7 +49,7 @@ void generate_dice_roll(game_context *ctx, unsigned int *out_dice_values, int sa
int set_die_held(game_context *ctx, unsigned int index, unsigned int held);
void roll_and_print(game_context *ctx, unsigned int *out_dice_values, unsigned int animation_seconds);
void clear_held_values(game_context *ctx);
unsigned int scorecard_is_not_full(struct scorecard_st *scorecard);
unsigned int can_continue_playing(struct scorecard_st *scorecard);

// scorecard functions
unsigned int calculate_score(struct scorecard_st *scorecard, char *scoring_selection);
+3 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ int main(void) {
    const char *selected_action = menu_prompt(items, num_menu_items);

    if (strcasecmp(selected_action, "start") == 0) {
        while (scorecard_is_not_full(&ctx.game_state.scorecard)) {
        while (can_continue_playing(&ctx.game_state.scorecard)) {
            take_turn(&ctx, NUM_DICE);
        }
    } else if (strcasecmp(selected_action, "demo") == 0) {
@@ -76,11 +76,13 @@ void take_turn(game_context *ctx, unsigned int num_dice) {
            const char *player_action = menu_prompt(in_turn_menu, num_menu_items);
            if (strcasecmp(player_action, "enter_hold_selection") == 0) {
                // enter the menu for which dice to hold

            } else if (strcasecmp(player_action, "roll") == 0) {
                printf("Rolling again...\n");
                can_move_on = 1;
            } else if (strcasecmp(player_action, "score") == 0) {
                // enter the score menu

            }
        }
    }