domaca_uloha_7
This commit is contained in:
parent
ad74267726
commit
0014ef9236
18
du7/snake.c
18
du7/snake.c
@ -71,28 +71,30 @@ int step_state(struct state* st){
|
|||||||
hlava = st->snake;
|
hlava = st->snake;
|
||||||
|
|
||||||
while (had != NULL) {
|
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++) {
|
for (i = 0; i < FOOD_COUNT; i++) {
|
||||||
if (foodx[i] == nx) {
|
if (st->foodx[i] == had->x) {
|
||||||
if (foody[i] == ny) {
|
if (st->foody[i] == had->y) {
|
||||||
had = add_snake(had, foodx[i], foody[i]);
|
had = add_snake(had, st->foodx[i], st->foody[i]);
|
||||||
|
|
||||||
foodx[i] = -1;
|
st->foodx[i] = -1;
|
||||||
foody[i] = -1;
|
st->foody[i] = -1;
|
||||||
pocetJedal--;
|
pocetJedal--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pocetJedal == 0) return END_FOOD;
|
if (pocetJedal == 0) return END_FOOD;
|
||||||
|
|
||||||
|
had = had->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
had = hlava;
|
had = hlava;
|
||||||
free(hlava);
|
free(hlava);
|
||||||
|
|
||||||
if (nx > 0 && nx < width) {
|
if (nx > 0 && nx < st->width) {
|
||||||
if (ny > 0 && ny < height) {
|
if (ny > 0 && ny < st->height) {
|
||||||
had = add_snake(had, nx, ny);
|
had = add_snake(had, nx, ny);
|
||||||
had = remove_snake(had);
|
had = remove_snake(had);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user