61 lines
1.2 KiB
C
61 lines
1.2 KiB
C
#include "snake.h"
|
|
#include <stdlib.h>
|
|
|
|
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;
|
|
while(curent_element->next != NULL){
|
|
curent_element = curent_element->next;
|
|
}
|
|
|
|
free(curent_element);
|
|
|
|
if(curent_element==snake){
|
|
return 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;
|
|
}
|
|
|