Skip to content

Commit

Permalink
Merge pull request #2 from squee72564/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
squee72564 authored Jan 2, 2024
2 parents e42dde1 + fda2c8a commit f0b8eda
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
28 changes: 15 additions & 13 deletions minesweeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,28 @@ 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));

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,
Expand All @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions scenes/confirmation_scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
20 changes: 18 additions & 2 deletions views/minesweeper_game_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion views/minesweeper_game_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit f0b8eda

Please sign in to comment.