运行结果:
- 11 -
心得:
附录:
#include\
#include\#include\#include
#pragma
import(__use_no_semihosting_swi)
const U32 NewGame_Button_ID = 100;
const U32 Pause_Button_ID = 101;
const U32 Left_Button_ID = 102;
const U32 Right_Button_ID = 103; const U32 Down_Button_ID = 104;
const U32 Rotate_Button_ID = 105; const U32 MainDraw_Wnd_ID = 110;
const U32 PieceDraw_Wnd_ID = 115; const U32 ScoreDraw_Wnd_ID = 120;
const int ROWCOUNT = 21;
const int COLCOUNT = 10;
U32 Chose_Color; U32 COLOR[10][20];
U32 Rand_Color(); int Shape = 7; PDC pdc; structRECT NewGame_Button_RECT, Pause_Button_RECT, Left_Button_RECT, Right_Button_RECT, Down_Button_RECT, Rotate_Button_RECT, MainDraw_Wnd_RECT, PieceDraw_Wnd_RECT, ScoreDraw_Wnd_RECT;
structRECT *pNewGame_Button_RECT, *pPause_Button_RECT, *pLeft_Button_RECT, *pRight_Button_RECT,
- 12 -
*pDown_Button_RECT, int LastX, LastY, *pRotate_Button_RECT, LastAngle, score = 0, *pMainDraw_Wnd_RECT, delay = 500; int BlockInfo[7][4][4][2]= *pPieceDraw_Wnd_RECT, { *pScoreDraw_Wnd_RECT; int BoardArray[10][20]; //定义一个10x20的游戏区域 BOOLEAN boardinitialized = FALSE, StillRunning = TRUE; BOOLEAN Paused = FALSE, kludgeflag = FALSE, forceredraw = FALSE, GameOver = FALSE; int CurrentBlockX =0, CurrentBlockY =0, CurrentBlockColour =0, CurrentBlockShape, CurrentBlockAngle; int NextBlockX =0, NextBlockY =0, NextBlockColour =0, NextBlockShape, NextBlockAngle;
- 13 -
{ {{0,0},{1,0},{0,1},{1,1}}, {{0,0},{1,0},{0,1},{1,1}}, {{0,0},{1,0},{0,1},{1,1}}, {{0,0},{1,0},{0,1},{1,1}} }, { {{0,0},{-1,0},{0,1},{0,-1}}, {{0,0},{0,1},{1,0},{0,-1}}, {{0,0},{0,1},{1,0},{-1,0}}, {{0,0},{1,0},{0,-1},{-1,0}} }, { {{0,0},{-1,0},{1,0},{2,0}}, {{0,0},{0,-1},{0,1},{0,2}}, {{0,0},{-1,0},{1,0},{2,0}}, {{0,0},{0,-1},{0,1},{0,2}} }, { {{0,0},{0,-1},{0,1},{1,1}}, {{0,0},{1,0},{-1,0},{-1,1}}, {{0,0},{0,1},{0,-1},{-1,-1}}, {{0,0},{-1,0},{1,0},{1,-1}} }, { {{0,0},{0,-1},{0,1},{-1,1}}, {{0,0},{1,0},{-1,0},{-1,-1}}, {{0,0},{0,1},{0,-1},{1,-1}}, {{0,0},{-1,0},{1,0},{1,1}} }, { {{0,0},{-1,0},{0,-1},{1,-1}}, {{0,0},{0,-1},{1,0},{1,1}}, {{0,0},{-1,0},{0,-1},{1,-1}}, {{0,0},{0,-1},{1,0},{1,1}}, }, {
{{0,0},{1,0},{0,-1},{-1,-1}}, #define AutoDrop_Task_Prio {{0,0},{0,1},{1,0},{1,-1}}, 20 {{0,0},{1,0},{0,-1},{-1,-1}}, {{0,0},{0,1},{1,0},{1,-1}}, OS_EVENT *Nand_Rw_Sem; } OS_EVENT *Uart_Rw_Sem; }; /***********************************/ void Led_Flash_Task(void*Id) int update(void); { int DrawMainFrame(PDC); unsigned char led_state; int SetScoreText(PDC); Uart_Printf(0,\int dopaint(PDC); for(;;) int realdopaint(PDC); { BOOLEAN newGame(void); Led_Display(led_state); BOOLEAN pause(void); led_state=~led_state; BOOLEAN moveLeft(void); OSTimeDly(250); BOOLEAN moveRight(void); } BOOLEAN drop(void); } BOOLEAN rotateClockwise(void); void initOSGUI() int CheckRow(PDC); { int makeNewPiece(void); initOSMessage(); int DisplayPiece(PDC); initOSList(); int getPieceColour(void); initOSDC(); int getPieceX(int); initOSCtrl(); int getPieceY(int); initOSFile(); } extern U8 isConfigsysLoad; extern U8 sysCONFIG[]; int main(void) extern U32 ConfigSYsdata[]; { ARMTargetInit(); OS_STK Main_Stack[STACKSIZE*8] OSInit(); ={0,}; uHALr_ResetMMU(); void Main_Task(void*Id); LCD_Init(); #define Main_Task_Prio LCD_printf(\12 is OK\\n\ LCD_printf(\Text OS_STK Led_Flash_Stack[STACKSIZE] Mode\\n\ ={0,};//LED闪烁任务 initOSGUI(); void Led_Flash_Task(void*Id); LoadFont(); #define Led_Flash_Prio 56 LoadConfigSys(); LCD_printf(\task on OS_STK uc/os-Ⅱ...\\n\AutoDrop_Task_Stack[STACKSIZE*8] ={0,}; OSTaskCreate(Main_Task,(voidvoid AutoDrop_Task(void*Id); *)0,(OS_STK*)&Main_Stack[STACKSIZE
- 14 -
*8-1], Main_Task_Prio); OSTaskCreate(Led_Flash_Task,(void*)0,(OS_STK*)&Led_Flash_Stack[STACKSIZE-1], Led_Flash_Prio); OSTaskCreate(AutoDrop_Task,(void*)0,(OS_STK*)&AutoDrop_Task_Stack[STACKSIZE-1], AutoDrop_Task_Prio); OSAddTask_Init(); LCD_printf(%uc/os-Ⅱ...\\n\ LCD_printf(\graph mode...\\n\ LCD_ChangeMode(DspGraMode); InitRtc(); Nand_Rw_Sem=OSSemCreate(1); OSStart(); return 0; }
void onKey(int nkey,int fnkey) { switch(nkey) { case 0: newGame(); return; case 1: pause(); return; case 4: moveLeft(); return; case 6: moveRight(); return;
case 9:
drop(); return; case 5: rotateClockwise(); return; default: return; } }
/**************************/ void Main_Task(void*Id) { POSMSG pMsg; structPOINT Touch_Position,*pTouch_Position; ButtonCtrl NewGame_Button,Pause_Button,Left_Button, Right_Button,Down_Button,Rotate_Button; PButtonCtrl pNewGame_Button,pPause_Button,pLeft_Button, pRight_Button,pDown_Button,pRotate_Button; Wnd
MainDraw_Wnd,PieceDraw_Wnd,ScoreDraw_Wnd; PWnd
pMainDraw_Wnd,pPieceDraw_Wnd,pScoreDraw_Wnd; char NewGame_Button_Caption_8[]=\ char Pause_Button_Caption_8[]=\ause\ char
- 15 -