CTimer是一个需激活对象,我们用CActiveScheduler::Add(this)将它加入时间表队列。
void CS60TestEngine::ConstructL()
{
CTimer::ConstructL();
CActiveScheduler::Add(this);
After(iInterval);
iState=ERunning;
}
但用户重新玩游戏,将先用Cancel()来结束,在隔一定时间后重新开始.
void CS60TestEngine::Reset()
{
if (iState==ERunning)
Cancel();
iState=ERunning;
After(iInterval);
}
在RunL里,方块延一条线下坠,但它不能再下坠时我们将固定此方块,再产生新的方块,
void CS60TestEngine::RunL()
{
if (!iDoc->MoveBlock(iDoc->iBlockPos+TPoint(0, 1)))
{
if (!iDoc->FixBlock())
{
// Game over
TBuf<64> message;
CEikonEnv::Static()->ReadResource(message, R_NOTE_GAME_OVER);
CAknInformationNote *informationNote=new(ELeave) CAknInformationNote;
informationNote->ExecuteLD(message);
iState=EGameOver;
return;
}
iDoc->CheckRows();
if (iDoc->iLevel<=(iDoc->iLines/10))
{
iInterval*=3;
iInterval/=4;
iDoc->iLevel++;
}
iDoc->NewBlock();
}
iBeginTime.HomeTime();
After(iInterval);
}
但不能再放方块时,我们将结束游戏,并显示一段文字
CEikonEnv::Static()->ReadResource(message, R_NOTE_GAME_OVER)
结束游戏引擎
iState=EGameOver。
我们将在资源文件中加载”game over”,这样我们只要翻译资源文件就可将游戏翻译成不同的语言,s60test.rss在加入TBUF型字符串
RESOURCE TBUF32 r_note_game_over
{
buf = "Game Over";
}
Build 将其建成s60test..rsg文件,在这个文件中R_NOTE_GAME_OVER定义成ID,通过
CEikonEnv::Static()->ReadResource(message, R_NOTE_GAME_OVER)
来加载“game over”