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); }