Loading gamelogic.c +16 −0 Original line number Diff line number Diff line Loading @@ -89,3 +89,19 @@ void initialize_scorecard(struct scorecard_st *scorecard) { = scorecard->chance = SCORE_UNSCORED; } unsigned int scorecard_is_not_full(struct scorecard_st *scorecard) { return scorecard->aces == SCORE_UNSCORED || scorecard->twos == SCORE_UNSCORED || scorecard->threes == SCORE_UNSCORED || scorecard->fours == SCORE_UNSCORED || scorecard->fives == SCORE_UNSCORED || scorecard->sixes == SCORE_UNSCORED || scorecard->three_of_a_kind == SCORE_UNSCORED || scorecard->four_of_a_kind == SCORE_UNSCORED || scorecard->full_house == SCORE_UNSCORED || scorecard->small_straight == SCORE_UNSCORED || scorecard->large_straight == SCORE_UNSCORED || scorecard->yahtc == SCORE_UNSCORED || scorecard->chance == SCORE_UNSCORED; } gamelogic.h +1 −0 Original line number Diff line number Diff line Loading @@ -49,6 +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); // scorecard functions unsigned int calculate_score(struct scorecard_st *scorecard, char *scoring_selection); Loading graphics.c +0 −1 Original line number Diff line number Diff line Loading @@ -36,4 +36,3 @@ void cursor_to_dice_start(const int erase_lines) { // move cursor all the way to the left printf("\r"); } yaht.c +10 −8 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ // MIT License void do_demo_dice_rolls(game_context *ctx, unsigned int num_dice); // this is specifically to show 2 demo rolls, with one hold void game_loop(game_context *ctx, unsigned int num_dice); void take_turn(game_context *ctx, unsigned int num_dice); int main(void) { game_context ctx; Loading @@ -35,7 +35,9 @@ int main(void) { const char *selected_action = menu_prompt(items, num_menu_items); if (strcasecmp(selected_action, "start") == 0) { game_loop(&ctx, NUM_DICE); while (scorecard_is_not_full(&ctx.game_state.scorecard)) { take_turn(&ctx, NUM_DICE); } } else if (strcasecmp(selected_action, "demo") == 0) { do_demo_dice_rolls(&ctx, NUM_DICE); } Loading @@ -48,22 +50,22 @@ int main(void) { return 0; } void game_loop(game_context *ctx, unsigned int num_dice) { void take_turn(game_context *ctx, unsigned int num_dice) { // clear_held_values(ctx); // todo fix the struct so that this isn't needed before the first roll_and_print() unsigned int next_roll[num_dice]; unsigned int next_roll_dice_values[num_dice]; const menu_item in_turn_menu[] = { {.title = "Hold dice", .command = "enter_hold_selection", .enabled = 1}, {.title = "Roll again", .command = "roll", .enabled = 1}, {.title = "Score", .command = "score", .enabled = 1}, }; const unsigned int num_menu_items = sizeof(in_turn_menu) / sizeof(menu_item); for (int i = 1; i < 4; i++) { for (int which_roll_number = 1; which_roll_number < 4; which_roll_number++) { clear_held_values(ctx); // print Roll 1. printf("Roll %d\n", i); // print roll number printf("Roll %d\n", which_roll_number); // do a roll roll_and_print(ctx, next_roll, 3); roll_and_print(ctx, next_roll_dice_values, 3); // ask if holding dice, scoring, or rolling again // (put this in a while loop so user keeps getting prompted with choice until choosing to roll again) Loading Loading
gamelogic.c +16 −0 Original line number Diff line number Diff line Loading @@ -89,3 +89,19 @@ void initialize_scorecard(struct scorecard_st *scorecard) { = scorecard->chance = SCORE_UNSCORED; } unsigned int scorecard_is_not_full(struct scorecard_st *scorecard) { return scorecard->aces == SCORE_UNSCORED || scorecard->twos == SCORE_UNSCORED || scorecard->threes == SCORE_UNSCORED || scorecard->fours == SCORE_UNSCORED || scorecard->fives == SCORE_UNSCORED || scorecard->sixes == SCORE_UNSCORED || scorecard->three_of_a_kind == SCORE_UNSCORED || scorecard->four_of_a_kind == SCORE_UNSCORED || scorecard->full_house == SCORE_UNSCORED || scorecard->small_straight == SCORE_UNSCORED || scorecard->large_straight == SCORE_UNSCORED || scorecard->yahtc == SCORE_UNSCORED || scorecard->chance == SCORE_UNSCORED; }
gamelogic.h +1 −0 Original line number Diff line number Diff line Loading @@ -49,6 +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); // scorecard functions unsigned int calculate_score(struct scorecard_st *scorecard, char *scoring_selection); Loading
graphics.c +0 −1 Original line number Diff line number Diff line Loading @@ -36,4 +36,3 @@ void cursor_to_dice_start(const int erase_lines) { // move cursor all the way to the left printf("\r"); }
yaht.c +10 −8 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ // MIT License void do_demo_dice_rolls(game_context *ctx, unsigned int num_dice); // this is specifically to show 2 demo rolls, with one hold void game_loop(game_context *ctx, unsigned int num_dice); void take_turn(game_context *ctx, unsigned int num_dice); int main(void) { game_context ctx; Loading @@ -35,7 +35,9 @@ int main(void) { const char *selected_action = menu_prompt(items, num_menu_items); if (strcasecmp(selected_action, "start") == 0) { game_loop(&ctx, NUM_DICE); while (scorecard_is_not_full(&ctx.game_state.scorecard)) { take_turn(&ctx, NUM_DICE); } } else if (strcasecmp(selected_action, "demo") == 0) { do_demo_dice_rolls(&ctx, NUM_DICE); } Loading @@ -48,22 +50,22 @@ int main(void) { return 0; } void game_loop(game_context *ctx, unsigned int num_dice) { void take_turn(game_context *ctx, unsigned int num_dice) { // clear_held_values(ctx); // todo fix the struct so that this isn't needed before the first roll_and_print() unsigned int next_roll[num_dice]; unsigned int next_roll_dice_values[num_dice]; const menu_item in_turn_menu[] = { {.title = "Hold dice", .command = "enter_hold_selection", .enabled = 1}, {.title = "Roll again", .command = "roll", .enabled = 1}, {.title = "Score", .command = "score", .enabled = 1}, }; const unsigned int num_menu_items = sizeof(in_turn_menu) / sizeof(menu_item); for (int i = 1; i < 4; i++) { for (int which_roll_number = 1; which_roll_number < 4; which_roll_number++) { clear_held_values(ctx); // print Roll 1. printf("Roll %d\n", i); // print roll number printf("Roll %d\n", which_roll_number); // do a roll roll_and_print(ctx, next_roll, 3); roll_and_print(ctx, next_roll_dice_values, 3); // ask if holding dice, scoring, or rolling again // (put this in a while loop so user keeps getting prompted with choice until choosing to roll again) Loading