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

📄 scorelistwnd.c

📁 飞机游戏(brew)
💻 C
字号:
#include "ScoreListWnd.h"

#include "AEEStdlib.h"

#include "pfly.h"
#include "pfly_res.h"

static boolean ScoreListWnd_HandleKeyEvent(pthis, eCode, wParam);
static void ScoreListWnd_Update(ScoreListWnd* pthis);
static void ScoreListWnd_LoadList(ScoreListWnd* pthis);
static void ScoreListWnd_SaveList(ScoreListWnd* pthis);


boolean ScoreListWnd_New(ScoreListWnd *pthis, PflyApp* pMe)
{
	pthis->pMe = pMe;
	MEMSET(pthis->scorelist, 0, sizeof(pthis->scorelist));
	ScoreListWnd_LoadList(pthis);

	return TRUE;
}


boolean ScoreListWnd_HandleEvent(ScoreListWnd* pthis, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
	switch (eCode) {
	case EVT_APP_SUSPEND:
		return TRUE;
		
	case EVT_APP_RESUME:
		ScoreListWnd_Update(pthis);
		return TRUE;
		
	default:
		return ScoreListWnd_HandleKeyEvent(pthis, eCode, wParam);		 
	}

}

static boolean ScoreListWnd_HandleKeyEvent(ScoreListWnd* pthis, AEEEvent eCode, uint16 wParam)
{
	if( eCode == EVT_KEY) {
 		switch(wParam) {
		case AVK_CLR:
			return Pfly_SetActiveWnd(pthis->pMe, IDW_MAINMENU);

		default:
			return FALSE;
		}
	}
	return FALSE;
}

boolean ScoreListWnd_Open(ScoreListWnd* pthis)
{
	ScoreListWnd_Update(pthis);

	return TRUE;
}

static void ScoreListWnd_Update(ScoreListWnd* pthis)
{
	int loop;
	int screenX, screenY ,centerX, centerY;
	int stepH, stepW;
	
	AEEDeviceInfo deviceInfo;

	AECHAR   str[MAX_STRING_SIZE];
	char     temp[MAX_STRING_SIZE];

	IDisplay *m_pIDisplay = pthis->pMe->a.m_pIDisplay;
	IShell   *m_pIShell = pthis->pMe->a.m_pIShell;	
	
	ISHELL_GetDeviceInfo(m_pIShell, &deviceInfo);
	screenX = deviceInfo.cxScreen;
	screenY = deviceInfo.cyScreen;
	centerX = screenX/2;
	centerY = screenY/2;

	stepH = IDISPLAY_GetFontMetrics(m_pIDisplay, AEE_FONT_NORMAL, NULL, NULL);
	stepW = stepH;

	IDISPLAY_ClearScreen(m_pIDisplay);
	IDISPLAY_FillRect(m_pIDisplay, NULL, MAKE_RGB(128,138,238));
	
	ISHELL_LoadResString(m_pIShell, PFLY_RES_FILE, IDS_MENU_SCOREVIEW, str, MAX_STRING_SIZE);
	IDISPLAY_DrawText(m_pIDisplay, AEE_FONT_BOLD, str, -1, 0,
		5, NULL, IDF_ALIGN_CENTER | IDF_TEXT_TRANSPARENT);

	for(loop = 0; loop < MAX_LIST_LENGTH; loop ++)	{
		SPRINTF(temp, "%d", loop+1);
		STRTOWSTR(temp, str, MAX_STRING_SIZE);
		IDISPLAY_DrawText(m_pIDisplay, AEE_FONT_NORMAL, str, -1,  0, (2+loop)*stepH, NULL, IDF_TEXT_TRANSPARENT);	

		SPRINTF(temp, "%d", pthis->scorelist[loop]);
		STRTOWSTR(temp, str, MAX_STRING_SIZE);
		IDISPLAY_DrawText(m_pIDisplay, AEE_FONT_NORMAL, str, -1,  screenX-stepW*2, (2+loop)*stepH, NULL, IDF_TEXT_TRANSPARENT);	
	}

	IDISPLAY_Update(m_pIDisplay);
}

void ScoreListWnd_Close(ScoreListWnd* pthis)
{
}

void ScoreListWnd_Free(ScoreListWnd* pthis)
{
	
}

static void ScoreListWnd_LoadList(ScoreListWnd* pthis)
{
	IFileMgr *pFileMgr	= NULL;
	IFile *pFile		= NULL;
	IShell *pIShell		= pthis->pMe->a.m_pIShell;
	int i;
	if(ISHELL_CreateInstance(pIShell, AEECLSID_FILEMGR, (void **)&pFileMgr) != SUCCESS)
	{
		return;
	}
	if((pFile = IFILEMGR_OpenFile(pFileMgr, LIST_FILE, _OFM_READWRITE)) == NULL){
		IFILEMGR_Release(pFileMgr);
		return;
	}
	
	for(i = 0; i < MAX_LIST_LENGTH; i ++)
	{
		IFILE_Read(pFile, &pthis->scorelist[i], sizeof(int));
	}
	
	IFILE_Release(pFile);
	IFILEMGR_Release(pFileMgr);
}

static void ScoreListWnd_SaveList(ScoreListWnd* pthis)
{
	IFileMgr *pFileMgr	= NULL;
	IFile *pFile		= NULL;
	IShell *pIShell		= pthis->pMe->a.m_pIShell;
	int i;

	if(ISHELL_CreateInstance(pIShell, AEECLSID_FILEMGR, (void **)&pFileMgr) != SUCCESS)
	{
		return;
	}
	if((pFile = IFILEMGR_OpenFile(pFileMgr, LIST_FILE, _OFM_READWRITE)) == NULL){
		IFILEMGR_Release(pFileMgr);
		return;
	}
	
	for(i = 0; i < MAX_LIST_LENGTH; i ++)
	{
		IFILE_Write(pFile, &pthis->scorelist[i], sizeof(int));
	}
	
	IFILE_Release(pFile);
	IFILEMGR_Release(pFileMgr);
}

boolean ScoreListWnd_AddToList(ScoreListWnd* pthis, int score)
{
	int i, j;
	for(i = 0; i < MAX_LIST_LENGTH; i++)
	{
		if(score > pthis->scorelist[i]){
			break;
		}
	}
	if(i < MAX_LIST_LENGTH){
		for(j = MAX_LIST_LENGTH-1; j > i; j --)
		{
			pthis->scorelist[j] = pthis->scorelist[j-1];
		}
		pthis->scorelist[i] = score;

		ScoreListWnd_SaveList(pthis);
		return TRUE;
	}
	return FALSE;
}

⌨️ 快捷键说明

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