47 lines
954 B
C
47 lines
954 B
C
#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) {
|
|
if (snake == NULL) {
|
|
return NULL;
|
|
}
|
|
struct snake* next = snake->next;
|
|
free(snake);
|
|
return next;
|
|
}
|
|
|
|
int is_snake(struct snake* snake, int x, int y) {
|
|
while (snake != NULL) {
|
|
if (snake->x == x && snake->y == y) {
|
|
return 1;
|
|
}
|
|
snake = snake->next;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|