-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnake_backend.h
49 lines (40 loc) · 1.03 KB
/
snake_backend.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
/*
* snake_backend.h
*
* Created on: Jun 1, 2022
* Author: Piotr
*/
#ifndef SNAKE_BACKEND_H_
#define SNAKE_BACKEND_H_
#define SNAKE_START_LENGTH 4
#include <stdbool.h>
extern int points;
enum Direction {
UP, DOWN, LEFT, RIGHT
};
enum Status {
SUCC, FAILURE
};
struct PointList {
int x;
int y;
struct PointList* next;
};
typedef struct PointList PointList;
typedef struct {
PointList* snake;
PointList* foods;
int xmax;
int ymax;
} Board;
bool is_same_place(PointList* cell1, PointList* cell2);
enum Status move_snake(Board* board, enum Direction dir);
PointList* next_move(Board* board, enum Direction dir);
PointList* create_cell(int x, int y);
PointList* create_random_cell(int xmax, int ymax);
PointList* create_snake();
Board* create_board(PointList* foods, PointList* snake, int xmax, int ymax);
bool list_contains(PointList* cell, PointList* list);
bool remove_from_list(PointList* elt, PointList** list);
void add_new_food(Board* board);
#endif /* SNAKE_BACKEND_H_ */