diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-10-19 14:52:49 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-10-19 14:52:49 -0300 |
| commit | c100e56944590985ed8ecbdcbc5f0d27b6542767 (patch) | |
| tree | 9488c54256350055ee15592a0a573b8c5e86ef91 /snake.h | |
| parent | a38868de0918da3979d2f7115f9164c979a48346 (diff) | |
feat:the game
Kinda forgot commit.
Diffstat (limited to 'snake.h')
| -rw-r--r-- | snake.h | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -0,0 +1,54 @@ +#ifndef SNAKE_H +#define SNAKE_H + +#include <stdbool.h> +#include <stddef.h> + +typedef enum Direction { + NORTH, + WEST, + EAST, + SOUTH +} Direction; + +typedef struct Point { + unsigned int x; + unsigned int y; +} Point; + +typedef struct PointList { + Point point; + struct PointList *next; +} PointList; + +typedef struct Snake { + PointList *head; + PointList *tail; + size_t length; + Direction moving_direction; +} Snake; + +typedef struct Map { + Point fruit; + Snake *snake; + bool fruit_eaten; + unsigned int height; + unsigned int width; +} Map; + +Snake *create_snake(unsigned int x, unsigned int y, Direction direction); + +Map *create_map(unsigned int width, unsigned int height); + +/* Attempts to move the snake. + * Returns true if the snake sucessfully moved, + * false for game over. + */ +bool move_snake(Map *map); + +/* Frees the snake */ +void free_snake(Snake *snake); + +void free_map(Map *map); + +#endif /* SNAKE_H */ |
