update tetris module

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@942 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
qiuyiuestc 2010-09-24 07:56:37 +00:00
parent c217605bef
commit cf2d8031cf
3 changed files with 26 additions and 28 deletions

View File

@ -12,34 +12,19 @@
* 2010-08-28 Yi.Qiu the first version
*/
/**
* @addtogroup LM3S
*/
/*@{*/
#include <rtthread.h>
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_server.h>
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/workbench.h>
extern void tetris_ui_entry(void* parameter);
#include "tetris.h"
int rt_application_init()
{
rt_thread_t tid;
rtgui_rect_t rect;
/* ×¢²áÃæ°å */
rect.x1 = 0;
rect.y1 = 0;
rect.x2 = 240;
rect.y2 = 320;
rtgui_panel_register("main", &rect);
rtgui_panel_set_default_focused("main");
tid = rt_thread_create("wb", tetris_ui_entry, RT_NULL, 2048, 20, 5);
if (tid != RT_NULL) rt_thread_startup(tid);
return 0;
}
/*@}*/

View File

@ -57,3 +57,5 @@
rt_tetris_view_t* rt_tetris_view_create(void* private);
rt_err_t rt_tetris_view_destroy(rt_tetris_view_t* thiz);
rt_err_t tetris_ui_entry(void* parameter);

View File

@ -26,7 +26,6 @@
struct app_info
{
struct rtgui_view* home_view;
struct rtgui_view* info_view;
struct rtgui_workbench* workbench;
rt_tetris_t * tetris;
rt_tetris_view_t* tetris_view;
@ -35,6 +34,17 @@ struct app_info
typedef struct app_info app_info;
static app_info g_app_info;
static void _game_over(void)
{
rtgui_timer_stop(g_app_info._timer);
rt_tetris_pause(g_app_info.tetris);
rt_tetris_destory(g_app_info.tetris);
rt_tetris_view_destroy(g_app_info.tetris_view);
rtgui_view_destroy(g_app_info.home_view);
rtgui_workbench_destroy(g_app_info.workbench);
rt_kprintf("GAME OVER\n");
}
static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
if (event->type == RTGUI_EVENT_PAINT)
@ -90,9 +100,7 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg
if( rt_tetris_drop(g_app_info.tetris) == -RT_ETIMEOUT
&& rt_tetris_status(g_app_info.tetris) != RT_FALSE)
{
rt_kprintf("GAME OVER\n");
rtgui_timer_stop(g_app_info._timer);
rt_tetris_pause(g_app_info.tetris);
_game_over();
}
}
}
@ -105,10 +113,7 @@ static void _timer_timeout(rtgui_timer_t* timer, void* parameter)
{
if( rt_tetris_down(g_app_info.tetris) == -RT_ETIMEOUT)
{
rt_kprintf("GAME OVER\n");
rtgui_timer_stop(g_app_info._timer);
rt_tetris_destory(g_app_info.tetris);
rt_tetris_view_destroy(g_app_info.tetris_view);
_game_over();
}
}
@ -132,7 +137,7 @@ static rt_bool_t workbench_event_handler(rtgui_widget_t *widget, rtgui_event_t *
return rtgui_workbench_event_handler(widget, event);
}
void tetris_ui_entry(void* parameter)
rt_err_t tetris_ui_entry(void* parameter)
{
rt_mq_t mq;
@ -140,7 +145,11 @@ void tetris_ui_entry(void* parameter)
rtgui_thread_register(rt_thread_self(), mq);
g_app_info.workbench = rtgui_workbench_create("main", "workbench");
if (g_app_info.workbench == RT_NULL) return;
if (g_app_info.workbench == RT_NULL)
{
rt_kprintf("can't find panel 'main'\n");
return -RT_ERROR;
}
rtgui_widget_set_event_handler(RTGUI_WIDGET(g_app_info.workbench), workbench_event_handler);
/* add home view */
@ -171,5 +180,7 @@ void tetris_ui_entry(void* parameter)
rtgui_thread_deregister(rt_thread_self());
rt_mq_delete(mq);
return RT_EOK;
}