Loading yaht.c +35 −14 Original line number Diff line number Diff line Loading @@ -9,9 +9,12 @@ // Chris Morris // 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 do_demo_dice_rolls(game_context *ctx, unsigned int num_dice); // this is specifically to show 2 demo rolls, with one hold unsigned int take_turn(game_context *ctx, unsigned int num_dice); void show_rules(); int main(void) { game_context ctx; // initialize random device for game state Loading @@ -25,14 +28,16 @@ int main(void) { printf("yaht.c\n"); // todo add rules menu item + rules output menu_item items[] = { {.title = "New Game", .command = "start", .enabled = 1}, {.title = "Demo", .command = "demo", .enabled = 1}, // {.title = "Demo", .command = "demo", .enabled = 1}, // todo deprecate demo {.title = "Rules", .command = "rules", .enabled = 1}, {.title = "Exit", .command = "exit", .enabled = 1}, }; const unsigned int num_menu_items = sizeof(items) / sizeof(menu_item); int exiting = 0; // to be modified by the internal menu selection while (exiting == 0) { const char *selected_action = menu_prompt(items, num_menu_items, "Main menu", ""); if (strcasecmp(selected_action, "start") == 0) { Loading @@ -40,9 +45,17 @@ int main(void) { while (can_continue_playing(&ctx.game_state.scorecard) && !game_over) { game_over = take_turn(&ctx, NUM_DICE); } printf("Your final score was %d.\nThank you for playing!\n", calculate_total_score(&ctx.game_state.scorecard)); } else if (strcasecmp(selected_action, "demo") == 0) { do_demo_dice_rolls(&ctx, NUM_DICE); printf("Your final score was %d.\nThank you for playing!\n", calculate_total_score(&ctx.game_state.scorecard)); // } else if (strcasecmp(selected_action, "demo") == 0) { // do_demo_dice_rolls(&ctx, NUM_DICE); // } } else if (strcasecmp(selected_action, "rules") == 0) { show_rules(); } else if (strcasecmp(selected_action, "exit") == 0) { exiting = 1; } } // cleanup items Loading @@ -56,7 +69,8 @@ int main(void) { unsigned int take_turn(game_context *ctx, unsigned int num_dice) { clear_held_values(ctx); unsigned int next_roll_dice_values[num_dice]; for (unsigned int which_roll_number = ROLL_NUMBER_OFFSET; which_roll_number < ROLLS_PER_TURN + ROLL_NUMBER_OFFSET; which_roll_number++) { for (unsigned int which_roll_number = ROLL_NUMBER_OFFSET; which_roll_number < ROLLS_PER_TURN + ROLL_NUMBER_OFFSET; which_roll_number++) { // print roll number printf("Roll %d\n", which_roll_number); // sleep_ms(1000); Loading @@ -76,7 +90,8 @@ unsigned int take_turn(game_context *ctx, unsigned int num_dice) { {.title = "End game", .command = "quit", .enabled = 1}, }; const unsigned int num_menu_items = sizeof(in_turn_menu) / sizeof(menu_item); const char *player_action = menu_prompt(in_turn_menu, num_menu_items, "Choose from the following:", "disabled"); const char *player_action = menu_prompt(in_turn_menu, num_menu_items, "Choose from the following:", "disabled"); if (strcasecmp(player_action, "enter_hold_selection") == 0) { // enter the menu for which dice to hold hold_dice_with_menu(ctx->game_state.dice, NUM_DICE); Loading @@ -87,7 +102,8 @@ unsigned int take_turn(game_context *ctx, unsigned int num_dice) { // enter the score menu char *selection = get_player_score_selection_with_menu(&ctx->game_state.scorecard); if (strcasecmp(selection, "back") != 0) { unsigned int points_awarded = calculate_selection_score(ctx, selection); // todo we should use the return value for this to assign the point value, not do it within get_player_score_selection() unsigned int points_awarded = calculate_selection_score(ctx, selection); // todo we should use the return value for this to assign the point value, not do it within get_player_score_selection() printf("for selection %s, points awarded: %d\n", selection, points_awarded); return 0; // 0 signifies user_quit == false, which will move on to the next turn } Loading Loading @@ -126,3 +142,8 @@ void do_demo_dice_rolls(game_context *ctx, unsigned int num_dice) { } printf("\n"); } void show_rules() { // todo write show_rules() printf("⚠\uFE0F under construction ⚠\uFE0F\n"); } Loading
yaht.c +35 −14 Original line number Diff line number Diff line Loading @@ -9,9 +9,12 @@ // Chris Morris // 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 do_demo_dice_rolls(game_context *ctx, unsigned int num_dice); // this is specifically to show 2 demo rolls, with one hold unsigned int take_turn(game_context *ctx, unsigned int num_dice); void show_rules(); int main(void) { game_context ctx; // initialize random device for game state Loading @@ -25,14 +28,16 @@ int main(void) { printf("yaht.c\n"); // todo add rules menu item + rules output menu_item items[] = { {.title = "New Game", .command = "start", .enabled = 1}, {.title = "Demo", .command = "demo", .enabled = 1}, // {.title = "Demo", .command = "demo", .enabled = 1}, // todo deprecate demo {.title = "Rules", .command = "rules", .enabled = 1}, {.title = "Exit", .command = "exit", .enabled = 1}, }; const unsigned int num_menu_items = sizeof(items) / sizeof(menu_item); int exiting = 0; // to be modified by the internal menu selection while (exiting == 0) { const char *selected_action = menu_prompt(items, num_menu_items, "Main menu", ""); if (strcasecmp(selected_action, "start") == 0) { Loading @@ -40,9 +45,17 @@ int main(void) { while (can_continue_playing(&ctx.game_state.scorecard) && !game_over) { game_over = take_turn(&ctx, NUM_DICE); } printf("Your final score was %d.\nThank you for playing!\n", calculate_total_score(&ctx.game_state.scorecard)); } else if (strcasecmp(selected_action, "demo") == 0) { do_demo_dice_rolls(&ctx, NUM_DICE); printf("Your final score was %d.\nThank you for playing!\n", calculate_total_score(&ctx.game_state.scorecard)); // } else if (strcasecmp(selected_action, "demo") == 0) { // do_demo_dice_rolls(&ctx, NUM_DICE); // } } else if (strcasecmp(selected_action, "rules") == 0) { show_rules(); } else if (strcasecmp(selected_action, "exit") == 0) { exiting = 1; } } // cleanup items Loading @@ -56,7 +69,8 @@ int main(void) { unsigned int take_turn(game_context *ctx, unsigned int num_dice) { clear_held_values(ctx); unsigned int next_roll_dice_values[num_dice]; for (unsigned int which_roll_number = ROLL_NUMBER_OFFSET; which_roll_number < ROLLS_PER_TURN + ROLL_NUMBER_OFFSET; which_roll_number++) { for (unsigned int which_roll_number = ROLL_NUMBER_OFFSET; which_roll_number < ROLLS_PER_TURN + ROLL_NUMBER_OFFSET; which_roll_number++) { // print roll number printf("Roll %d\n", which_roll_number); // sleep_ms(1000); Loading @@ -76,7 +90,8 @@ unsigned int take_turn(game_context *ctx, unsigned int num_dice) { {.title = "End game", .command = "quit", .enabled = 1}, }; const unsigned int num_menu_items = sizeof(in_turn_menu) / sizeof(menu_item); const char *player_action = menu_prompt(in_turn_menu, num_menu_items, "Choose from the following:", "disabled"); const char *player_action = menu_prompt(in_turn_menu, num_menu_items, "Choose from the following:", "disabled"); if (strcasecmp(player_action, "enter_hold_selection") == 0) { // enter the menu for which dice to hold hold_dice_with_menu(ctx->game_state.dice, NUM_DICE); Loading @@ -87,7 +102,8 @@ unsigned int take_turn(game_context *ctx, unsigned int num_dice) { // enter the score menu char *selection = get_player_score_selection_with_menu(&ctx->game_state.scorecard); if (strcasecmp(selection, "back") != 0) { unsigned int points_awarded = calculate_selection_score(ctx, selection); // todo we should use the return value for this to assign the point value, not do it within get_player_score_selection() unsigned int points_awarded = calculate_selection_score(ctx, selection); // todo we should use the return value for this to assign the point value, not do it within get_player_score_selection() printf("for selection %s, points awarded: %d\n", selection, points_awarded); return 0; // 0 signifies user_quit == false, which will move on to the next turn } Loading Loading @@ -126,3 +142,8 @@ void do_demo_dice_rolls(game_context *ctx, unsigned int num_dice) { } printf("\n"); } void show_rules() { // todo write show_rules() printf("⚠\uFE0F under construction ⚠\uFE0F\n"); }