This commit is contained in:
Tančáková 2024-04-08 15:23:28 +02:00
parent 9ec5ae06fe
commit cc37d791de

View File

@ -1,46 +1,21 @@
#include "snake.h"
#include <stdlib.h>
struct snake* add_snake(struct snake* snake, int x, int y) {
struct snake* head = (struct snake*)malloc(sizeof(struct snake));
if (head == NULL) {
return NULL;
}
head->x = x;
head->y = y;
head->next = snake;
return head;
}
struct snake* remove_snake(struct snake* snake) { struct snake* remove_snake(struct snake* snake) {
if (snake == NULL) { if (snake == NULL) {
return NULL; return NULL;
} }
struct snake* next = snake->next; struct snake* current = snake;
free(snake); struct snake* prev = NULL;
return next; while (current->next != NULL) {
} prev = current;
current = current->next;
int is_snake(struct snake* snake, int x, int y) { }
while (snake != NULL) { if (prev != NULL) {
if (snake->x == x && snake->y == y) { prev->next = NULL;
return 1; } else {
} // If prev is NULL, it means we are removing the head of the list
snake = snake->next; // and the new head will be the next node
} snake = NULL;
return 0; }
} free(current);
return snake;
void free_snake(struct snake* snake) {
while (snake != NULL) {
struct snake* next = snake->next;
free(snake);
snake = next;
}
}
int step_state(struct state* state) {
// Implement step_state function here
return END_CONTINUE;
} }