rtt-f030/bsp/simulator/testdll/snake/snake.h

69 lines
1.4 KiB
C
Raw Normal View History

#ifndef _SNAKE_H_
#define _SNAKE_H_
#include <rtthread.h>
#define snake_length_max 20 //<2F><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
#define snake_length_init 3 //<2F><>ʼ<EFBFBD><CABC><EFBFBD>߳<EFBFBD>
#define snake_room_size_hight 8 //<2F><><EFBFBD>Ӹ<EFBFBD> 0-255 <20><><EFBFBD><EFBFBD>>8
#define snake_room_size_widht 8 //<2F><><EFBFBD>ӿ<EFBFBD> 0-255 <20><><EFBFBD><EFBFBD>>8
#define snake_init_pointx 1
#define snake_init_pointy 2
typedef struct
{
rt_int32_t x, y;
} point_t;
typedef struct
{
rt_int32_t width; // max x
rt_int32_t height; // max y
rt_uint8_t *range; // map, map->range[y * map->width + x]
point_t snake_flush[2];
point_t food_flush[1];
} map_t;
typedef enum
{
SNAKE_DIR_UP,
SNAKE_DIR_DOWN,
SNAKE_DIR_LEFT,
SNAKE_DIR_RIGHT
} SNAKE_DIR;
typedef enum
{
FOOD, // <20>Ե<EFBFBD>ˮ<EFBFBD><CBAE>
OVER, // ҧ<><D2A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
NORMAL // <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
} SYS_STE;
typedef struct
{
point_t body;
rt_list_t list;
} snake_t;
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ͼ
map_t *map_init(rt_uint32_t width, rt_uint32_t heigth);
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>
rt_bool_t snake_init(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʳ<EFBFBD><CAB3>
rt_bool_t food_init(map_t *map, rt_uint32_t max_num);
void map_deinit(map_t *map);
void snake_deinit(void);
void food_deinit(void);
SYS_STE snake_step(SNAKE_DIR dir, map_t *map);
rt_bool_t snake_restart(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map);
#endif