📄 snake.h
字号:
/*
** snake.h
**
** Written by Peter Sutton - October 2004
**
** Details of the snake
*/
#include <inttypes.h>
/* Directions */
#define UP 0
#define RIGHT 1
#define DOWN 2
#define LEFT 3
/* Possible results of an attempt to move the snake */
#define OUT_OF_BOUNDS -1
#define COLLISION -2
#define MOVE_OK 1
#define ATE_FOOD 2
/* The type that we use for positions */
typedef struct {
unsigned char x;
unsigned char y;
} posn_type;
/*
** init_snake()
**
** Initialise the snake position.
*/
void init_snake(void);
/*
** get_snake_head_position()
**
** Returns the position of the head of the snake
*/
posn_type get_snake_head_position(void);
/* move_snake()
**
** Attempt to move the snake by one in the current direction.
** Returns -1 if the snake has run into the edge or itself,
** 0 if the move is successful, 1 if the snake has eaten
** some food (and grown). If the snake has too many bends
** (i.e. the move would create an extra element beyond
** our element array then any attempt to turn is rejected.
*/
int8_t move_snake(void);
/* set_snake_dirn(direction)
**
** Attempt to set snake direction to one of UP, DOWN,
** LEFT or RIGHT. Returns 1 if successful, 0 otherwise.
** (Will fail if try and reverse snake - OK to continue
** in same direction or turn 90degrees.)
*/
int8_t set_snake_dirn(int8_t dirn);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -