summaryrefslogtreecommitdiff
path: root/snake.h
blob: a7439bbaa892f0bc57d8425446969396ca497d1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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 */