pause fixed

This commit is contained in:
Rorikstr | Rust Dev 2025-09-29 20:24:49 +03:00
parent e58a842a43
commit 280cbee0a2
2 changed files with 31 additions and 15 deletions

View file

@ -1,26 +1,49 @@
#include "01_automato.h"
#include "../../logging.h"
int load_high_score() {
FILE* file = fopen("high_score.txt", "r");
int high_score = 0;
if (file) {
fscanf(file, "%d", &high_score);
fclose(file);
}
return high_score;
}
void save_high_score(int score) {
FILE* file = fopen("high_score.txt", "w");
if (file) {
fprintf(file, "%d", score);
fclose(file);
}
}
void userInput(UserAction_t action, bool hold) {
LOG_FUNCTION_START("userInput", "action=%d, hold=%d", action, hold);
(void)hold; // заглушка
GameState_t* state = get_game_state();
// Команды движения игнорируются до первого спавна (пока state = Init или первый Spawn)
if ((state->state == Init || state->state == Spawn) &&
(action == Left || action == Right || action == Down || action == Up || action == Action)) {
LOG_FUNCTION_END("userInput", "ignored movement command during initialization, state=%d", state->state);
// Если игра на паузе, обрабатываются только определенные команды
if (state->info->pause &&
(action == Left || action == Right || action == Down || action == Up ||
action == Action || action == Start)) {
LOG_FUNCTION_END("userInput", "ignored movement command during pause, state=%d", state->state);
return;
}
switch (action) {
case Start:
// Загружаем рекорд при старте игры
state->info->high_score = load_high_score();
state->state = Init;
break;
case Terminate:
// Сохраняем рекорд при выходе, если текущий рекорд побит
if (state->info->score > state->info->high_score) {
state->info->high_score = state->info->score;
save_high_score(state->info->high_score);
}
state->state = GameOver;
break;