summaryrefslogtreecommitdiff
path: root/snake.h
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-10-19 14:52:49 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-10-19 14:52:49 -0300
commitc100e56944590985ed8ecbdcbc5f0d27b6542767 (patch)
tree9488c54256350055ee15592a0a573b8c5e86ef91 /snake.h
parenta38868de0918da3979d2f7115f9164c979a48346 (diff)
feat:the game
Kinda forgot commit.
Diffstat (limited to 'snake.h')
-rw-r--r--snake.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/snake.h b/snake.h
index e69de29..a7439bb 100644
--- a/snake.h
+++ b/snake.h
@@ -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 */