⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boxman.c

📁 Boxman(推箱子)源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*===========================================================================

FILE: Boxman.c

SERVICES: Boxman Game Application

GENERAL DESCRIPTION: Boxman Game Main Control Program

INITIALIZATION AND SEQUENCING REQUIREMENTS:
BREW must be initialized. 

(c) COPYRIGHT 2003,2004 Hisense Incorporated.
                   All Rights Reserved.

                   Hisense Proprietary
===========================================================================*/

/*===============================================================================
  $DateTime: 2004/02/10 17:12:00 $
  $Author: whb $
  $Change: 000001 $

                      EDIT HISTORY FOR FILE

  This section contains comments describing changes made to the module.
  Notice that changes are listed in reverse chronological order.

when         who     what, where, why
----------   ---     ---------------------------------------------------------
02/18/2004   whb     add select stage function
02/12/2004   whb     Initial Version

=============================================================================== */


/*===============================================================================
INCLUDES DEFINITIONS
=============================================================================== */

#include "AEEModGen.h"
#include "AEEAppGen.h"
#include "AEEShell.h"
#include "Boxman.bid"  //save app id
#include "AEENet.h"
#include "AEEFile.h"
#include "AEEMenu.h"
#include "AEEStdLib.h"
#include "AEEImage.h"
#include "AEEText.h"
#include "AEEDisp.h"
#include "Boxman_res.h" //necessary resource
#include "Boxman.h"
#include "upimage.h"
//...

/*===============================================================================
Macro definitions
=============================================================================== */
#define STATE_NULL		0
#define STATE_MAINMENU  1
#define STATE_RUNGAME	2
#define STATE_SUCCESS	3
#define STATE_QUIT		4
#define STATE_SELSTAGE	5

#define UPCBMPGetU32(bytePtr)		( (U32) (((bytePtr)[3] <<24) + ((bytePtr)[2] <<16)+((bytePtr)[1] <<8)+(bytePtr)[0]) )
#define MAX_SOFTKEY_CHARS			    8
#define SOFTKEY_BACKGROUND_COLOR        MAKE_RGB(192, 192, 192)

#define kMAPPath  "map"
#define kFilePrefix "map"
#define kMaxFileNameLength  64

#define kColorClearGray						0xC0C0C000
#define kColorClearLightYellow				0xC0FFFF00
#define kColorClearBlack					0x00000000

#define kColorClearDialogBox				kColorClearBlack
#define kColorClearDialogBackground			kColorClearLightYellow
/*===============================================================================
structure definitions
=============================================================================== */

typedef	unsigned char	U8;	/* unsigned 8 bit integer */
typedef	unsigned short	U16;	/* unsigned 16 bit integer */
typedef	unsigned long	U32;	/* unsigned 32 bit integer */
typedef	signed char	S8;	/* signed 8 bit integer */
typedef	signed short	S16;	/* signed 16 bit integer */
typedef	signed long	S32;	/* signed 32 bit integer */

typedef struct _Boxman_type
{
AEEApplet  a;
AEERect    m_nClntAreaRect;
AEERect    m_nSoftkeyAreaRect;
uint16     m_nScrWidth;
uint16     m_nScrHeight;
uint16     m_nLineHeight;       //Normal font
uint16     m_nLargeLineHeight;  //Larege font
IBitmap*   m_pSuspendBitmap;

S16		   m_ManX;  /* record the position of the Man*/
S16        m_ManY;
U8		   *m_pMap; /* pointer to the map*/
U8		   m_Arrived; /* how many boxes have been on the dest*/
U8		   m_BoxNum; /* the number of boxes*/

U8		   m_nState;
void	   *m_pObj;
U8		   m_nCurMap;
}CBoxman; 



/*===============================================================================
Function Prototypes
=============================================================================== */

static boolean Boxman_HandleEvent(CBoxman * pApp, 
				   AEEEvent eCode, 
                                   uint16 wParam, 
                                   uint32 dwParam);
static boolean Boxman_InitAppData(CBoxman * pApp);
static void    Boxman_FreeAppData(CBoxman * pApp);
static void    Boxman_ReleaseObj(void ** ppObj);
static boolean Boxman_Start(CBoxman * pApp);
static boolean Boxman_Stop(CBoxman * pApp);
static boolean Boxman_Suspend(CBoxman * pApp);
static boolean Boxman_Resume(CBoxman * pApp);
static boolean Boxman_HandleKey(CBoxman * pApp,
                                 uint16 wParam, 
                                 uint32 dwParam);
static boolean Boxman_HandleCommand(CBoxman * pApp,
                                     uint16 wParam, 
                                     uint32 dwParam);
