pause fixed
This commit is contained in:
parent
e58a842a43
commit
280cbee0a2
2 changed files with 31 additions and 15 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -9,15 +9,7 @@ void display_game(GameInfo_t game_state) {
|
|||
|
||||
clear();
|
||||
|
||||
// Убираем проверку на GameOver из display
|
||||
if (game_state.pause) {
|
||||
mvprintw(FIELD_HEIGHT / 2, FIELD_WIDTH * 2 + 1, "PAUSED");
|
||||
refresh();
|
||||
LOG_FUNCTION_END("display_game", "paused");
|
||||
return;
|
||||
}
|
||||
|
||||
// Отображение игрового поля
|
||||
// Отображение игрового поля (всегда, даже во время паузы)
|
||||
for (int i = 0; i < FIELD_HEIGHT; ++i) {
|
||||
for (int j = 0; j < FIELD_WIDTH; ++j) {
|
||||
if (game_state.field[i][j] == 2) {
|
||||
|
|
@ -48,12 +40,13 @@ void display_game(GameInfo_t game_state) {
|
|||
mvprintw(FIELD_HEIGHT + 4, 1, "Level: %d", game_state.level);
|
||||
mvprintw(FIELD_HEIGHT + 5, 1, "Speed: %d", game_state.speed);
|
||||
|
||||
// Показываем надпись "PAUSED" если игра на паузе
|
||||
if (game_state.pause) {
|
||||
mvprintw(FIELD_HEIGHT / 2, FIELD_WIDTH * 2 + 1, "PAUSED");
|
||||
}
|
||||
|
||||
refresh();
|
||||
|
||||
LOG_FUNCTION_END("display_game", "score=%d, level=%d",
|
||||
game_state.score, game_state.level);
|
||||
LOG_FUNCTION_END("display_game", "score=%d, level=%d, pause=%d",
|
||||
game_state.score, game_state.level, game_state.pause);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue