pvjc24/cv9/snake.c

47 lines
954 B
C
Raw Normal View History

2024-04-08 13:20:22 +00:00
#include "snake.h"
2024-04-08 13:14:43 +00:00
#include <stdlib.h>
struct snake* add_snake(struct snake* snake, int x, int y) {
2024-04-08 13:16:50 +00:00
struct snake* head = (struct snake*)malloc(sizeof(struct snake));
if (head == NULL) {
return NULL;
2024-04-08 13:14:43 +00:00
}
2024-04-08 13:16:50 +00:00
head->x = x;
head->y = y;
head->next = snake;
return head;
2024-04-08 13:14:43 +00:00
}
struct snake* remove_snake(struct snake* snake) {
if (snake == NULL) {
2024-04-08 13:16:50 +00:00
return NULL;
2024-04-08 13:14:43 +00:00
}
2024-04-08 13:16:50 +00:00
struct snake* next = snake->next;
2024-04-08 13:14:43 +00:00
free(snake);
2024-04-08 13:16:50 +00:00
return next;
2024-04-08 13:14:43 +00:00
}
int is_snake(struct snake* snake, int x, int y) {
while (snake != NULL) {
if (snake->x == x && snake->y == y) {
2024-04-08 13:16:50 +00:00
return 1;
2024-04-08 13:14:43 +00:00
}
snake = snake->next;
}
return 0;
}
2024-04-08 13:16:50 +00:00
void free_snake(struct snake* snake) {
while (snake != NULL) {
struct snake* next = snake->next;
free(snake);
snake = next;
2024-04-08 13:14:43 +00:00
}
}
2024-04-08 13:20:22 +00:00
int step_state(struct state* state) {
// Implement step_state function here
return END_CONTINUE;
2024-04-08 13:16:50 +00:00
}