static boolean Boxman_Notify(CBoxman *pApp,uint16 w,uint32 dw);
static boolean Boxman_DisplayMainMenu(CBoxman * pApp);
static boolean Boxman_MainMenuHandleKey(CBoxman * pApp,
                                 uint16 wParam, 
                                 uint32 dwParam);
static boolean Boxman_MainMenuHandleCommand(CBoxman * pApp,
                                     uint16 wParam, 
                                     uint32 dwParam);
static boolean Boxman_GameStart(CBoxman * pApp);
static boolean Boxman_GameHandleKey(CBoxman * pApp,
                                     uint16 wParam, 
                                     uint32 dwParam);

static boolean Boxman_DisplaySuccess(CBoxman * pApp);
static boolean Boxman_SuccessHandleKey(CBoxman * pApp,
                                     uint16 wParam, 
                                     uint32 dwParam);
static boolean Boxman_DisplayQuit(CBoxman * pApp);
static boolean Boxman_QuitHandleKey(CBoxman * pApp,
                                     uint16 wParam, 
                                     uint32 dwParam);
static boolean Boxman_SelectStage(CBoxman * pApp);
static boolean Boxman_SelectStageHandleKey(CBoxman * pApp,
                                     uint16 wParam, 
                                     uint32 dwParam);

/* general drawing routines */

static void Boxman_ClearDisplay(CBoxman* pApp);
static void Boxman_CheckScreen(CBoxman* pApp);

static void DevBitBlt(CBoxman* pApp,
			   S16 destX, S16 destY, 
			   S16 width, S16 height, 
			   S16 srcX, S16 srcY, 
			   const unsigned char * imageData, S32 imageLen);
static void Boxman_DrawMan(CBoxman* pApp,S16 x,S16 y);
static void Boxman_DrawWall(CBoxman* pApp,S16 x,S16 y);
static void Boxman_DrawBG(CBoxman* pApp,S16 x,S16 y);
static void Boxman_DrawBox(CBoxman* pApp,S16 x,S16 y);
static void Boxman_DrawDest(CBoxman* pApp,S16 x,S16 y);

static boolean Boxman_ReadMap(CBoxman * pApp,U8 mapId);
static void Boxman_makePathnameFromID(char* filename, U8 mapId);
static U32 Boxman_Itoa(U8* buffer, S32 eger);
static void DevDrawDialog(CBoxman * pApp,const AECHAR *szText);

#if defined(BREW_STATIC_APP)

static int  BoxmanMod_CreateInstance(AEECLSID  ClsId,
                                      IShell   *pIShell,
                                      IModule  *po,
                                      void    **ppObj);
static int  Boxman_Load(IShell   *ps, 
                         void     *pHelpers, 
                         IModule **pMod);



PFNMODENTRY Boxman_GetModInfo(IShell      *ps, 
                               AEECLSID   **ppClasses, 
                               AEEAppInfo **pApps, 
                               uint16      *pnApps,
                               uint16      *pwMinPriv);

#endif //BREW_STATIC_APP

/*===========================================================================
                      STATIC/LOCAL DATA
===========================================================================*/

#if defined(BREW_STATIC_APP)

static const AEEAppInfo gaiBoxman = {
   AEECLSID_APP_Boxman,//new class
   Boxman_RES_FILE,    //resource file name
   IDS_Boxman_TITLE,   //app title
   0,0,0,0,
   AFLAG_TOOL           //app type
};

#endif //BREW_STATIC_APP

/*===========================================================================
                      Function Implementations
===========================================================================*/

#if defined(BREW_STATIC_APP)


/*===========================================================================

FUNCTION Boxman_GetModInfo

DESCRIPTION
  Retrieves information about the static module

DEPENDENCIES
  none

RETURN VALUE
  none

SIDE EFFECTS
  none
===========================================================================*/
PFNMODENTRY Boxman_GetModInfo( IShell      *ps, 
                           	AEECLSID   **ppClasses, 
                           	AEEAppInfo **pApps, 
                           	uint16      *pnApps,
                           	uint16      *pwMinPriv)
{
   PARAM_NOT_REF(ps)
   PARAM_NOT_REF(ppClasses)
   PARAM_NOT_REF(pwMinPriv)

   *pApps = (AEEAppInfo *)&gaiBoxman;
   *pnApps = 1;
   return (PFNMODENTRY)Boxman_Load;
}

