submit1
This commit is contained in:
parent
14160f2884
commit
fe913763f6
60
cv9/snake.c
Normal file
60
cv9/snake.c
Normal file
@ -0,0 +1,60 @@
|
||||
#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->next!=NULL){
|
||||
next_element=current->next;
|
||||
free(current);
|
||||
current=next_element;
|
||||
}
|
||||
free(current);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user