Files
player/Project_App_Snake/App_Src/calc/snake.h
2025-07-05 19:47:28 +08:00

88 lines
1.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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