diff options
| author | qiuyiuestc <[email protected]> | 2010-09-24 07:56:37 +0000 |
|---|---|---|
| committer | qiuyiuestc <[email protected]> | 2010-09-24 07:56:37 +0000 |
| commit | cf2d8031cf1c0debae8f0ceef0765cbd8c1a3eba (patch) | |
| tree | b00b04012d685d81f1b3de71da154ff25d7a374b /components/module | |
| parent | c217605befa4f89c24b5fcc168289b963489e9d5 (diff) | |
update tetris module
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@942 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/module')
| -rw-r--r-- | components/module/tetris/application.c | 21 | ||||
| -rw-r--r-- | components/module/tetris/tetris.h | 2 | ||||
| -rw-r--r-- | components/module/tetris/tetris_ui.c | 31 |
3 files changed, 26 insertions, 28 deletions
diff --git a/components/module/tetris/application.c b/components/module/tetris/application.c index df25f1863e..4c684735cc 100644 --- a/components/module/tetris/application.c +++ b/components/module/tetris/application.c @@ -11,35 +11,20 @@ * Date Author Notes
* 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;
}
-/*@}*/
+
diff --git a/components/module/tetris/tetris.h b/components/module/tetris/tetris.h index 4085c8c0c5..e6f570d455 100644 --- a/components/module/tetris/tetris.h +++ b/components/module/tetris/tetris.h @@ -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);
+
diff --git a/components/module/tetris/tetris_ui.c b/components/module/tetris/tetris_ui.c index 419497036e..49c7a66619 100644 --- a/components/module/tetris/tetris_ui.c +++ b/components/module/tetris/tetris_ui.c @@ -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;
}
|
