From 8acb9baa7b7c2bdd67dc44d54fcd2f4e087fb9e1 Mon Sep 17 00:00:00 2001 From: squee72564 Date: Mon, 1 Jan 2024 23:21:35 -0800 Subject: [PATCH 1/4] Added function to set board width/height state for setup & reset functions. --- views/minesweeper_game_screen.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/views/minesweeper_game_screen.c b/views/minesweeper_game_screen.c index e532c69..13b193b 100644 --- a/views/minesweeper_game_screen.c +++ b/views/minesweeper_game_screen.c @@ -72,7 +72,7 @@ typedef struct { uint16_t mines_left; uint16_t flags_left; CurrentPosition curr_pos; - uint8_t right_boundary, bottom_boundary; + uint8_t right_boundary, bottom_boundary, board_width, board_height; } MineSweeperGameScreenModel; void mine_sweeper_game_screen_view_enter(void* context) { @@ -352,7 +352,7 @@ static void setup_board(MineSweeperGameScreen* instance) { } -MineSweeperGameScreen* mine_sweeper_game_screen_alloc() { +MineSweeperGameScreen* mine_sweeper_game_screen_alloc(uint8_t width, uint8_t height) { MineSweeperGameScreen* mine_sweeper_game_screen = (MineSweeperGameScreen*)malloc(sizeof(MineSweeperGameScreen)); mine_sweeper_game_screen->view = view_alloc(); @@ -368,6 +368,9 @@ MineSweeperGameScreen* mine_sweeper_game_screen_alloc() { view_set_exit_callback(mine_sweeper_game_screen->view, mine_sweeper_game_screen_view_exit); mine_sweeper_game_screen->input_callback = NULL; + + // We need to initize board width and height before setup + mine_sweeper_game_screen_set_board_dimensions(mine_sweeper_game_screen, width, height); setup_board(mine_sweeper_game_screen); @@ -417,6 +420,19 @@ void mine_sweeper_game_screen_set_context(MineSweeperGameScreen* instance, void* instance->context = context; } +void mine_sweeper_game_screen_set_board_dimensions(MineSweeperGameScreen* instance, uint8_t width, uint8_t height) { + furi_assert(instance); + + with_view_model( + instance->view, + MineSweeperGameScreenModel * model, + { + model->board_width = width; + model->board_height = height; + }, + false); +} + bool mine_sweeper_is_tile_mine(MineSweeperGameScreen* instance, uint16_t x, uint16_t y) { furi_assert(instance); bool is_mine = false; From c91d51035265a06604eac3eaf62b84628c3d341e Mon Sep 17 00:00:00 2001 From: squee72564 Date: Mon, 1 Jan 2024 23:22:26 -0800 Subject: [PATCH 2/4] Added f set_board_dimensions function, and alloc now takes dimensions --- views/minesweeper_game_screen.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/views/minesweeper_game_screen.h b/views/minesweeper_game_screen.h index 973d8e0..5678594 100644 --- a/views/minesweeper_game_screen.h +++ b/views/minesweeper_game_screen.h @@ -44,7 +44,7 @@ typedef bool (*GameScreenInputCallback)(InputEvent* event, void* context); * * @return MineSweeperGameScreen view instance */ -MineSweeperGameScreen* mine_sweeper_game_screen_alloc(); +MineSweeperGameScreen* mine_sweeper_game_screen_alloc(uint8_t width, uint8_t height); /** Deinitialize and free Start Screen view * @@ -82,6 +82,10 @@ void mine_sweeper_game_screen_set_input_callback( */ void mine_sweeper_game_screen_set_context(MineSweeperGameScreen* instance, void* context); +/** + * ADD LATER + */ +void mine_sweeper_game_screen_set_board_dimensions(MineSweeperGameScreen* instance, uint8_t width, uint8_t height); /** Return true/false if tile is a mine * From 9d7f0bf63418488657c7e6e7d95af88e9531f766 Mon Sep 17 00:00:00 2001 From: squee72564 Date: Mon, 1 Jan 2024 23:25:04 -0800 Subject: [PATCH 3/4] Added initial board dimensions to alloc call for game_screen --- minesweeper.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/minesweeper.c b/minesweeper.c index 4176f2d..f65a8c2 100644 --- a/minesweeper.c +++ b/minesweeper.c @@ -40,6 +40,20 @@ static MineSweeperApp* app_alloc() { view_dispatcher_set_navigation_event_callback(app->view_dispatcher, minesweeper_navigation_event_callback); view_dispatcher_set_tick_event_callback(app->view_dispatcher, minesweeper_tick_event_callback, 500); + // Set setting info to default + app->settings_info.width_str = furi_string_alloc(); + app->settings_info.height_str = furi_string_alloc(); + app->settings_info.board_width = 32; + app->settings_info.board_height = 32; + app->settings_info.difficulty = 0; + memset(&app->t_settings_info, 0, sizeof(app->t_settings_info)); + app->is_settings_changed = false; + + // Set hardware related values to default + app->haptic = 1; + app->speaker = 1; + app->led = 1; + // Alloc views and add to view dispatcher app->start_screen = start_screen_alloc(); view_dispatcher_add_view(app->view_dispatcher, MineSweeperStartScreenView, start_screen_get_view(app->start_screen)); @@ -47,7 +61,7 @@ static MineSweeperApp* app_alloc() { app->loading = loading_alloc(); view_dispatcher_add_view(app->view_dispatcher, MineSweeperLoadingView, loading_get_view(app->loading)); - app->game_screen = mine_sweeper_game_screen_alloc(); + app->game_screen = mine_sweeper_game_screen_alloc(app->settings_info.board_width, app->settings_info.board_height); view_dispatcher_add_view( app->view_dispatcher, MineSweeperGameScreenView, @@ -62,19 +76,7 @@ static MineSweeperApp* app_alloc() { app->confirmation_screen = dialog_ex_alloc(); view_dispatcher_add_view(app->view_dispatcher, MineSweeperConfirmationView, dialog_ex_get_view(app->confirmation_screen)); - // Set setting info to default - app->settings_info.width_str = furi_string_alloc(); - app->settings_info.height_str = furi_string_alloc(); - app->settings_info.board_width = 32; - app->settings_info.board_height = 32; - app->settings_info.difficulty = 0; - memset(&app->t_settings_info, 0, sizeof(app->t_settings_info)); - app->is_settings_changed = false; - // Set hardware related values to default - app->haptic = 1; - app->speaker = 1; - app->led = 1; return app; From fda2c8a705340dbf0fa3440dcaaa5ba25a4fc73e Mon Sep 17 00:00:00 2001 From: squee72564 Date: Mon, 1 Jan 2024 23:25:57 -0800 Subject: [PATCH 4/4] setting new board dimensions on settings change --- scenes/confirmation_scene.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scenes/confirmation_scene.c b/scenes/confirmation_scene.c index 6bee589..fd3e037 100644 --- a/scenes/confirmation_scene.c +++ b/scenes/confirmation_scene.c @@ -57,6 +57,11 @@ bool minesweeper_scene_confirmation_screen_on_event(void* context, SceneManagerE app->settings_info.difficulty = app->t_settings_info.difficulty; app->is_settings_changed = false; + mine_sweeper_game_screen_set_board_dimensions( + app->game_screen, + app->settings_info.board_width, + app->settings_info.board_width); + // Reset the game board mine_sweeper_game_screen_reset(app->game_screen);