?? eros.c
字號:
/*===========================================================================
FILE: eros.c
===========================================================================*/
/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "target.h"
#include "AEE.h"
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEFile.h" // File interface definitions
#include "AEEDB.h" // Database interface definitions
#include "AEENet.h" // Socket interface definitions
#include "AEESound.h" // Sound Interface definitions
#include "AEETapi.h" // TAPI Interface definitions
#include "AEEStdLib.h"
#ifdef AEE_SIMULATOR
#include "Controls.h"
#else
#include "OEMClassIDs.h"
#endif
#include "AEETabCtrl.h"
#include "hs_comfunc.h"
#include "hs_comdefine.h"
#include "AEEWindow.h"
#include "HS_NotifyWin.h"
#include "HS_CommonWins.h"
#include "AEEText.h"
#include "AEEImage.h"
#include "CoreApp.h"
//added by wuhaoyong
#include "eros.bid"
#include "eros.brh"
#include "commonres.brh"
#include "AEEDisp.h"
#ifndef AEE_SIMULATOR
#include "msg.h"
#endif
#include "AEEAnnunciator.h"
#define MAP_WIDTH 11
#define MAP_HEIGHT 20
#ifndef COLOR_DISPLAY
#define COLOR_DISPLAY
#endif
#ifdef COLOR_DISPLAY
#define RED_COLOR MAKE_RGB(0xC0, 0x00, 0x00)
#define BLUE_COLOR MAKE_RGB(0, 0, 255)
#define GREEN_COLOR MAKE_RGB(0x00, 0x60, 0x00)
#define LIGHT_RED_COLOR MAKE_RGB(255, 0, 0)
#define LIGHT_BLUE_COLOR MAKE_RGB(128, 255, 255)
#define DARK_GREEN_COLOR MAKE_RGB(0, 128, 64)
#define ORANGE_COLOR MAKE_RGB(255, 128, 0)
#define PURPLE_COLOR MAKE_RGB(179, 21, 206)
#define YELLOW_GREEN_COLOR MAKE_RGB(158, 152, 69)
#define GREY_COLOR MAKE_RGB(80, 80, 80)
#endif
#define noblack FALSE
#define black TRUE
//add by wuhaoyong
#define STATE_NULL 0
#define STATE_MAINMENU 1
#define STATE_RUNGAME 2
#define STATE_GAMEOVER 3
#define STATE_QUIT 4
#define STATE_OPTION 5
#define STATE_RECORD 6
#define STATE_HELP 7
#define STATE_GAMEPASS 8
#define LEVEL_EASY 0//簡單
#define LEVEL_MODERATE 1//適中
#define LEVEL_DIFFICULT 2//難
#define LEVEL_HELLUVA 3//很難
#define EROSMAINMENU_ITEMBASE 1000
#define EROSMAINMENU_ITEM1 (EROSMAINMENU_ITEMBASE +1)//開始有喜
#define EROSMAINMENU_ITEM2 (EROSMAINMENU_ITEMBASE +2)//游戲設置
#define EROSMAINMENU_ITEM3 (EROSMAINMENU_ITEMBASE +3)//最高分
#define EROSMAINMENU_ITEM4 (EROSMAINMENU_ITEMBASE +4)//幫助
#define EROSMAINMENU_ITEM5 (EROSMAINMENU_ITEMBASE +5)//退出游戲
#define EROSMAINMENU_ITEM6 (EROSMAINMENU_ITEMBASE +6)
#define EROSMAINMENU_ITEM7 (EROSMAINMENU_ITEMBASE +7)
#define EROSMAINMENU_ITEM8 (EROSMAINMENU_ITEMBASE +8)
#define EROSMAINMENU_ITEM9 (EROSMAINMENU_ITEMBASE +9)
#define EROSMAINMENU_ITEM10 (EROSMAINMENU_ITEMBASE +10)
#define IBUTTON_CONFIRM 3100
#define IBUTTON_RETURN 3101
#define IBUTTON_CLEAR 3102
#define NOTIFY_YES 3105
#define NOTIFY_NO 3106
#define NOTIFY_CONFIRM 3517
#define ITEMTEXT_LEN 16
#define MAX_EROS_NUM 5
#define MAX_EROS_OPTION_NUM 4
#define EROS_LEVEL_FILE "eros_level.dat"
#define EROS_SCORE_FILE "eros_score.dat"
#define EROS_MAP_FILE "eros_map.dat"
#define EROS_PARA_FILE "eros_para.dat"
//#define FEATURE_EROS_CG005
#ifndef AEE_SIMULATOR
char *gsErosResFile = AEE_RES_LANGDIR EROS_RES_FILE;
#else
char *gsErosResFile = EROS_RES_FILE;
#endif
/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via "pMe->"
-------------------------------------------------------------------*/
// create an applet structure that's passed around. All variables in
// here will be able to be referenced as static.
typedef struct _eros
{
AEEApplet a ; // First element of this structure must be AEEApplet
AEEDeviceInfo DeviceInfo; // always have access to the hardware device information
// add your own variables here...
AEERect m_Rect;
unsigned char block_width;
unsigned char block_height;
RGBVAL frame_color;
int difficult_level;
int a0;
int dels;
int next_block;
int block[4][4];
int map[MAP_WIDTH][MAP_HEIGHT];
int map_line;
int map_col;
int x_size;
int y_size;
int block_x;
int block_y;
int current_block;
int gameover;
uint64 score;
boolean pause;
RGBVAL color_table[10];
int32 r_color;
int32 g_color;
int32 b_color;
//add by wuhaoyong
uint8 m_nState;
int m_continue;//是否顯示繼續游戲的菜單,1顯示,0不顯示
uint8 m_nLevel;
uint16 m_nTimer;
uint16 m_MenuSel;//added by wuhaoyong
IMenuCtl* m_pIMenu; //for all menu,added by wuhaoyong
IWindow* m_pNotifyWin;
IButtonCtl* m_pReturn;//返回軟鍵
IButtonCtl* m_pConfirm;//確定軟鍵
IButtonCtl* m_pClear;//確定軟鍵
AEETabCtl* m_pTabCtl;
IBitmap *m_pSuspendBitmap;//wuhaoyongadd
uint16 m_nScrWidth;
uint16 m_nScrHeight;
IAnnunciator* m_pIAnnu; //icon area
} eros;
typedef struct
{
uint16 wItemID; //--菜單項ID
uint16 wItemIconID; //--菜單項圖標ID
AECHAR wItemText[ITEMTEXT_LEN+1]; //--菜單項文本
}EROSMenuItem;
/* 全局變量定義 */
EROSMenuItem ErosMainMenuTBL[] =
{
{EROSMAINMENU_ITEM1, IDI_NUMBER_01, NULL},
{EROSMAINMENU_ITEM2, IDI_NUMBER_02, NULL},
{EROSMAINMENU_ITEM3, IDI_NUMBER_03, NULL},
{EROSMAINMENU_ITEM4, IDI_NUMBER_04, NULL},
{EROSMAINMENU_ITEM5, IDI_NUMBER_05, NULL},
{EROSMAINMENU_ITEM10, IDI_NUMBER_06, NULL},
};
EROSMenuItem ErosOptionMenuTBL[] =
{
{EROSMAINMENU_ITEM6, IDI_RADIO_OFF, NULL},
{EROSMAINMENU_ITEM7, IDI_RADIO_OFF, NULL},
{EROSMAINMENU_ITEM8, IDI_RADIO_OFF, NULL},
{EROSMAINMENU_ITEM9, IDI_RADIO_OFF, NULL},
};
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
//added by wuhaoyong
#ifdef AEE_SIMULATOR
extern void AEE_SetShell(IShell *pIShell);
#endif
static boolean eros_HandleEvent(eros* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
boolean eros_InitAppData(eros* pMe);
static void Eros_ReleaseObj(void ** ppObj);
void eros_FreeAppData(eros* pMe);
uint64 up_Itoa(AECHAR * buffer, uint64 eger);
void ClearBlock(eros * pMe);
void write_video(eros * pMe,int x,int y,RGBVAL color,unsigned char full);
void GenerateBlock(eros * pMe,int kind); /*generate a block*/
void initialmemory(eros * pMe);
void restorememory(eros * pMe);
void GenerateNew(eros * pMe) ; /*generate a new block*/
void PutBlock(eros * pMe);
void RotateBlock(eros * pMe);
int CanPut(eros * pMe);
void DrawMap(eros * pMe) ; /*draw map*/
void DeleteRow(eros * pMe);
boolean Gameover(eros * pMe,uint32 r_color,uint32 g_color, uint32 b_color) ; /*draw map*/
boolean GamePass(eros * pMe,uint32 r_color,uint32 g_color, uint32 b_color) ;
static void update_map(eros * pMe);
static void Eros_IControlInit(eros* pMe);
static boolean Eros_Start(eros * pMe);
boolean Eros_SetForeImg(IShell* pIShell, IButtonCtl *pButton, uint16 wID);
static boolean Eros_DisplayMainMenu(eros * pMe);
void Eros_DrawMainMenu_CB(void* pi, AEEODCBData* is);
static void Eros_BuildMenuItemTBL(eros* pMe);
static void Eros_MainMenuDisplay(eros* pMe);
static void Eros_DrawTitleText(eros* pMe, uint16 resID);
static void Eros_DrawLevel(eros* pMe);
void Eros_DrawMenuItem(void *pUser, AEEODCBData* is , boolean bIconFlg);
static boolean Eros_IControlHandEvt(eros* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam);
static boolean Eros_HandleCommand(eros * pMe,uint16 wParam, uint32 dwParam);
static boolean Eros_GameRestart(eros * pMe);
static boolean Eros_GameStart(eros * pMe);
static boolean Eros_MainMenuHandleCommand(eros * pMe,uint16 wParam, uint32 dwParam);
static boolean Eros_Stop(eros * pMe);
static boolean Eros_HandleKey(eros * pMe,uint16 wParam, uint32 dwParam);
static boolean Eros_MainMenuHandleKey(eros * pMe,uint16 wParam, uint32 dwParam);
static boolean Eros_GameHandleKey(eros * pMe,uint16 wParam, uint32 dwParam);
static boolean Eros_DisplayOptionMenu(eros * pMe);
void Eros_DrawOptionMenu_CB(void* pi, AEEODCBData* is);
void Eros_DrawOptionMenuItem(void *pUser, AEEODCBData* is , boolean bIconFlg);
static void Eros_BuildOptionMenuItemTBL(eros* pMe);
static void Eros_OptionMenuDisplay(eros* pMe);
static boolean Eros_OptionMenuHandleCommand(eros * pMe,uint16 wParam, uint32 dwParam);
void Eros_Set_MenuIcon(IMenuCtl *pCtrl, uint16 listId);
void Eros_SetMenuIcon(IMenuCtl *pm,uint16 listId,boolean bSel);
void Eros_ReadLevelFile(eros * pMe);
void Eros_WriteLevelFile(eros * pMe);
void Eros_TestLevelFile(eros * pMe);
void Eros_TestScoreFile(eros * pMe);
static boolean Eros_WriteScoreFile(eros * pMe);
void Eros_ClearScoreFile(eros * pMe);
static boolean Eros_ScoreHandleCommand(eros * pMe,uint16 wParam, uint32 dwParam);
static boolean Eros_RecordHandleCommand(eros * pMe,uint16 wParam, uint32 dwParam);
static boolean Eros_HelpHandleCommand(eros * pMe,uint16 wParam, uint32 dwParam);
static boolean Eros_CreatNotifyWin(eros* pMe, HSNotifyWinType type, uint16 nResID);
static boolean eros_SaveScene(eros* pMe);
static boolean eros_ResumeScene(eros* pMe);
static boolean Eros_DisplayHelpMenu(eros * pMe,uint16 wParam, uint32 dwParam);
static void Eros_SetBackLightAlwaysOn(boolean onoff);
extern void HandleBacklights ( boolean onoff, int time);//zhangwei 04/12/29
extern void CoreTask_Set_Backlight(boolean value);
/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */
/*=========================================
static application,向serv版本移植才需要這些內容
=====================================*/
#if defined(BREW_STATIC_APP)
int Eros_CreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj);
int Eros_Load(IShell *ps, void * pHelpers, IModule ** pMod);
// Constant Data...
//static const AEEAppInfo gaiQCam = {AEECLSID_QCAMERA,QCAMERA_RES_FILE, IDS_TITLE, 0,0,0,0,AFLAG_TOOL};
static const AEEAppInfo gaiEros =
{
AEECLSID_EROS,EROS_RES_FILE, IDS_GAME_TITLE, 0,0,0,0,AFLAG_TOOL
};
PFNMODENTRY Eros_GetModInfo(IShell * ps, AEECLSID ** ppClasses, AEEAppInfo ** pApps, uint16 * pnApps,uint16 * pwMinPriv)
{
*pApps = (AEEAppInfo *)&gaiEros;
*pnApps = 1;
return((PFNMODENTRY)Eros_Load);
}
int Eros_Load(IShell *ps, void * pHelpers, IModule ** pMod)
{
return(AEEStaticMod_New((int16)(sizeof(AEEMod)),ps,pHelpers,pMod,Eros_CreateInstance,NULL));
}
#endif //BREW_STATIC_APP
/*===========================================================================
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
===========================================================================*/
#if defined(BREW_STATIC_APP) //向serv版本移植的標準寫法
int Eros_CreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
#else
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
#endif
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -