📄 gameappview.cpp
字号:
////////////////////////////////////////////////////////////////////////
//
// GameAppView.cpp
//
// Copyright (c) 2006 Nokia Corporation. All rights reserved.
//
////////////////////////////////////////////////////////////////////////
#include "GameAppView.h"
#include <lang/Globals.h>
#include <eikenv.h>
#include "GameEngine.h"
#include "App.h"
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
CGameAppView* CGameAppView::NewL(const TRect& aRect)
{
CGameAppView* self = CGameAppView::NewLC(aRect);
CleanupStack::Pop();
return self;
}
////////////////////////////////////////////////////////////////////////
CGameAppView* CGameAppView::NewLC(const TRect& aRect)
{
CGameAppView* self = new (ELeave) CGameAppView;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
////////////////////////////////////////////////////////////////////////
void CGameAppView::ConstructL(const TRect& aRect)
{
dprintf( "CGameAppView::ConstructL\n" );
lang::Globals::init();
// Create a window for this application view
CreateWindowL();
// Set the windows size
SetRect(aRect);
iEngine = CGameEngine::NewL(iEikonEnv->WsSession(),
*(CCoeEnv::Static()->ScreenDevice()), Window(), Rect().Size());
// Activate the window, which makes it ready to be drawn
ActivateL();
}
////////////////////////////////////////////////////////////////////////
CGameAppView::CGameAppView()
: iGameStarted(EFalse)
{
}
////////////////////////////////////////////////////////////////////////
CGameAppView::~CGameAppView()
{
delete iEngine;
lang::Globals::cleanup();
}
////////////////////////////////////////////////////////////////////////
void CGameAppView::Draw(const TRect& /*aRect*/) const
{
// Clear the screen
CWindowGc& gc = SystemGc();
gc.Clear(Rect());
}
////////////////////////////////////////////////////////////////////////
TKeyResponse CGameAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
TKeyResponse returnKey = EKeyWasNotConsumed;
App* app = iEngine->app();
// If the app switch key is pressed we need to stop drawing
if(aType == EEventKey && aKeyEvent.iScanCode == EStdKeyApplication0)
{
StopGame();
// we still want the key event to be passed on so don't consume the key
}
else if(aType == EEventKeyDown)
{
app->keyDown( getKeyByScancode( aKeyEvent.iScanCode ) );
returnKey = EKeyWasConsumed;
}
else if(aType == EEventKeyUp)
{
app->keyUp( getKeyByScancode( aKeyEvent.iScanCode ) );
returnKey = EKeyWasConsumed;
}
return returnKey;
}
////////////////////////////////////////////////////////////////////////
void CGameAppView::StartGameL()
{
if(!iGameStarted)
{
iGameStarted = ETrue;
iEngine->StartFirstGameL();
}
else
iEngine->StartGameL();
}
////////////////////////////////////////////////////////////////////////
void CGameAppView::StopGame()
{
iEngine->StopGame();
}
////////////////////////////////////////////////////////////////////////
TBool CGameAppView::IsPlaying()
{
return iEngine->Playing();
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
App::KeyType CGameAppView::getKeyByScancode( int scancode )
{
switch( scancode )
{
case EStdKeyDevice0:
return App::KEY_LEFTSOFT;
case EStdKeyDevice1:
return App::KEY_RIGHTSOFT;
case EStdKeyDevice3:
return App::KEY_MIDDLE;
case EStdKeyNkpAsterisk:
return App::KEY_ASTERISK;
case '0':
return App::KEY_0;
case '1':
return App::KEY_1;
case '2':
return App::KEY_2;
case '3':
return App::KEY_3;
case '4':
return App::KEY_4;
case '5':
return App::KEY_5;
case '6':
return App::KEY_6;
case '7':
return App::KEY_7;
case '8':
return App::KEY_8;
case '9':
return App::KEY_9;
case EStdKeyLeftArrow:
return App::KEY_LEFT;
case EStdKeyRightArrow:
return App::KEY_RIGHT;
case EStdKeyUpArrow:
return App::KEY_UP;
case EStdKeyDownArrow:
return App::KEY_DOWN;
default:
return App::KEY_NONE;
}
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -