чување 6e073c7d5929830eeea7af0d5844224a6c5335ca
родитељ db36d3795c5a0c7c2ef9690cfcfa9ae3751f8a3c
Аутор: Страхиња Радић <sr@strahinja.org>
Датум: Wed, 5 Aug 2026 18:52:42 +0000
Properly handle HOF entry and game over dialog display on F2
Diffstat:
| M | linije.c | | | 65 | +++++++++++++++++++++++++++++++++++++++++------------------------ |
измењених датотека: 1, додавања: 41(+), брисања: 24(-)
diff --git a/linije.c b/linije.c
@@ -225,6 +225,7 @@ struct State {
struct HiScoreEntry* hall_of_fame;
void (*input_callback)(struct State*);
int input_col;
+ int input_instant_reset;
int input_shown;
int location_pointer;
SDL_FPoint* location_stack;
@@ -648,13 +649,9 @@ fill_triplet_generate:
pop_strings(state);
goto fill_triplet_generate;
}
+ /* Shouldn't happen */
if (state->nfree < 3)
- {
- state->mode = STATE_GAME_OVER;
- prepare_dialog(state, GAME_OVER_DIALOG_WIDTH,
- GAME_OVER_DIALOG_HEIGHT, game_over_text, 0, 1);
- return;
- }
+ goto fill_triplet_fail;
pass++;
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
"fill_triplet: %s at (%0.0f, %0.0f)", cell_names[(int)color],
@@ -665,11 +662,10 @@ fill_triplet_generate:
return;
fill_triplet_fail:
- state->mode = STATE_GAME_OVER;
- prepare_dialog(state, GAME_OVER_DIALOG_WIDTH, GAME_OVER_DIALOG_HEIGHT,
- game_over_text, 0, 1);
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
- "fill_triplet: Prepared game over dialog");
+ "fill_triplet: input_instant_reset = %s",
+ state->input_instant_reset ? "TRUE" : "FALSE");
+ game_over(state);
}
int
@@ -711,7 +707,19 @@ game_over(struct State* state)
if (state->score > state->hall_of_fame[HI_SCORE_MAX - 1].score)
input_name(state);
else
- game_over_dialog(state);
+ {
+ SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
+ "game_over: input_instant_reset = %s",
+ state->input_instant_reset ? "TRUE" : "FALSE");
+ if (state->input_instant_reset)
+ {
+ reset(state);
+ fill_triplet(state);
+ state->input_instant_reset = 0;
+ }
+ else
+ game_over_dialog(state);
+ }
}
void
@@ -957,7 +965,6 @@ handle_input(struct State* state, SDL_Event* event)
state->input_shown = 0;
if (state->input_callback)
state->input_callback(state);
- game_over_dialog(state);
break;
case SDLK_BACKSPACE:
if (state->input_col == 0)
@@ -1094,8 +1101,8 @@ handle_key_down(struct State* state, SDL_Event* event)
case SDLK_F2:
if (state->dialog_shown && state->dialog_text == help_text)
break;
- reset(state);
- fill_triplet(state);
+ state->input_instant_reset = 1;
+ game_over(state);
break;
case SDLK_F3:
if (state->dialog_shown)
@@ -1211,14 +1218,15 @@ init_state(struct State* state)
state->full_screen = 1;
state->hall_of_fame = NULL;
// state->hof_text = NULL;
- state->input_callback = NULL;
- state->input_col = 0;
- state->input_shown = 0;
- state->location_pointer = 0;
- state->location_stack = NULL;
- state->mode = STATE_IDLE;
- state->moveno = 1;
- state->nfree = GRID_WIDTH * GRID_HEIGHT;
+ state->input_callback = NULL;
+ state->input_col = 0;
+ state->input_instant_reset = 0;
+ state->input_shown = 0;
+ state->location_pointer = 0;
+ state->location_stack = NULL;
+ state->mode = STATE_IDLE;
+ state->moveno = 1;
+ state->nfree = GRID_WIDTH * GRID_HEIGHT;
assign_point_xyIF(0, 0, &state->mouse);
state->path_start = NULL;
state->path_end = NULL;
@@ -1272,8 +1280,17 @@ input_name_callback(struct State* state)
return;
}
- prepare_dialog(state, GAME_OVER_DIALOG_WIDTH, GAME_OVER_DIALOG_HEIGHT,
- game_over_text, 0, 1);
+ SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
+ "input_name_callback: input_instant_reset = %s",
+ state->input_instant_reset ? "TRUE" : "FALSE");
+ if (state->input_instant_reset)
+ {
+ reset(state);
+ fill_triplet(state);
+ state->input_instant_reset = 0;
+ }
+ else
+ game_over_dialog(state);
}
int