restart button on the game over is now wokring properly well

This commit is contained in:
Priec
2025-12-14 17:15:50 +01:00
parent 3cef68142d
commit e5091a33e7
2 changed files with 45 additions and 2 deletions

View File

@@ -1,13 +1,54 @@
// src/game/game_over.cpp
#include "game_over.h"
#include "mbed.h"
#include "../render/background.h"
#include "../assets/background_frame.h"
#include <cstdio>
void show_game_over_screen(int seconds) {
printf("\033[2J\033[H");
// 34 znakov vo vypise
const int box_width = 34;
const int start_col = (VIEW_WIDTH - box_width) / 2;
const int box_height = 6;
const int top_padding = (VIEW_HEIGHT - box_height) / 2;
// Empty rows
for (int i = 0; i < top_padding; i++) {
printf("\r\n");
}
for (int i = 0; i < start_col; i++) printf(" ");
printf("==================================\r\n");
for (int i = 0; i < start_col; i++) printf(" ");
printf(" G A M E O V E R \r\n");
for (int i = 0; i < start_col; i++) printf(" ");
printf("==================================\r\n");
printf(" Vydrzal si %d sekund. \r\n", seconds);
for (int i = 0; i < start_col; i++) printf(" ");
printf(" Doba hry %d sekund. \r\n", seconds);
for (int i = 0; i < start_col; i++) printf(" ");
printf("==================================\r\n");
printf(" Stlacte tlacidlo pre restart. \r\n");
fflush(stdout);
DigitalIn restart_button(BUTTON1);
int initial_state = restart_button.read();
while (restart_button.read() == initial_state) {
ThisThread::sleep_for(50ms);
}
int new_state = restart_button.read();
while (restart_button.read() == new_state) {
ThisThread::sleep_for(50ms);
}
printf("\033[2J\033[H");
fflush(stdout);
}

View File

@@ -21,5 +21,7 @@ int main(void) {
serial_port.set_format(8, BufferedSerial::None, 1);
printf("Baud: %d, Format: 8-N-1\r\n", BAUD_RATE);
render_loop(1);
while (true) {
render_loop(4);
}
}