提交 6a8ac781 编写于 作者: G goprife@gmail.com

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
上级 90c3859e
......@@ -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)
......@@ -350,7 +355,7 @@ static void timeout(struct rtgui_timer *timer, void *parameter)
food_init(map, 1);
}
widget = RTGUI_WIDGET(parameter);
snake_update(widget);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册