/*===========================================================================

FUNCTION Boxman_Load

DESCRIPTION
  Static fixed .LIB entrypoint for applet

PARAMETERS:
   *ps: pointer to IShell
   *pHelpers : 
   **pointer : pointer to IModule

DEPENDENCIES
  none

RETURN VALUE
  none

SIDE EFFECTS
  none
===========================================================================*/
static int Boxman_Load(IShell   *ps,
			void     *pHelpers, 
                        IModule **pMod)
{
   return AEEStaticMod_New(sizeof(AEEMod),
                           ps,
                           pHelpers,
                           pMod,
                           BoxmanMod_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)
static int BoxmanMod_CreateInstance(AEECLSID  ClsId,
                                     IShell   *pIShell,
                                     IModule  *po,
                                     void    **ppObj)
#else
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
#endif
{
   CBoxman *pApp;
   *ppObj = NULL;
		
   if(ClsId == AEECLSID_BOXMAN)
   {
      if(AEEApplet_New( sizeof(CBoxman), 
			ClsId, 
			pIShell,
			po,
			(IApplet**)ppObj,
			(AEEHANDLER)Boxman_HandleEvent,
			(PFNFREEAPPDATA)Boxman_FreeAppData)
         		== TRUE)
      {
		 
		pApp=(CBoxman *)*ppObj;
		
		if (!Boxman_InitAppData( pApp ) ) 
		{
			IAPPLET_Release( (IApplet*) pApp );
			*ppObj = NULL;
			return EFAILED;
		}
		
         	return (AEE_SUCCESS);
      }
   }
   return (EFAILED);
}

/*===========================================================================

FUNCTION Boxman_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 Boxman_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 Boxman_HandleEvent(CBoxman * pApp, AEEEvent evt, uint16 w, uint32 dw)
{  
   
   switch (evt) 
   {
      case EVT_APP_START:                        		    
      
           return Boxman_Start(pApp);
      	         	   
      case EVT_APP_STOP:
      
           return Boxman_Stop(pApp);
                      
      case EVT_APP_SUSPEND:
      
           return Boxman_Suspend(pApp);
                      
      case EVT_APP_RESUME:
      
           return Boxman_Resume(pApp);
           
      case EVT_NOTIFY:
      
           return Boxman_Notify(pApp,w,dw);     
           
      case EVT_KEY:
      
           return Boxman_HandleKey(pApp,w,dw);
                  
      case EVT_COMMAND:
      
           return Boxman_HandleCommand(pApp,w,dw);
	
      //... other event handler
      
      default:
         break;
   }
   return FALSE;
}
static boolean Boxman_InitAppData(CBoxman * pApp)
{
	/*get the device information*/        
	
	AEEDeviceInfo  deviceInfo;
	
	ISHELL_GetDeviceInfo(pApp->a.m_pIShell, &deviceInfo);

        /*get the height of font*/
        
	pApp->m_nLineHeight = IDISPLAY_GetFontMetrics(pApp->a.m_pIDisplay,
													AEE_FONT_NORMAL,
													NULL,
													NULL);
	pApp->m_nLargeLineHeight = IDISPLAY_GetFontMetrics(pApp->a.m_pIDisplay,
													AEE_FONT_LARGE,
													NULL,
													NULL);
	SETAEERECT(&pApp->m_nClntAreaRect,
		   0,
		   0,
		   deviceInfo.cxScreen,
		   deviceInfo.cyScreen-pApp->m_nLargeLineHeight);
		   
	SETAEERECT(&pApp->m_nSoftkeyAreaRect,
		   pApp->m_nClntAreaRect.x,
		   pApp->m_nClntAreaRect.y+pApp->m_nClntAreaRect.dy,
		   pApp->m_nClntAreaRect.dx,
		   pApp->m_nLargeLineHeight);
    pApp->m_nScrHeight = deviceInfo.cyScreen;
	pApp->m_nScrWidth = deviceInfo.cxScreen;
	/* create the neccessary instance */
	
	//if(ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_BITMAP, (void**)(&pApp->m_pBmp)) != SUCCESS)
	//return FALSE;

	pApp->m_nState = NULL;
	pApp->m_pObj = NULL;

	pApp->m_ManX = 0;
	pApp->m_ManY = 0;
	pApp->m_pMap = (U8 *)MALLOC(MAP_HEIGHT*MAP_WIDTH);
	pApp->m_Arrived = 0;
	pApp->m_BoxNum = 0;
	pApp->m_nCurMap = 1;
	// Add code here ...

	return TRUE;
}
static void    Boxman_FreeAppData(CBoxman * pApp)
{

  Boxman_ReleaseObj( (void **)&pApp->m_pSuspendBitmap );

  Boxman_ReleaseObj( (void **)&pApp->m_pObj);
  /* release other resource */
  if(NULL != pApp->m_pMap)
  FREE(pApp->m_pMap);
  // Add code here ...
  
}
static void    Boxman_ReleaseObj(void ** ppObj)
{
  if ( ppObj && *ppObj ) 
  {
    (void) IBASE_Release( ( (IBase *) *ppObj ) );
    *ppObj = NULL;
  }
}
static boolean Boxman_Start(CBoxman * pApp)
{
	return Boxman_DisplayMainMenu(pApp);

}
static boolean Boxman_Stop(CBoxman * pApp)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -