56 lines
1.2 KiB
C
56 lines
1.2 KiB
C
#include "snake.h"
|
|
#include <stdlib.h>
|
|
|
|
struct snake* add_snake(struct snake* snake,int x,int y)
|
|
{
|
|
//vytvor novu prazdnu instanciu a alokuj jej pamat
|
|
struct snake* newSnake = (struct snake*)malloc(sizeof(struct snake));
|
|
//prida X,Y suradnice do polia do novej hlavicky
|
|
newSnake->x = x;
|
|
newSnake->y = y;
|
|
|
|
//nalinkuje ju na staru hlavicku
|
|
newSnake->next = snake;
|
|
|
|
return newSnake;
|
|
}
|
|
|
|
struct snake* remove_snake(struct snake* snake){
|
|
return NULL;
|
|
}
|
|
|
|
void free_snake(struct snake* sn)
|
|
{
|
|
//pomocna smernikova premenna
|
|
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){
|
|
|
|
//helper pointer/smernikova premena
|
|
struct snake* currentPtr = snake;
|
|
|
|
while (currentPtr != NULL)
|
|
{
|
|
if (currentPtr->x == x && currentPtr->y == y)
|
|
{
|
|
return 1;
|
|
}
|
|
//prejdi na dalsiu cast
|
|
currentPtr = currentPtr->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;
|
|
} |