📄 gamestartcontainer.cpp
字号:
#include <aknviewappui.h>
#include <aknconsts.h>
#include <aknutils.h>
#include <eikappui.h>
#include <coemain.h>
#include <eikenv.h>
#include <fbs.h>
#include <s32file.h>
#include <bautils.h>
#include <aknquerydialog.h> //Dialog box
#include <akntitle.h>
#include <barsread.h> //for ResouceReader
#include "GamestartContainer.h"
#include "lvtetris.rsg"
#include "lvtetris.hrh"
#include <lvtetris.mbg>
#include "LvtetrisEngine.h"
#include "LvtetrisMenu.h"
//#include <akncontext.h>
//#include <akngrid.h>
_LIT(KMbmFile, "\\System\\Apps\\LvTetris\\Lvtetris.mbm");
CGamestartContainer::CGamestartContainer()
{
backBuffer = NULL;
backBufferDevice = NULL;
backBufferGc = NULL;
iBackground = NULL;
iFrameStatus = 0;
// iStatus = GAMEINITIAL;
iLevel = ENormal;
iEngine = NULL;
iMenu = NULL;
iFrame = 0;
iDrawflag = 0;
}
CGamestartContainer::~CGamestartContainer()
{
iTimer->Cancel();
delete iTimer;
delete backBuffer;
delete backBufferDevice;
delete backBufferGc;
delete iBackground;
delete iEngine;
delete iMenu;
iTimer = NULL;
backBuffer = NULL;
backBufferDevice = NULL;
backBufferGc = NULL;
iBackground = NULL;
iEngine = NULL;
iMenu = NULL;
}
CGamestartContainer* CGamestartContainer::NewL( const TRect& aRect)
{
CGamestartContainer* self = CGamestartContainer::NewLC( aRect);
CleanupStack::Pop( self);
return self;
}
CGamestartContainer* CGamestartContainer::NewLC( const TRect& aRect)
{
CGamestartContainer* self = new ( ELeave ) CGamestartContainer;
CleanupStack::PushL( self);
self->ConstructL( aRect);
return self;
}
void CGamestartContainer::ConstructL( const TRect& aRect)
{
CreateWindowL();
//iRect = aRect;
iWidth = aRect.Width();
iHeight = aRect.Height();
//get bitmap back buffer
backBuffer = new (ELeave) CFbsBitmap();
// CleanupStack::PushL(backBuffer);
backBuffer->Create(CEikonEnv::Static()->ScreenDevice()->SizeInPixels(), CEikonEnv::Static()->DefaultDisplayMode());
//get bitmap back buffer device
backBufferDevice = CFbsBitmapDevice::NewL(backBuffer);
// CleanupStack::PushL(backBufferDevice);
//get bitmap back buffer device's graphic context
User::LeaveIfError(backBufferDevice->CreateContext(backBufferGc));
iBackground = iEikonEnv->CreateBitmapL(KMbmFile, EMbmLvtetrisBackground24);
// CleanupStack::PushL(iBackground);
SetRect( aRect);
ActivateL();
iEngine = CLvtetrisEngine::NewL();
// CleanupStack::PushL(iEngine);
iMenu = CLvtetrisMenu::NewL(backBufferGc);
iTimer = CPeriodic::NewL(CActive::EPriorityLow);
// CleanupStack::Pop(4);
iFrame = 40000; //25frame/sencond
iStatus = GAMEMENUING;
iEngine->iStateRunning = 0;
iTimer->Start( 0, iFrame, TCallBack(Tick, this));
}
TInt CGamestartContainer::CountComponentControls() const
{
return 0;
}
// ---------------------------------------------------------
// CCZZContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CGamestartContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex)
{
default:
return NULL;
}
}
// ---------------------------------------------------------
// CCZZContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CGamestartContainer::Draw(const TRect& aRect) const
{
aRect;
// if ( IsFocused())
// {
CWindowGc& gc = SystemGc();
gc.BitBlt(TPoint(0, 0), backBuffer);
// }
}
TKeyResponse CGamestartContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType)
{
if ( aType!=EEventKey)
return (EKeyWasConsumed);
if ( (iStatus == GAMERUNNING) || (iStatus == GAMEPAUSING))
{
if ( aType==EEventKey)
{
if (aKeyEvent.iCode == '0')
{
Continue();
return (EKeyWasConsumed);
}
iStatus = iEngine->Command(aKeyEvent.iCode);
return (EKeyWasConsumed);
}
}
else if(iStatus == GAMEMENUING)
{
iEngine->iStateRunning = 0;
iStatus = iMenu->Command(aKeyEvent.iCode);
if (iStatus == GAMERUNNING)
{
iEngine->iStateDifficulty = iMenu->Level();
iEngine->iStateRotateDir = iMenu->RotateDir();
}
return (EKeyWasConsumed);
}
else if(iStatus == GAMEOVERING)
{
if ( aType==EEventKey)
{
if(aKeyEvent.iCode == EKeyDevice0)
{
iStatus = GAMERUNNING;
return (EKeyWasConsumed);
}
else if(aKeyEvent.iCode == EKeyDevice1)
{
iStatus = GAMEMENUING;
return (EKeyWasConsumed);
}
}
}
return (EKeyWasNotConsumed);
}
//-----------------------------------//
// Custom Function in Menu //
//-----------------------------------//
TInt CGamestartContainer::Updata(void)
{
// if ( !IsFocused ())
// return 1;
if ( iFrameStatus == 0)
DoFrame();
else if ( iFrameStatus == 1)
{
DrawNow();
iFrameStatus = 0;
}
return 1;
}
void CGamestartContainer::Continue()
{
if ( iStatus == GAMEPAUSING )
{
iStatus = GAMERUNNING;
iTimer->Start( 0, iFrame, TCallBack(Tick, this));
}
else if ( iStatus == GAMERUNNING)
{
iStatus = GAMEPAUSING;
iEngine->DrawGamePauseInfor(backBufferGc);
iTimer->Cancel();
DrawNow();
// Updata();
// iStatus = GAMEPAUSING;
}
}
void CGamestartContainer::DoFrame()
{
backBufferGc->Clear();
if (iStatus == GAMERUNNING)
{
backBufferGc->BitBlt(TPoint(0, 0), iBackground);
TInt8 state = iEngine->Run();
if(state == 1) // game over
{
iStatus = GAMEOVERING;
return;
}
// if( iDrawflag || state == 2)
// {
iEngine->DrawTetris(backBufferGc);
// }
}
else if (iStatus == GAMEPAUSING)
{
// iEngine->DrawGamePauseInfor(backBufferGc);
}
else if (iStatus == GAMEOVERING)
{
iEngine->DrawGameOverInfor(backBufferGc);
DrawNow();
}
else if (iStatus == GAMEMENUING)
{
iMenu->DrawMenu();
}
iFrameStatus = 1;
}
//game state
TInt8 CGamestartContainer::GameState()
{
return iStatus;
}
/*
void CGamestartContainer::LoadBlocks()
{
}
void CGamestartContainer::DrawTetris()
{
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -