2012-11-23 21:40:31 +08:00
|
|
|
|
#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;
|
2012-12-27 16:26:35 +08:00
|
|
|
|
} point_t;
|
2012-11-23 21:40:31 +08:00
|
|
|
|
|
|
|
|
|
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];
|
2012-12-27 16:26:35 +08:00
|
|
|
|
} map_t;
|
2012-11-23 21:40:31 +08:00
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
SNAKE_DIR_UP,
|
|
|
|
|
SNAKE_DIR_DOWN,
|
|
|
|
|
SNAKE_DIR_LEFT,
|
|
|
|
|
SNAKE_DIR_RIGHT
|
2012-12-27 16:26:35 +08:00
|
|
|
|
} SNAKE_DIR;
|
2012-11-23 21:40:31 +08:00
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
FOOD, // <20>Ե<EFBFBD>ˮ<EFBFBD><CBAE>
|
|
|
|
|
OVER, // ҧ<><D2A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
NORMAL // <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
2012-12-27 16:26:35 +08:00
|
|
|
|
} SYS_STE;
|
2012-11-23 21:40:31 +08:00
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
point_t body;
|
|
|
|
|
rt_list_t list;
|
2012-12-27 16:26:35 +08:00
|
|
|
|
} snake_t;
|
2012-11-23 21:40:31 +08:00
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ͼ
|
2012-12-27 16:26:35 +08:00
|
|
|
|
map_t *map_init(rt_uint32_t width, rt_uint32_t heigth);
|
2012-11-23 21:40:31 +08:00
|
|
|
|
|
|
|
|
|
// <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
|