-
Notifications
You must be signed in to change notification settings - Fork 12
/
snake.h
53 lines (40 loc) · 1.19 KB
/
snake.h
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
#ifndef SNAKE_H
#define SNAKE_H
#include "xymap.h"
#include <stdlib.h>
enum direction { North, South, East, West };
typedef struct SnakePart_ {
int x;
int y;
struct SnakePart_ *next;
struct SnakePart_ *prev;
} SnakePart;
typedef struct Snake_ {
SnakePart *head;
SnakePart *tail;
int direction;
int length;
int grow;
int collision;
short teleport;
short onWayToFood;
} Snake;
typedef struct point {
int x;
int y;
} Point;
SnakePart *snake_part_create(int x, int y, SnakePart *prev);
void snake_part_free(SnakePart *snakePart);
Snake *snake_create(int x, int y, int direction, short teleport);
Snake *snake_copy(Snake *sn);
void snake_free(Snake *snake);
void update_position(Snake *snake, XYMap *blocksTaken, Point *food, int dir,
int maxX, int maxY);
void update_position_autopilot(Snake *snake, XYMap *blocksTaken, Point *food,
int x, int y, int maxX, int maxY);
void check_collision(Snake *sn, XYMap *blocksTaken, int x, int y, int maxX,
int maxY);
int snake_cmp(Snake *sn1, Snake *sn2);
void rand_pos_food(Point *food, XYMap *blocksTaken, int maxX, int maxY);
Point *point_create(int x, int y);
#endif