Loading gamelogic.c +18 −2 Original line number Diff line number Diff line Loading @@ -225,8 +225,24 @@ void hold_dice_with_menu(struct die_st *dice, unsigned int num_dice) { } } char *get_player_score_selection() { return ""; // placeholder char *get_player_score_selection_with_menu(struct scorecard_st *scorecard) { menu_item scoring_menu[] = { {.title = "aces", .command = "aces", .multi_selected = 0, .enabled = scorecard->aces != SCORE_UNSCORED}, {.title = "twos", .command = "twos", .multi_selected = 0, .enabled = scorecard->twos != SCORE_UNSCORED}, {.title = "threes", .command = "threes", .multi_selected = 0, .enabled = scorecard->threes != SCORE_UNSCORED}, {.title = "fours", .command = "fours", .multi_selected = 0, .enabled = scorecard->fours != SCORE_UNSCORED}, {.title = "fives", .command = "fives", .multi_selected = 0, .enabled = scorecard->fives != SCORE_UNSCORED}, {.title = "sixes", .command = "sixes", .multi_selected = 0, .enabled = scorecard->sixes != SCORE_UNSCORED}, {.title = "three of a kind", .command = "three_of_a_kind", .multi_selected = 0, .enabled = scorecard->three_of_a_kind != SCORE_UNSCORED}, {.title = "four of a kind", .command = "four_of_a_kind", .multi_selected = 0, .enabled = scorecard->four_of_a_kind != SCORE_UNSCORED}, {.title = "small straight", .command = "small_straight", .multi_selected = 0, .enabled = scorecard->small_straight != SCORE_UNSCORED}, {.title = "large straight", .command = "large_straight", .multi_selected = 0, .enabled = scorecard->large_straight != SCORE_UNSCORED}, {.title = "full house", .command = "full_house", .multi_selected = 0, .enabled = scorecard->full_house != SCORE_UNSCORED}, {.title = "yahtc", .command = "yahtc", .multi_selected = 0, .enabled = scorecard->yahtc != SCORE_UNSCORED}, {.title = "chance", .command = "chance", .multi_selected = 0, .enabled = scorecard->chance != SCORE_UNSCORED}, }; unsigned int num_menu_items = sizeof(scoring_menu) / sizeof(menu_item); return menu_prompt(scoring_menu, num_menu_items); } unsigned int sum_dice_matching_value(struct die_st *dice, unsigned int value) { Loading gamelogic.h +1 −1 Original line number Diff line number Diff line Loading @@ -58,7 +58,7 @@ void hold_dice_with_menu(struct die_st *dice, unsigned int num_dice); unsigned int calculate_selection_score(game_context *ctx, char *selection); unsigned int calculate_total_score(struct scorecard_st *scorecard); void initialize_scorecard(struct scorecard_st *scorecard); char *get_player_score_selection(); char *get_player_score_selection_with_menu(struct scorecard_st *scorecard); unsigned int sum_dice_matching_value(struct die_st *dice, unsigned int value); #endif //DICELOGIC_H menu.c +6 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,9 @@ char *menu_prompt(const menu_item *items, const unsigned int num_menu_items) { if (i == hovered_selection_index) { printf("> "); } if (!items[i].enabled) { printf(" [disabled] "); } printf("%s\n", items[i].title); } } Loading Loading @@ -88,6 +91,9 @@ void menu_prompt_multi_select(menu_item *items, const unsigned int num_menu_item if (items[i].multi_selected) { printf(" [selected] "); } if (!items[i].enabled) { printf(" [disabled] "); } printf("%s\n", items[i].title); } } Loading yaht.c +1 −1 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ unsigned int take_turn(game_context *ctx, unsigned int num_dice) { can_roll_again = 1; } else if (strcasecmp(player_action, "score") == 0) { // enter the score menu char *selection = get_player_score_selection(); char *selection = get_player_score_selection_with_menu(&ctx->game_state.scorecard); calculate_selection_score(ctx, selection); } else if (strcasecmp(player_action, "quit") == 0) { // todo this could be more robust or interactive. maybe add the final score? Loading Loading
gamelogic.c +18 −2 Original line number Diff line number Diff line Loading @@ -225,8 +225,24 @@ void hold_dice_with_menu(struct die_st *dice, unsigned int num_dice) { } } char *get_player_score_selection() { return ""; // placeholder char *get_player_score_selection_with_menu(struct scorecard_st *scorecard) { menu_item scoring_menu[] = { {.title = "aces", .command = "aces", .multi_selected = 0, .enabled = scorecard->aces != SCORE_UNSCORED}, {.title = "twos", .command = "twos", .multi_selected = 0, .enabled = scorecard->twos != SCORE_UNSCORED}, {.title = "threes", .command = "threes", .multi_selected = 0, .enabled = scorecard->threes != SCORE_UNSCORED}, {.title = "fours", .command = "fours", .multi_selected = 0, .enabled = scorecard->fours != SCORE_UNSCORED}, {.title = "fives", .command = "fives", .multi_selected = 0, .enabled = scorecard->fives != SCORE_UNSCORED}, {.title = "sixes", .command = "sixes", .multi_selected = 0, .enabled = scorecard->sixes != SCORE_UNSCORED}, {.title = "three of a kind", .command = "three_of_a_kind", .multi_selected = 0, .enabled = scorecard->three_of_a_kind != SCORE_UNSCORED}, {.title = "four of a kind", .command = "four_of_a_kind", .multi_selected = 0, .enabled = scorecard->four_of_a_kind != SCORE_UNSCORED}, {.title = "small straight", .command = "small_straight", .multi_selected = 0, .enabled = scorecard->small_straight != SCORE_UNSCORED}, {.title = "large straight", .command = "large_straight", .multi_selected = 0, .enabled = scorecard->large_straight != SCORE_UNSCORED}, {.title = "full house", .command = "full_house", .multi_selected = 0, .enabled = scorecard->full_house != SCORE_UNSCORED}, {.title = "yahtc", .command = "yahtc", .multi_selected = 0, .enabled = scorecard->yahtc != SCORE_UNSCORED}, {.title = "chance", .command = "chance", .multi_selected = 0, .enabled = scorecard->chance != SCORE_UNSCORED}, }; unsigned int num_menu_items = sizeof(scoring_menu) / sizeof(menu_item); return menu_prompt(scoring_menu, num_menu_items); } unsigned int sum_dice_matching_value(struct die_st *dice, unsigned int value) { Loading
gamelogic.h +1 −1 Original line number Diff line number Diff line Loading @@ -58,7 +58,7 @@ void hold_dice_with_menu(struct die_st *dice, unsigned int num_dice); unsigned int calculate_selection_score(game_context *ctx, char *selection); unsigned int calculate_total_score(struct scorecard_st *scorecard); void initialize_scorecard(struct scorecard_st *scorecard); char *get_player_score_selection(); char *get_player_score_selection_with_menu(struct scorecard_st *scorecard); unsigned int sum_dice_matching_value(struct die_st *dice, unsigned int value); #endif //DICELOGIC_H
menu.c +6 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,9 @@ char *menu_prompt(const menu_item *items, const unsigned int num_menu_items) { if (i == hovered_selection_index) { printf("> "); } if (!items[i].enabled) { printf(" [disabled] "); } printf("%s\n", items[i].title); } } Loading Loading @@ -88,6 +91,9 @@ void menu_prompt_multi_select(menu_item *items, const unsigned int num_menu_item if (items[i].multi_selected) { printf(" [selected] "); } if (!items[i].enabled) { printf(" [disabled] "); } printf("%s\n", items[i].title); } } Loading
yaht.c +1 −1 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ unsigned int take_turn(game_context *ctx, unsigned int num_dice) { can_roll_again = 1; } else if (strcasecmp(player_action, "score") == 0) { // enter the score menu char *selection = get_player_score_selection(); char *selection = get_player_score_selection_with_menu(&ctx->game_state.scorecard); calculate_selection_score(ctx, selection); } else if (strcasecmp(player_action, "quit") == 0) { // todo this could be more robust or interactive. maybe add the final score? Loading