?? timerapp.c
字號(hào):
/*===========================================================================
FILE: TimerApp.c
===========================================================================*/
/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "Fan.h" // Shell interface definitions
#include "AEEFile.h"
#include "string_res.h"
#include "TimerApp.bid"
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
//#define AEECLSID_TIMERAPP 0x0100FF02
#define AEECLSID_ALARMAPP 0x0100FF03
//static boolean AlarmApp_HandleEvent(IApplet *pi, AEEEvent eCode,uint16 wParam, uint32 dwParam);
static void TimerApp_FreeAppData(IApplet* pMe) {}
//static void AlarmApp_FreeAppData(IApplet* pMe) {}
/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */
/*===========================================================================
FUNCTION: AEEClsCreateInstance
DESCRIPTION
This function is invoked while the app is being loaded. All Modules must provide this
function. Ensure to retain the same name and parameters for this function.
In here, the module must verify the ClassID and then invoke the AEEApplet_New() function
that has been provided in AEEAppGen.c.
After invoking AEEApplet_New(), this function can do app specific initialization. In this
example, a generic structure is provided so that app developers need not change app specific
initialization section every time except for a call to IDisplay_InitAppData().
This is done as follows: InitAppData() is called to initialize AppletData
instance. It is app developers responsibility to fill-in app data initialization
code of InitAppData(). App developer is also responsible to release memory
allocated for data contained in AppletData -- this can be done in
IDisplay_FreeAppData().
PROTOTYPE:
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
PARAMETERS:
clsID: [in]: Specifies the ClassID of the applet which is being loaded
pIShell: [in]: Contains pointer to the IShell object.
pIModule: pin]: Contains pointer to the IModule object to the current module to which
this app belongs
ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
of memory for this structure and initializing the base data members is done by AEEApplet_New().
DEPENDENCIES
none
RETURN VALUE
AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
successful
EFAILED: If the app does not need to be loaded or if errors occurred in
AEEApplet_New(). If this function returns FALSE, the app will not be loaded.
SIDE EFFECTS
none
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
*ppObj = NULL;
if(ClsId == AEECLSID_TIMERAPP)
{
if(AEEApplet_New(sizeof(TimerApp), ClsId, pIShell,po,(IApplet**)ppObj,
(AEEHANDLER)TimerApp_HandleEvent,(PFNFREEAPPDATA)TimerApp_FreeAppData)
== TRUE)
{
// Add your code here .....
if(TimerApp_InitAppData((IApplet *)*ppObj))
return (AEE_SUCCESS);
else
{
*ppObj = NULL;
IAPPLET_Release((IApplet *)*ppObj);
return EFAILED;
}
}
}
return (EFAILED);
}
static boolean TimerApp_InitAppData(IApplet* po)
{
TimerApp * pMe = (TimerApp *)po;
AEEDeviceInfo * pDi;
// AEERect DeviceRect;
pDi = MALLOC(sizeof(AEEDeviceInfo));
if(!pDi)
return FALSE;
ISHELL_GetDeviceInfo(pMe->a.m_pIShell,pDi);
pMe->pIDisplay = pMe->a.m_pIDisplay;
pMe->pIShell = pMe->a.m_pIShell;
pMe->window = SPRITE_MENU;
pMe->cx = pDi->cxScreen;
pMe->cy = pDi->cyScreen;
pMe->keyPressed = 0;
pMe->isPaused = 0;
pMe->timerValue = 1000;
pMe->temp = 0;
pMe->count = 0;
FREEIF(pDi);
pMe->K = 0;
return TRUE;
}
void TimerCB(TimerApp * pMe)
{
//TimerApp * pMe = (TimerApp *) pv;
int a;
// pMe->timerValue = 1000; //可以控制游戲速度
pMe->Y=1; //當(dāng)ispuased=1時(shí) 只響應(yīng)AVK_SOFT2;
if(pMe->K && !(pMe->isPaused))
{
if(Isbottom(pMe))
{
pMe->flag=1;
clean(pMe);
pMe->R=pMe->R+2;
for(a=0;a<4;a++)
{
pMe->aa[a].x++;
}
myDraw(pMe);
}
else if(pMe->K)
{
//pMe->timerValue = 1000;
//pMe->count++;
//displayScore(pMe);
Star(pMe);
Isover(pMe);
pMe->flag=1;
}
}
pMe->Y=0;
ISHELL_SetTimer(pMe->a.m_pIShell,pMe->timerValue,TimerCB,(void *)pMe);
IDISPLAY_Update(pMe->a.m_pIDisplay);
}
/*===========================================================================
FUNCTION TimerApp_HandleEvent
DESCRIPTION
This is the EventHandler for this app. All events to this app are handled in this
function. All APPs must supply an Event Handler.
PROTOTYPE:
boolean TimerApp_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
PARAMETERS:
pi: Pointer to the AEEApplet structure. This structure contains information specific
to this applet. It was initialized during the AEEClsCreateInstance() function.
ecode: Specifies the Event sent to this applet
wParam, dwParam: Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE: If the app has processed the event
FALSE: If the app did not process the event
SIDE EFFECTS
none
===========================================================================*/
static boolean TimerApp_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
TimerApp * pMe = (TimerApp * )pi;
switch (eCode)
{
// App is told it is starting up
case EVT_APP_START:
// Add your code here...
if(SPRITE_MENU == pMe->window)
{
return TimeApp_EnterMenu(pMe);
}
else if(SPRITE_GAME == pMe->window)
{
return TimeApp_EnterGame(pMe);
}
else if (SPRITE_LEVEL == pMe->window)
{
return TimeApp_EnterLevel(pMe);
}
else if (SPRITE_OVER == pMe->window)
{
return TimeApp_EnterOver(pMe);
}
// App is told it is exiting
case EVT_APP_STOP:
// Add your code here...
if(SPRITE_MENU == pMe->window)
{
return TimeApp_ExitMenu(pMe);
}
else if(SPRITE_GAME == pMe->window)
{
return TimeApp_ExitGame(pMe);
}
else if (SPRITE_LEVEL == pMe->window)
{
return TimeApp_ExitLevel(pMe);
}
else if (SPRITE_OVER == pMe->window)
{
return TimeApp_ExitOver(pMe);
}
default:
if(SPRITE_MENU == pMe->window)
{
return TimeApp_MenuHandleEvent(pMe, eCode, wParam, dwParam);
}
else if(SPRITE_GAME == pMe->window)
{
return TimeApp_GameHandleEvent(pMe, eCode, wParam, dwParam);
}
else if (SPRITE_LEVEL == pMe->window)
{
return TimeApp_LevelHandleEvent(pMe, eCode, wParam, dwParam);
}
else if (SPRITE_OVER == pMe->window)
{
return TimeApp_OverHandleEvent(pMe, eCode, wParam, dwParam);
}
}
return FALSE;
}
boolean TimeApp_EnterMenu(TimerApp* sTimeApp)
{
AECHAR buffer[10] = {0};
AECHAR arrow[] = {'-', '-', '>', '\0'};
sTimeApp->menu_index = 0;
ISHELL_LoadResString(sTimeApp->pIShell, STRING_RES_FILE, IDS_NEW, buffer, sizeof(buffer));
IDISPLAY_DrawText(sTimeApp->pIDisplay, AEE_FONT_NORMAL, buffer, -1, 20, 40, NULL, IDF_ALIGN_CENTER);
ISHELL_LoadResString(sTimeApp->pIShell, STRING_RES_FILE, IDS_LOAD, buffer, sizeof(buffer));
IDISPLAY_DrawText(sTimeApp->pIDisplay, AEE_FONT_NORMAL, buffer, -1, 20, 60, NULL, IDF_ALIGN_CENTER);
ISHELL_LoadResString(sTimeApp->pIShell, STRING_RES_FILE, IDS_EXIT, buffer, sizeof(buffer));
IDISPLAY_DrawText(sTimeApp->pIDisplay, AEE_FONT_NORMAL, buffer, -1, 20, 80, NULL, IDF_ALIGN_CENTER);
IDISPLAY_DrawText(sTimeApp->pIDisplay, AEE_FONT_NORMAL, arrow, -1, 20, 40, NULL, 0);
IDISPLAY_Update(sTimeApp->pIDisplay);
return TRUE;
}
boolean TimeApp_ExitMenu(TimerApp* sTimeApp)
{
return TRUE;
}
boolean TimeApp_EnterGame(TimerApp* sTimeApp)
{
AEERect DeviceRect;
int i,j,x,y;
int cx,cy;
//uint16 nCode = 10;
// uint32 numMinutes = 1;
x = 0;
y = 0;
cx = 9;
cy = 10;
//sTimeApp->timerValue = 1000;
sTimeApp->nextindex = 10;
sTimeApp->isPaused = 0;
Star(sTimeApp);
for(i = 0;i < 14;i++)
{
for(j = 0;j < 10;j++)
{
x =j * cx;
y = i * cy;
SETAEERECT(&DeviceRect,x,y,cx,cy);
IDISPLAY_DrawFrame(sTimeApp->a.m_pIDisplay,&DeviceRect,AEE_FT_EMPTY,MAKE_RGB(120,120,120));//灰色
IDISPLAY_FillRect(sTimeApp->a.m_pIDisplay,&DeviceRect,MAKE_RGB(255,255,255));
}
}
TimeApp_LoadData(sTimeApp);
displayScore(sTimeApp);
IDISPLAY_Update(sTimeApp->a.m_pIDisplay);
ISHELL_SetTimer(sTimeApp->a.m_pIShell,sTimeApp->timerValue,TimerCB,(void *)sTimeApp);
return TRUE;
}
boolean TimeApp_ExitGame(TimerApp* sTimeApp)
{
TimeApp_SaveData(sTimeApp);
return TRUE;
}
boolean TimeApp_EnterLevel(TimerApp* sTimeApp)
{
//畫等級(jí);
AECHAR tempLevelBuffer[10] = {0};
AECHAR format[] = {'%', 'd', '\0'};
AECHAR buffer[10] = {0};
sTimeApp->tempLevel = 0;
TimeApp_LoadData(sTimeApp);
IDISPLAY_ClearScreen(sTimeApp->a.m_pIDisplay);
ISHELL_LoadResString(sTimeApp->pIShell, STRING_RES_FILE, IDS_SELECT, buffer, sizeof(buffer));
IDISPLAY_DrawText(sTimeApp->pIDisplay, AEE_FONT_NORMAL, buffer, -1, 20, 40, NULL, IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE/3);
WSPRINTF(tempLevelBuffer, sizeof(tempLevelBuffer), format, sTimeApp->tempLevel);
IDISPLAY_DrawText(sTimeApp->a.m_pIDisplay, AEE_FONT_BOLD, tempLevelBuffer, -1, 0, 0, NULL, IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
IDISPLAY_Update(sTimeApp->a.m_pIDisplay);
}
boolean TimeApp_ExitLevel(TimerApp* sTimeApp)
{
return TRUE;
}
boolean TimeApp_EnterOver(TimerApp* sTimeApp)
{
AECHAR buffer[10] = {0};
AECHAR arrow[] = {'-', '-', '>', '\0'};
sTimeApp->menu_index = 0;
ISHELL_LoadResString(sTimeApp->pIShell, STRING_RES_FILE, IDS_RESTART, buffer, sizeof(buffer));
IDISPLAY_DrawText(sTimeApp->pIDisplay, AEE_FONT_NORMAL, buffer, -1, 20, 40, NULL, IDF_ALIGN_CENTER);
ISHELL_LoadResString(sTimeApp->pIShell, STRING_RES_FILE, IDS_TOMIAN, buffer, sizeof(buffer));
IDISPLAY_DrawText(sTimeApp->pIDisplay, AEE_FONT_NORMAL, buffer, -1, 20, 60, NULL, IDF_ALIGN_CENTER);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -