88 lines
1.5 KiB
C
88 lines
1.5 KiB
C
|
#ifndef SNAKE_H__
|
|||
|
#define SNAKE_H__
|
|||
|
|
|||
|
#include "main_inc.h"
|
|||
|
#include "global.h"
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//定义格子类型
|
|||
|
#define CELL_TYPE_AIR 0
|
|||
|
#define CELL_TYPE_WALL 1
|
|||
|
#define CELL_TYPE_HEAD 2
|
|||
|
#define CELL_TYPE_BODY 3
|
|||
|
#define CELL_TYPE_FOOD 4
|
|||
|
|
|||
|
|
|||
|
//定义地图尺寸,最大254*254
|
|||
|
#define MAP_X_SIZE 25
|
|||
|
#define MAP_Y_SIZE 25
|
|||
|
|
|||
|
|
|||
|
//定义贪吃蛇前进方向
|
|||
|
#define DIR_RIGHT 1
|
|||
|
#define DIR_LEFT 2
|
|||
|
#define DIR_UP 3
|
|||
|
#define DIR_DOWN 4
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//定义每个格子的属性
|
|||
|
typedef struct
|
|||
|
{
|
|||
|
u8 type;
|
|||
|
u8 next_x;
|
|||
|
u8 next_y;
|
|||
|
}cell_struct;
|
|||
|
|
|||
|
|
|||
|
//定义贪吃蛇类
|
|||
|
typedef struct
|
|||
|
{
|
|||
|
cell_struct map[MAP_X_SIZE*MAP_Y_SIZE];
|
|||
|
int wall_num;//墙的个数
|
|||
|
int mark; //分数,吃了多少食物
|
|||
|
int dir; //贪吃蛇前进方向
|
|||
|
|
|||
|
u8 head_x; //这里保存头部坐标加快运算速度
|
|||
|
u8 head_y;
|
|||
|
u8 tail_x;
|
|||
|
u8 tail_y;
|
|||
|
|
|||
|
}snak_struct;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//创建一个贪吃蛇类
|
|||
|
snak_struct *snake_creat(void);
|
|||
|
|
|||
|
//初始化
|
|||
|
void snake_init(snak_struct *s);
|
|||
|
|
|||
|
//删除一个贪吃蛇类
|
|||
|
void snake_delete(snak_struct *s);
|
|||
|
|
|||
|
//生成新的食物,返回1,生成了食物,0,找不到地方生成食物了,游戏结束
|
|||
|
int snake_food(snak_struct *s);
|
|||
|
|
|||
|
//贪吃蛇前进一步,1,成功,0,失败
|
|||
|
int snake_forward(snak_struct *s);
|
|||
|
|
|||
|
//蛇生长,吃到了食物,返回1,成功
|
|||
|
int snake_grow(snak_struct *s);
|
|||
|
|
|||
|
//找到新的尾部,返回1,成功,0,失败
|
|||
|
int snake_find_tail_new(snak_struct *s);
|
|||
|
|
|||
|
//运行,返回0,游戏结束
|
|||
|
int snake_run(snak_struct *s);
|
|||
|
|
|||
|
//设置前进方向
|
|||
|
int snake_set_dir(snak_struct *s,int dir);
|
|||
|
|
|||
|
|
|||
|
#endif
|
|||
|
|