-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnake.h
More file actions
53 lines (44 loc) · 970 Bytes
/
snake.h
File metadata and controls
53 lines (44 loc) · 970 Bytes
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 "move.h"
#include <unistd.h>
/**
* Data structure to represent a snake segment. Basically a node in a linked list.
*/
typedef struct Segment Segment;
struct Segment {
Direction direction;
int x_pos;
int y_pos;
Segment* next;
};
/**
* Data structure to represent a snake. Implemented as en enhanced linked list of Segment nodes.
*/
typedef struct Snake Snake;
struct Snake {
Segment* head;
Segment* end;
int length;
};
/**
* Create a new snake at the specified coordinates.
*/
Snake* new_snake(int x, int y);
/**
* Delete a snake and free the memory associated with it.
*/
void delete_snake(Snake* snake);
/**
* Adds a segment to the snake.
*/
void add_segment(Snake* snake);
/**
* Update direction of the snake based on the move stack.
*/
void update_direction(Snake* snake, MoveList* moves);
/**
* Moves each segment of the snake one step.
*/
void move_snake(Snake* snake);
#endif