fix bug in snake (bsp/simulator) with patch by provided by Romeo(xeonrun@@gmail.com)
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2444 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
90c3859e32
commit
6a8ac7814c
|
@ -10,7 +10,7 @@
|
|||
}while(0)
|
||||
|
||||
rt_list_t snake_head;
|
||||
SNAKE_DIR prevdir;
|
||||
SNAKE_DIR prevdir, newdir;
|
||||
|
||||
static SNAKE_DIR dir_adjust(SNAKE_DIR dir)
|
||||
{
|
||||
|
@ -20,14 +20,14 @@ static SNAKE_DIR dir_adjust(SNAKE_DIR dir)
|
|||
|| (SNAKE_DIR_RIGHT == prevdir && SNAKE_DIR_LEFT != dir)
|
||||
)
|
||||
{
|
||||
prevdir = dir;
|
||||
newdir = dir;
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("dirction change error\n\r");
|
||||
}
|
||||
|
||||
return prevdir;
|
||||
return newdir;
|
||||
}
|
||||
|
||||
static void across_XY(point_t *node, const map_t *map)
|
||||
|
@ -77,6 +77,10 @@ static SYS_STE node_update(snake_t *tail, const point_t *node, map_t *map)
|
|||
}
|
||||
|
||||
map->range[node->y * map->width + node->x] = OVER;
|
||||
|
||||
if (ret != OVER)
|
||||
prevdir = newdir;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -324,11 +324,16 @@ static rt_bool_t event_handler(struct rtgui_object *object, rtgui_event_t *event
|
|||
static void timeout(struct rtgui_timer *timer, void *parameter)
|
||||
{
|
||||
struct rtgui_widget *widget;
|
||||
SYS_STE ret;
|
||||
|
||||
if (!map)
|
||||
return;
|
||||
|
||||
if (snake_step(run_state, map) == FOOD)
|
||||
ret = snake_step(run_state, map);
|
||||
if (OVER == ret)
|
||||
return;
|
||||
|
||||
if (FOOD == ret)
|
||||
{
|
||||
snake_len++;
|
||||
if (snake_len >= (map->width * map->height) / 3)
|
||||
|
|
Loading…
Reference in New Issue