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

📄 s60testengine.cpp

📁 基于Symbian OS的手机开发与应用:第12章游戏--俄罗斯方块示例源程序。
💻 CPP
字号:
#include <aknnotewrappers.h>
#include <e32def.h>

#include "s60testdocument.h"
#include "s60testengine.h"
#include "s60test.pan"
#include "step6.rsg"

CS60TestEngine *CS60TestEngine::NewLC(CS60TestDocument *aDoc)
{
  CS60TestEngine *self=new(ELeave) CS60TestEngine(aDoc);
  CleanupStack::PushL(self);
  self->ConstructL();
  return self;
}

CS60TestEngine *CS60TestEngine::NewL(CS60TestDocument *aDoc)
{
  CS60TestEngine *self=CS60TestEngine::NewLC(aDoc);
  CleanupStack::Pop(self);
  return self;
}


void CS60TestEngine::ConstructL()
{
  CTimer::ConstructL();
  CActiveScheduler::Add(this);
  After(iInterval);
  iState=ERunning;
}

void CS60TestEngine::KeyLeft()
{
  iDoc->MoveBlock(iDoc->iBlockPos-TPoint(1, 0));
}

void CS60TestEngine::KeyRight()
{
  iDoc->MoveBlock(iDoc->iBlockPos+TPoint(1, 0));
}

void CS60TestEngine::KeyDrop()
{
  while (iDoc->MoveBlock(iDoc->iBlockPos+TPoint(0, 1)))
    ;
}

void CS60TestEngine::KeyRotate(int dir)
{
  iDoc->RotateBlock(dir);
}

void CS60TestEngine::Reset()
{
  if (iState==ERunning)
    Cancel();
  iPauseRef=0;
  if (iTechPauseRef==0)
  {
    After(iInterval);
    iState=ERunning;
  } else
  {
    iPauseTime.HomeTime();
    iBeginTime.HomeTime();
    iState=EPaused;
  }
}

void CS60TestEngine::DoPause()
{
  __ASSERT_ALWAYS(iPauseRef>=0 && iTechPauseRef>=0, Panic(ES60TestAssert));

  if (iPauseRef==0 && iTechPauseRef==0)
  {
    if (iState==EPaused)
    {
      int ms=iPauseTime.MicroSecondsFrom(iBeginTime).Int64().GetTInt();
      if (ms<0 || ms>iInterval)
        ms=0;
      iState=ERunning;
      After(iInterval-ms);
    }
  } else
  {
    if (iState==ERunning)
    {
      iState=EPaused;
      iPauseTime.HomeTime();
      Cancel();
    }
  }
}

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);
}

⌨️ 快捷键说明

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