domaca_uloha_7
This commit is contained in:
parent
220b417b95
commit
4d74b16736
12
du7/snake.c
12
du7/snake.c
@ -2,14 +2,14 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
struct snake* add_snake(struct snake* snake,int x,int y){
|
struct snake* add_snake(struct snake* snake,int x,int y){
|
||||||
struct snake* novyZaciatok = calloc(1, sizeof(struct snake)); //alokujem pamäť smerníka
|
struct snake* novyZaciatok = calloc(1, sizeof(struct snake)); //alokujem pamäť smerníka
|
||||||
novyZaciatok->x = x; //nastavím súradnice hada
|
novyZaciatok->x = x; //nastavím súradnice hada
|
||||||
novyZaciatok->y = y;
|
novyZaciatok->y = y;
|
||||||
|
|
||||||
if (snake != NULL) { //ak má had telo,
|
if (snake != NULL) { //ak má had telo,
|
||||||
novyZaciatok->next = snake; //tak mu iba pridám hlavu
|
novyZaciatok->next = snake; //tak mu iba pridám hlavu
|
||||||
} else {
|
} else {
|
||||||
novyZaciatok->next = NULL; //inak musím vytvoriť nové telo
|
novyZaciatok->next = NULL; //inak musím vytvoriť nové telo
|
||||||
}
|
}
|
||||||
|
|
||||||
return novyZaciatok;
|
return novyZaciatok;
|
||||||
@ -19,7 +19,7 @@ struct snake* remove_snake(struct snake* snake){
|
|||||||
if (snake == NULL) return NULL;
|
if (snake == NULL) return NULL;
|
||||||
|
|
||||||
struct snake* nasledujuci = calloc(1, sizeof(struct snake));
|
struct snake* nasledujuci = calloc(1, sizeof(struct snake));
|
||||||
nasledujuci = snake->next;
|
nasledujuci->next = snake->next;
|
||||||
free(snake);
|
free(snake);
|
||||||
|
|
||||||
return nasledujuci;
|
return nasledujuci;
|
||||||
|
Loading…
Reference in New Issue
Block a user