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

📄 russdmd.c

📁 俄罗斯方块的整套源代码
💻 C
字号:
#include "russdmd.h"

#include "AEEStdLib.h"
#include "AEELicense.h"
#include "russdmd.bid"

#include "commondef.h"

static boolean	RussDmdApp_HandleEvent(RussDmdApp * pme, AEEEvent eCode,uint16 wParam, uint32 dwParam);
static boolean	RussDmdApp_Init(RussDmdApp *pMe);
static void		RussDmdApp_Free(RussDmdApp *pMe);
static boolean	RussDmdApp_IsDemo(RussDmdApp *pMe);

boolean RussDmdApp_SetActiveWnd(RussDmdApp *pMe, int wnd)
{
	switch(pMe->activeView) 
	{
	case IDW_GAME:
		GameWnd_Close(&pMe->game);
		break;
	case IDW_MAINMENU:
		MainMenuWnd_Close(&pMe->mainMenu);
		break;
	case IDW_SCORELIST:
		ScoreListWnd_Close(&pMe->score);
		break;
	case IDW_SMS:
		SendSmsWnd_Close(&pMe->sms);
		break;
	default:
		break;
	}

	pMe->activeView = wnd;
	pMe->keyFlag = kKeypad_NULL;

	switch(pMe->activeView) 
	{
	case IDW_GAME:
		return GameWnd_Open(&pMe->game);
	case IDW_MAINMENU:
		return MainMenuWnd_Open(&pMe->mainMenu);
	case IDW_SCORELIST:
		return ScoreListWnd_Open(&pMe->score);
	case IDW_SMS:
		return SendSmsWnd_Open(&pMe->sms);
	default:
		return FALSE;
	}
}


int AEEClsCreateInstance(AEECLSID ClsId, IShell * pIShell, IModule * pMod, void ** ppObj)
{
	*ppObj = NULL;

	if (ClsId != AEECLSID_RUSSDMD)
		return EFAILED;
	
	if (!AEEApplet_New(sizeof(RussDmdApp),		// Size of our private class
		ClsId,									// Our class ID
		pIShell,								// Shell interface
		pMod,									// Module instance
		(IApplet**)ppObj,						// Return object
		(AEEHANDLER)RussDmdApp_HandleEvent,		// Our event handler
		(PFNFREEAPPDATA)RussDmdApp_Free))			
		return EFAILED;
	
	return SUCCESS;
}

static boolean RussDmdApp_HandleEvent(RussDmdApp * pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
	switch (eCode) 
	{
	case EVT_APP_START:
		if (RussDmdApp_Init(pMe) != TRUE) 
		{
			return FALSE;
		}		
		return RussDmdApp_SetActiveWnd(pMe, IDW_MAINMENU);
		
	case EVT_APP_STOP:
		return TRUE;

	case EVT_KEY:
		if (wParam == AVK_UP || wParam == AVK_2)
		{
			pMe->keyFlag |= kKeypad_Up;
		}
		else if (wParam == AVK_DOWN || wParam == AVK_8)
		{
			pMe->keyFlag |= kKeypad_Down;
		}
		else if (wParam == AVK_LEFT || wParam == AVK_4)
		{
			pMe->keyFlag |= kKeypad_Left;
		}
		else if (wParam == AVK_RIGHT || wParam == AVK_6)
		{
			pMe->keyFlag |= kKeypad_Right;
		}
		else if (wParam == AVK_SELECT)
		{
			pMe->keyFlag |= kKeypad_Select;
		}
		else if (wParam == AVK_CLR)
		{
			pMe->keyFlag |= kKeypad_Clr;
		}

		return TRUE;

	default:
		switch(pMe->activeView) 
		{
		case IDW_GAME:
			return GameWnd_HandleEvent(&pMe->game, eCode, wParam, dwParam);
		case IDW_MAINMENU:
			return MainMenuWnd_HandleEvent(&pMe->mainMenu, eCode, wParam, dwParam);
		case IDW_SCORELIST:
			return ScoreListWnd_HandleEvent(&pMe->score, eCode, wParam, dwParam);
		case IDW_SMS:
			return SendSmsWnd_HandleEvent(&pMe->sms, eCode, wParam, dwParam);
		default:
			break;
		}
	}
	return FALSE;
}

static boolean RussDmdApp_Init(RussDmdApp *pMe)
{
	AEEDeviceInfo di;

	ISHELL_GetDeviceInfo(pMe->a.m_pIShell, &di);
	pMe->screenWidth = di.cxScreen;
	pMe->screenHeight = di.cyScreen;

	pMe->keyFlag = kKeypad_NULL;

	pMe->activeView = IDW_NOWND;

	if (GameWnd_New(&pMe->game, pMe) != TRUE) 
	{
		return FALSE;
	}
	if (MainMenuWnd_New(&pMe->mainMenu, pMe) != TRUE) 
	{
		return FALSE;
	}
	if (ScoreListWnd_New(&pMe->score, pMe) != TRUE) 
	{
		return FALSE;
	}
	if (SendSmsWnd_New(&pMe->sms, pMe) != TRUE) 
	{
		return FALSE;
	}

	pMe->game.m_nLevel = 0;		// 最低一级
	pMe->game.m_bIsDemo = RussDmdApp_IsDemo(pMe);

	return TRUE;
}

boolean RussDmdApp_IsDemo(RussDmdApp *pMe)
{
	ILicense *pLicense;
	AEELicenseType nLicenseType;
	uint32 dwExpire;
	uint32 dwSeq;
	AEEPriceType nPriceType;

	boolean bReturn;

	if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_LICENSE, (void**)&pLicense) != SUCCESS)
		return FALSE;
	else
	{
		nPriceType = ILICENSE_GetPurchaseInfo(pLicense, &nLicenseType, &dwExpire, &dwSeq);
		if (nLicenseType == LT_NONE)
			bReturn = FALSE;
		else
		{
			if(nPriceType == PT_DEMO)
				bReturn = TRUE;
			else 
				bReturn = FALSE;
		}
	}

	if (pLicense)
	{
		ILICENSE_Release(pLicense);
		pLicense = NULL;
	}
	return bReturn;
}

static void RussDmdApp_Free(RussDmdApp *pMe)
{
	GameWnd_Free(&pMe->game);
	MainMenuWnd_Free(&pMe->mainMenu);
	ScoreListWnd_Free(&pMe->score);
	SendSmsWnd_Free(&pMe->sms);
}

⌨️ 快捷键说明

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