This commit is contained in:
Filip Chochol 2026-03-31 19:40:08 +02:00
parent b2c01620ed
commit 5a63b053bd

View File

@ -6,12 +6,13 @@ struct snake* add_snake(struct snake* snake, int x, int y) {
nova_cast->x = x;
nova_cast->y = y;
nova_cast->next = snake;
return snake;
return nova_cast;
}
struct snake* remove_snake(struct snake* hlava) {
if (hlava == NULL) return NULL;
if (hlava->next == NULL) {
free(hlava);
return NULL;
}
hlava->next = remove_snake(hlava->next);
@ -20,7 +21,7 @@ struct snake* remove_snake(struct snake* hlava) {
int is_snake(struct snake* snake, int x, int y) {
for (struct snake* this = snake; this != NULL; this = this->next) {
if (this->x = x && this->y == y) return 1;
if (this->x == x && this->y == y) return 1;
}
return 0;
}
@ -28,6 +29,7 @@ int is_snake(struct snake* snake, int x, int y) {
void free_snake(struct snake* sn) {
if (sn == NULL) return;
free_snake(sn->next);
free(sn);
}
int step_state(struct state* st) {
@ -56,6 +58,6 @@ int step_state(struct state* st) {
}
st->snake = add_snake(st->snake, nova_x, nova_y);
remove_snake(st->snake);
st->snake = remove_snake(st->snake);
return END_CONTINUE;
}