odmazat chvost
This commit is contained in:
parent
82bb5222c8
commit
41ea365d44
16
du4/snake.c
16
du4/snake.c
@ -15,7 +15,21 @@ struct snake* add_snake(struct snake* snake,int x,int y){
|
||||
}
|
||||
|
||||
struct snake* remove_snake(struct snake* snake){
|
||||
return NULL;
|
||||
|
||||
struct snake* clanok = snake;
|
||||
|
||||
if (snake -> next == NULL) {
|
||||
free(snake);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (clanok -> next -> next != NULL) { // posuvam sa po hadovi kym nenajdem koniec chvosta ktory odmazem
|
||||
clanok = clanok -> next;
|
||||
}
|
||||
|
||||
free (clanok -> next); //po tom co som nasiel kde je koniec, odmazem koniec chvosta a korunujem nasledujuci clanok novym koncom
|
||||
clanok -> next = NULL;
|
||||
return snake; //kedze som menil snaka podla referenciam v pamati, mozem vratit noveho stareho hada
|
||||
}
|
||||
|
||||
void free_snake(struct snake* sn){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user