Изменить 'du7/snake.c'
This commit is contained in:
parent
228a3c4b9c
commit
be7fcb6486
18
du7/snake.c
18
du7/snake.c
@ -7,7 +7,7 @@ struct snake* add_snake(struct snake* snake,int x,int y){
|
||||
newHead-> = y;
|
||||
newHead->next = snake;
|
||||
|
||||
struct snake* temp = snake;
|
||||
/*struct snake* temp = snake;
|
||||
int myX, myY;
|
||||
|
||||
while(temp->next != NULL){
|
||||
@ -20,8 +20,8 @@ struct snake* add_snake(struct snake* snake,int x,int y){
|
||||
|
||||
//temp->next = (struct snake*) calloc(1, sizeof(struct snake));
|
||||
temp->next->x = temp->x - (myX - temp->x);
|
||||
temp->next->y = temp->y - (myY - temp->y);
|
||||
temp->next->next = NULL;
|
||||
temp->next->y = temp->y - (myX - temp->y);
|
||||
temp->next->next = NULL;*/
|
||||
|
||||
return newHead;
|
||||
}
|
||||
@ -46,6 +46,8 @@ void free_snake(struct snake* sn){
|
||||
sn = sn->next;
|
||||
temp->next = NULL;
|
||||
}
|
||||
|
||||
free(sn);
|
||||
}
|
||||
|
||||
int is_snake(struct snake* snake,int x,int y){
|
||||
@ -67,7 +69,7 @@ int step_state(struct state* st){
|
||||
|
||||
for(int i = 0; i < FOOD_COUNT; i++){
|
||||
if(nx == st->foodx[i] && ny == st->foody[i]){
|
||||
add_snake(st->snake, st->foodx[i], st->foody[i]);
|
||||
st->snake = add_snake(st->snake, st->foodx[i], st->foody[i]);
|
||||
st->foodx[i] = -1;
|
||||
st->foody[i] = -1;
|
||||
for(int j = 0; j < FOOD_COUNT; j++){
|
||||
@ -78,18 +80,18 @@ int step_state(struct state* st){
|
||||
return END_FOOD;
|
||||
}
|
||||
}
|
||||
return END_CONTINUE;
|
||||
}
|
||||
}
|
||||
|
||||
for(struct snake* temp = st->snake->next; temp != NULL; temp = temp->next){
|
||||
if(nx == temp->x && ny == temp->y){
|
||||
for(struct snake* temp = st->snake->next != NULL; temp = temp->next){
|
||||
if((nx == temp->x && ny == temp->y) || (nx < 0 || nx >= st->width || ny < 0 || ny >= st->height)){
|
||||
return END_SNAKE;
|
||||
}
|
||||
}
|
||||
|
||||
add_snake(st->snake, nx, ny);
|
||||
st->snake = add_snake(st->snake, nx, ny);
|
||||
remove_snake(st->snake);
|
||||
|
||||
return END_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user