domaca_uloha_7

This commit is contained in:
Tomáš Vasiľ 2022-04-27 20:33:02 +02:00
parent 1f52f19175
commit ad74267726

View File

@ -62,5 +62,41 @@ int is_snake(struct snake* snake,int x,int y){
int step_state(struct state* st){ int step_state(struct state* st){
int nx = (st->snake->x + st->sx); int nx = (st->snake->x + st->sx);
int ny = (st->snake->y + st->sy); int ny = (st->snake->y + st->sy);
int i, pocetJedal = FOOD_COUNT;
struct snake* had = calloc(1, sizeof(struct snake));
struct snake* hlava = calloc(1, sizeof(struct snake));
had = st->snake;
hlava = st->snake;
while (had != NULL) {
if (snake->x == nx || snake->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]);
foodx[i] = -1;
foody[i] = -1;
pocetJedal--;
}
}
}
if (pocetJedal == 0) return END_FOOD;
}
had = hlava;
free(hlava);
if (nx > 0 && nx < width) {
if (ny > 0 && ny < height) {
had = add_snake(had, nx, ny);
had = remove_snake(had);
}
}
return END_CONTINUE; return END_CONTINUE;
} }