plne funkcna

This commit is contained in:
Denis Landa 2025-06-08 21:47:41 +02:00
parent 36f21816e3
commit 240983bf56

View File

@ -13,14 +13,12 @@ void init_game(GameState *state) {
void draw_game(const GameState *state){ void draw_game(const GameState *state){
world_clear(); world_clear();
// Vykresli mriežku a symboly
for (int y = 0; y < BOARD_SIZE; y++){ for (int y = 0; y < BOARD_SIZE; y++){
for (int x = 0; x < BOARD_SIZE; x++){ for (int x = 0; x < BOARD_SIZE; x++){
char symbol = state->board[y][x]; char symbol = state->board[y][x];
if (symbol == '\0') symbol = ' '; if (symbol == '\0') symbol = ' ';
world_draw_char(x * 4 + 2, y * 2 + 1, symbol); world_draw_char(x * 4 + 2, y * 2 + 1, symbol);
// Nakresli mriežku
if (x < BOARD_SIZE - 1){ if (x < BOARD_SIZE - 1){
world_draw_char(x * 4 + 3, y * 2 + 1, '|'); world_draw_char(x * 4 + 3, y * 2 + 1, '|');
} }
@ -32,15 +30,12 @@ void draw_game(const GameState *state) {
} }
} }
// Zvýrazni kurzor
world_draw_char(state->cursor_x * 4 + 2, state->cursor_y * 2 + 1, world_draw_char(state->cursor_x * 4 + 2, state->cursor_y * 2 + 1,
state->current_player == 0 ? 'X' : 'O'); state->current_player == 0 ? 'X' : 'O');
// Zobraz aktuálneho hráča
world_draw_text(0, BOARD_SIZE * 2 + 2, world_draw_text(0, BOARD_SIZE * 2 + 2,
state->current_player == 0 ? "Hrac: X" : "Hrac: O"); state->current_player == 0 ? "Hrac: X" : "Hrac: O");
// Zobraz info, ak hra skoncila
if (state->game_over){ if (state->game_over){
world_draw_text(0, BOARD_SIZE * 2 + 3, "Koniec hry! Stlac Q pre ukoncenie."); world_draw_text(0, BOARD_SIZE * 2 + 3, "Koniec hry! Stlac Q pre ukoncenie.");
} }
@ -74,9 +69,12 @@ void handle_key(GameState *state, int key) {
case ' ': case ' ':
if (state->board[state->cursor_y][state->cursor_x] == ' ') { if (state->board[state->cursor_y][state->cursor_x] == ' ') {
state->board[state->cursor_y][state->cursor_x] = state->current_player ? 'O' : 'X'; state->board[state->cursor_y][state->cursor_x] = state->current_player ? 'O' : 'X';
if (check_winner(state)) { if (check_winner(state))
{
state->game_over = 1; state->game_over = 1;
} else { }
else
{
state->current_player = !state->current_player; state->current_player = !state->current_player;
} }
} }