From 0014ef92362e4e4b886f08da5a0b7ffebb28b262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Vasi=C4=BE?= Date: Wed, 27 Apr 2022 20:49:06 +0200 Subject: [PATCH] domaca_uloha_7 --- du7/snake.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/du7/snake.c b/du7/snake.c index 451ecd4..3b20d43 100644 --- a/du7/snake.c +++ b/du7/snake.c @@ -71,28 +71,30 @@ int step_state(struct state* st){ hlava = st->snake; while (had != NULL) { - if (snake->x == nx || snake->y == ny) return END_SNAKE; + if (had->x == nx || had->y == ny) return END_SNAKE; for (i = 0; i < FOOD_COUNT; i++) { - if (foodx[i] == nx) { - if (foody[i] == ny) { - had = add_snake(had, foodx[i], foody[i]); + if (st->foodx[i] == had->x) { + if (st->foody[i] == had->y) { + had = add_snake(had, st->foodx[i], st->foody[i]); - foodx[i] = -1; - foody[i] = -1; + st->foodx[i] = -1; + st->foody[i] = -1; pocetJedal--; } } } if (pocetJedal == 0) return END_FOOD; + + had = had->next; } had = hlava; free(hlava); - if (nx > 0 && nx < width) { - if (ny > 0 && ny < height) { + if (nx > 0 && nx < st->width) { + if (ny > 0 && ny < st->height) { had = add_snake(had, nx, ny); had = remove_snake(had); }