diff --git a/a2/snake.c b/a2/snake.c index 6c55f16..c96b0b9 100644 --- a/a2/snake.c +++ b/a2/snake.c @@ -2,21 +2,20 @@ #include #include #include "world.h" - -// Game state structure -struct state { - int width; - int height; - int sx; - int sy; - struct snake* snake; - int foodx[5]; - int foody[5]; -}; +#include "snake.h" // Initialize game state void* init_game() { struct state* st = calloc(1, sizeof(struct state)); + st->width = 0; + st->height = 0; + st->sx = 0; + st->sy = 0; + st->snake = NULL; + for (int i = 0; i < 5; i++) { + st->foodx[i] = 0; + st->foody[i] = 0; + } return st; } @@ -58,7 +57,7 @@ int world_event(struct event* w, void* game) { st->sx = 0; st->sy = -1; } - } else if (w->type == EVENT_ESC) { + } else if (w->type == EVENT_ESC) { return 1; } else if (w->type == EVENT_TIMEOUT) { clear_screen(); @@ -84,4 +83,4 @@ int world_event(struct event* w, void* game) { } } return 0; -} +} \ No newline at end of file