diff --git a/applications/plugins/snake_game/snake_game.c b/applications/plugins/snake_game/snake_game.c index b316fb77d..3405a7b26 100644 --- a/applications/plugins/snake_game/snake_game.c +++ b/applications/plugins/snake_game/snake_game.c @@ -87,7 +87,7 @@ static void snake_game_render_callback(Canvas* const canvas, void* ctx) { canvas_set_font(canvas, FontSecondary); char buffer[18]; - snprintf(buffer, sizeof(buffer), "Score: %u", snake_state->len - 7); + snprintf(buffer, sizeof(buffer), "Score: %u", snake_state->len); canvas_draw_str_aligned(canvas, 64, 41, AlignCenter, AlignBottom, buffer); snprintf(buffer, sizeof(buffer), "Highscore: %d", snake_state->highscore); @@ -222,6 +222,18 @@ static void snake_game_move_snake(SnakeState* const snake_state, Point const nex snake_state->points[0] = next_step; } +static void snake_game_game_over(SnakeState* const snake_state, NotificationApp* notification) { + snake_state->state = GameStateGameOver; + snake_state->len = snake_state->len -7; + if(snake_state->len > snake_state->highscore){ + snake_state->isNewHighscore = true; + snake_state->highscore = snake_state->len; + } + + notification_message_block(notification, &sequence_fail); + +} + static void snake_game_process_game_step(SnakeState* const snake_state, NotificationApp* notification) { if(snake_state->state == GameStateGameOver) { @@ -241,9 +253,7 @@ static void snake_state->state = GameStateLastChance; return; } else if(snake_state->state == GameStateLastChance) { - snake_state->state = GameStateGameOver; - snake_state->highscore = snake_game_save_score_to_file(snake_state->len); - notification_message_block(notification, &sequence_fail); + snake_game_game_over(snake_state, notification); return; } } else { @@ -254,9 +264,7 @@ static void crush = snake_game_collision_with_tail(snake_state, next_step); if(crush) { - snake_state->state = GameStateGameOver; - snake_state->highscore = snake_game_save_score_to_file(snake_state->len); - notification_message_block(notification, &sequence_fail); + snake_game_game_over(snake_state, notification); return; } @@ -264,9 +272,7 @@ static void if(eatFruit) { snake_state->len++; if(snake_state->len >= MAX_SNAKE_LEN) { - snake_state->state = GameStateGameOver; - snake_state->highscore = snake_game_save_score_to_file(snake_state->len); - notification_message_block(notification, &sequence_fail); + snake_game_game_over(snake_state, notification); return; } }