2023-12-06 14:57:12 +00:00
|
|
|
#ifndef SERPENT_H
|
|
|
|
#define SERPENT_H
|
|
|
|
|
2023-12-08 09:02:48 +00:00
|
|
|
/* Program information */
|
2023-12-06 14:57:12 +00:00
|
|
|
#define NAME "serpent"
|
|
|
|
#define VERSION 0.1
|
|
|
|
/* */
|
|
|
|
|
2023-12-07 16:08:32 +00:00
|
|
|
/* Absolute value macro */
|
|
|
|
#define ABS(x) (x) < 0 ? -(x) : (x)
|
|
|
|
/* */
|
|
|
|
|
2023-12-07 23:33:25 +00:00
|
|
|
/* Global variables/constants */
|
|
|
|
#define START_SNAKE_SIZE 5 /* snake's initial size */
|
2023-12-06 14:57:12 +00:00
|
|
|
#define SNAKE_BODY '*' /* snake's body */
|
|
|
|
#define SNAKE_HEAD_U 'v' /* head when going up */
|
|
|
|
#define SNAKE_HEAD_D '^' /* head when going down */
|
|
|
|
#define SNAKE_HEAD_L '>' /* head when going left */
|
|
|
|
#define SNAKE_HEAD_R '<' /* head when going right */
|
|
|
|
#define FOOD '@' /* normal food */
|
2023-12-08 09:02:48 +00:00
|
|
|
#define SCREEN_WIDTH 50 /* the virtual screen width */
|
|
|
|
#define SCREEN_HEIGHT 20 /* the virtual screen height */
|
2023-12-06 14:57:12 +00:00
|
|
|
/* */
|
|
|
|
|
2023-12-08 09:02:48 +00:00
|
|
|
/* Possible directions for the snake */
|
|
|
|
typedef enum {
|
|
|
|
UP,
|
|
|
|
DOWN,
|
|
|
|
LEFT,
|
|
|
|
RIGHT
|
|
|
|
} Direction;
|
2023-12-06 14:57:12 +00:00
|
|
|
|
2023-12-07 23:33:25 +00:00
|
|
|
/* Snake node structure (for dobly linked list) */
|
2023-12-08 09:02:48 +00:00
|
|
|
typedef struct SnakeNode {
|
2023-12-07 23:33:25 +00:00
|
|
|
int pX, pY; /* represents the node's position on the board */
|
2023-12-08 09:02:48 +00:00
|
|
|
struct SnakeNode *next, *prev; /* pointers to the next and previous nodes */
|
|
|
|
} SnakeNode;
|
2023-12-06 14:57:12 +00:00
|
|
|
|
2023-12-07 23:33:25 +00:00
|
|
|
/* Snake structure (dobly linked list) */
|
2023-12-08 09:02:48 +00:00
|
|
|
typedef struct Snake {
|
|
|
|
Direction direction;
|
|
|
|
SnakeNode *head, *tail; /* snake's nodes, dobly linked list */
|
|
|
|
} Snake;
|
2023-12-06 14:57:12 +00:00
|
|
|
|
2023-12-07 23:33:25 +00:00
|
|
|
/* Apple structure */
|
2023-12-08 09:02:48 +00:00
|
|
|
typedef struct Food {
|
2023-12-07 23:33:25 +00:00
|
|
|
int pX, pY; /* represents the apple's position on the board */
|
2023-12-08 09:02:48 +00:00
|
|
|
} Apple;
|
2023-12-06 14:57:12 +00:00
|
|
|
|
|
|
|
#endif //SERPENT_H
|