Aktualizovat du4 /snake.c

This commit is contained in:
Tomáš Vlček 2026-04-15 18:44:56 +00:00
parent 47ac20e4b6
commit 4cefc5a5a6

View File

@ -1,8 +1,21 @@
#include "snake.h"
#include <stdlib.h>
struct snake* add_snake(struct snake* snake,int x,int y){
return NULL;
struct snake* add_snake(struct snake* snake,int x,int y)
{
if (snake == NULL)
{
return NULL;
}
//pomocna smernikova premenna
struct snake* currentPtr = snake;
while (currentPtr != NULL)
{
//uloz dalsiu cast
struct snake* nextPtr = currentPtr->next;
free(currentPtr);
currentPtr = nextPtr;
}
}
struct snake* remove_snake(struct snake* snake){
@ -11,7 +24,15 @@ struct snake* remove_snake(struct snake* snake){
void free_snake(struct snake* sn)
{
//pomocna pointer premanna
struct snake* currentPtr = sn;
while (currentPtr != NULL)
{
//uloz dalsiu cast
struct snake* nextPtr = currentPtr->next;
free(currentPtr);
currentPtr = nextPtr;
}
}
int is_snake(struct snake* snake,int x,int y){