#include "snake.h" #include struct snake* add_snake(struct snake* snake,int x,int y){ struct snake* head = calloc(1,sizeof(struct snake)); 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* curent_element = snake; struct snake* previous_element; while(curent_element->next != NULL){ previous_element=curent_element; curent_element = curent_element->next; } free(curent_element); if(curent_element==snake){ return NULL; } previous_element->next=NULL; return snake; } void free_snake(struct snake* sn){ struct snake* current=sn; if(current==NULL){ return; } struct snake* next_element; while(current!=NULL){ next_element=current->next; free(current); current=next_element; } } int is_snake(struct snake* snake,int x,int y){ struct snake* current =snake; while(current!=NULL){ if(x==current->x&&y==current->y){ return 1; } current=current->next; } return 0; } int step_state(struct state* st){ int nx = (st->snake->x + st->sx); int ny = (st->snake->y + st->sy); return END_CONTINUE; }