From 54e655945b14232f419bd57a3747be9382e38092 Mon Sep 17 00:00:00 2001 From: devmilanian Date: Fri, 29 Jul 2022 21:56:13 -0400 Subject: [PATCH 1/3] Feature: game_2048 press center to restart --- applications/game2048/game_2048.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/applications/game2048/game_2048.c b/applications/game2048/game_2048.c index e3d68acf579..b7c8502b41a 100644 --- a/applications/game2048/game_2048.c +++ b/applications/game2048/game_2048.c @@ -323,6 +323,19 @@ static void game_2048_process_move(GameState* const game_state) { // } +static void game_2048_restart(GameState* const game_state) { + // clear all cells + for(uint8_t y = 0; y < 4; y++) { + for(uint8_t x = 0; x < 4; x++) { + game_state->field[y][x] = 0; + } + } + + // start next game + game_2048_set_new_number(game_state); + game_2048_set_new_number(game_state); +} + int32_t game_2048_app(void* p) { int32_t return_code = 0; @@ -399,7 +412,9 @@ int32_t game_2048_app(void* p) { game_2048_process_move(game_state); game_2048_set_new_number(game_state); break; - case InputKeyOk:; // TODO: reinit in game ower state + case InputKeyOk: + game_state->direction = DirectionIdle; + game_2048_restart(game_state); break; case InputKeyBack: loop = false; @@ -423,4 +438,4 @@ int32_t game_2048_app(void* p) { furi_message_queue_free(event_queue); return return_code; -} \ No newline at end of file +} From dca2363eb187d0040b9db94978598a5a32dd292a Mon Sep 17 00:00:00 2001 From: devmilanian Date: Fri, 29 Jul 2022 22:44:19 -0400 Subject: [PATCH 2/3] Fix UNUSED --- applications/game2048/game_2048.c | 1 + 1 file changed, 1 insertion(+) diff --git a/applications/game2048/game_2048.c b/applications/game2048/game_2048.c index b7c8502b41a..cfd44552dc7 100644 --- a/applications/game2048/game_2048.c +++ b/applications/game2048/game_2048.c @@ -337,6 +337,7 @@ static void game_2048_restart(GameState* const game_state) { } int32_t game_2048_app(void* p) { + UNUSED(p); int32_t return_code = 0; FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent)); From b110f4ef5a4bb5782d89370f97e8852fecbe6a97 Mon Sep 17 00:00:00 2001 From: devmilanian Date: Sat, 30 Jul 2022 03:07:32 -0400 Subject: [PATCH 3/3] Fix: require long press to restart --- applications/game2048/game_2048.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/applications/game2048/game_2048.c b/applications/game2048/game_2048.c index cfd44552dc7..67a3eeeae30 100644 --- a/applications/game2048/game_2048.c +++ b/applications/game2048/game_2048.c @@ -391,7 +391,7 @@ int32_t game_2048_app(void* p) { GameState* game_state = (GameState*)acquire_mutex_block(&state_mutex); if(event_status == FuriStatusOk) { - if(event.type == InputTypePress) { + if(event.type == InputTypeShort) { switch(event.key) { case InputKeyUp: game_state->direction = DirectionUp; @@ -415,12 +415,16 @@ int32_t game_2048_app(void* p) { break; case InputKeyOk: game_state->direction = DirectionIdle; - game_2048_restart(game_state); break; case InputKeyBack: loop = false; break; } + } else if(event.type == InputTypeLong) { + if(event.key == InputKeyOk) { + game_state->direction = DirectionIdle; + game_2048_restart(game_state); + } } }