#include "game.h" #include "world.h" #include #include "world.h" #include #include void* init_game(void) { struct game* state = (struct game*)calloc(1, sizeof(struct game)); if (!state) { return NULL; } state->cat_x = 5; state->cat_y = 5; state->cat_dx = 1; state->cat_dy = 1; state->mouse_x = 15; state->mouse_y = 10; snprintf(state->message, sizeof(state->message), "Давай, попробуй поймать меня!"); return state; } int game_event(struct event* event, void* g_state) { struct game* game = (struct game*)g_state; if (!game) return 0; if (event->type == KEY_SREDO) { switch (event->key) { case KEY_UP: game->cat_y -= game->cat_dy; break; case KEY_DOWN: game->cat_y += game->cat_dy; break; case KEY_LEFT: game->cat_x -= game->cat_dx; break; case KEY_RIGHT: game->cat_x += game->cat_dx; break; default: break; } } game->mouse_x += (rand() % 3) - 1; game->mouse_y += (rand() % 3) - 1; if (game->cat_x == game->mouse_x && game->cat_y == game->mouse_y) { snprintf(game->message, sizeof(game->message), "Мышь поймана! Ура!"); } return 0; }