diff -urN step3/group/S60test.mmp step4/group/S60test.mmp --- step3/group/S60test.mmp 2004-06-19 21:12:32.000000000 +0200 +++ step4/group/S60test.mmp 2004-06-19 20:27:56.000000000 +0200 @@ -1,7 +1,7 @@ -TARGET Step3.app +TARGET Step4.app TARGETTYPE app -UID 0x100039CE 0x04545FF3 -TARGETPATH \system\apps\Step3 +UID 0x100039CE 0x04545FF4 +TARGETPATH \system\apps\Step4 LANG SC SOURCEPATH ..\src @@ -10,11 +10,12 @@ SOURCE S60TestAppView.cpp SOURCE S60TestAppUi.cpp SOURCE S60TestDocument.cpp +SOURCE S60TestEngine.cpp SOURCE Block.cpp SOURCE Grid.cpp SOURCEPATH ..\group -RESOURCE Step3.rss +RESOURCE Step4.rss USERINCLUDE ..\inc diff -urN step3/group/Step4.rss step4/group/Step4.rss --- step3/group/Step4.rss 2004-06-19 20:58:42.000000000 +0200 +++ step4/group/Step4.rss 2004-06-19 20:46:58.000000000 +0200 @@ -72,3 +72,9 @@ MENU_ITEM {command = EAknSoftkeyExit; txt = "Exit";} }; } + +RESOURCE TBUF32 r_note_game_over +{ + buf = "Game Over"; +} + diff -urN step3/inc/s60testappui.h step4/inc/s60testappui.h --- step3/inc/s60testappui.h 2004-06-19 21:06:08.000000000 +0200 +++ step4/inc/s60testappui.h 2004-06-19 20:29:04.000000000 +0200 @@ -2,6 +2,7 @@ #define __S60TEST_APPUI_H__ #include +#include "s60testengine.h" class CS60TestDocument; @@ -22,6 +23,7 @@ TEventCode /*aType*/); private: + CS60TestEngine *iEngine; CS60TestAppView *iAppView; CS60TestDocument *iDoc; }; diff -urN step3/inc/s60testappview.h step4/inc/s60testappview.h --- step3/inc/s60testappview.h 2004-06-20 10:12:48.000000000 +0200 +++ step4/inc/s60testappview.h 2004-06-20 10:31:56.000000000 +0200 @@ -5,12 +5,13 @@ #include class CS60TestDocument; +class CS60TestEngine; class CS60TestAppView : public CCoeControl { public: - static CS60TestAppView* NewL(const TRect& aRect, CS60TestDocument *aDoc); - static CS60TestAppView* NewLC(const TRect& aRect, CS60TestDocument *aDoc); + static CS60TestAppView* NewL(const TRect& aRect, CS60TestDocument *aDoc, CS60TestEngine *aEngine); + static CS60TestAppView* NewLC(const TRect& aRect, CS60TestDocument *aDoc, CS60TestEngine *aEngine); ~CS60TestAppView(); static const TUint32 KColors[10]; @@ -20,8 +21,9 @@ private: void ConstructL(const TRect& aRect); - CS60TestAppView(CS60TestDocument *aDoc); + CS60TestAppView(CS60TestDocument *aDoc, CS60TestEngine *aEngine); CS60TestDocument *iDoc; + CS60TestEngine *iEngine; }; diff -urN step3/inc/s60testdocument.h step4/inc/s60testdocument.h --- step3/inc/s60testdocument.h 2004-06-19 21:23:20.000000000 +0200 +++ step4/inc/s60testdocument.h 2004-06-20 10:30:30.000000000 +0200 @@ -19,6 +19,7 @@ static CS60TestDocument* NewLC(CEikApplication& aApp); ~CS60TestDocument(); void GetRowContent(int nr, TFixedArray &row) const; + int CheckRows(); void NewBlock(); void Reset(); bool IsBlock(const TPoint &p) const; @@ -29,6 +30,9 @@ TGrid iGrid; TBlock iCurrBlock; TPoint iBlockPos; + TInt32 iScore; + TInt16 iLines; + TInt16 iLevel; CS60TestAppUi *iAppUi; TInt64 seed; diff -urN step3/inc/s60testengine.h step4/inc/s60testengine.h --- step3/inc/s60testengine.h 1970-01-01 01:00:00.000000000 +0100 +++ step4/inc/s60testengine.h 2004-06-21 18:55:36.000000000 +0200 @@ -0,0 +1,42 @@ +#ifndef S60TESTENGINE +#define S60TESTENGINE + +#include "e32base.h" + +class CS60TestDocument; + +class CS60TestEngine : public CTimer +{ +public: + static CS60TestEngine* NewLC(CS60TestDocument *aDoc); + static CS60TestEngine* NewL(CS60TestDocument *aDoc); + + void KeyLeft(); + void KeyRight(); + void KeyRotate(int dir); + void KeyDrop(); + + void Reset(); + + int iInterval; + TTime iBeginTime; + TTime iPauseTime; + + enum TEngineState + { + EGameOver=0, + EPaused, + ERunning + }; + TEngineState iState; + +protected: + CS60TestDocument *iDoc; + + CS60TestEngine(CS60TestDocument *aDoc) + :CTimer(EPriorityStandard), iInterval(500000), iDoc(aDoc) { } + void RunL(); + void ConstructL(); +}; + +#endif diff -urN step3/src/s60testapplication.cpp step4/src/s60testapplication.cpp --- step3/src/s60testapplication.cpp 2004-06-20 10:13:08.000000000 +0200 +++ step4/src/s60testapplication.cpp 2004-06-20 10:31:26.000000000 +0200 @@ -2,7 +2,7 @@ #include "S60TestApplication.h" // UID for the application, this should correspond to the uid defined in the mmp file -static const TUid KUidS60TestApp = {0x04545FF3}; +static const TUid KUidS60TestApp = {0x04545FF4}; CApaDocument* CS60TestApplication::CreateDocumentL() { diff -urN step3/src/s60testappui.cpp step4/src/s60testappui.cpp --- step3/src/s60testappui.cpp 2004-06-19 21:17:30.000000000 +0200 +++ step4/src/s60testappui.cpp 2004-06-20 10:28:08.000000000 +0200 @@ -12,11 +12,13 @@ { BaseConstructL(); - iAppView=CS60TestAppView::NewL(ClientRect(), iDoc); + iEngine=CS60TestEngine::NewL(iDoc); + iAppView=CS60TestAppView::NewL(ClientRect(), iDoc, iEngine); AddToStackL(iAppView); } CS60TestAppUi::CS60TestAppUi(CS60TestDocument *aDoc) +:iEngine(NULL) { iDoc=aDoc; } @@ -29,6 +31,7 @@ delete iAppView; iAppView = NULL; } + delete iEngine; } void CS60TestAppUi::UpdateBoard() @@ -48,6 +51,7 @@ case ES60TestNewGame: iDoc->Reset(); + iEngine->Reset(); UpdateBoard(); break; @@ -63,29 +67,22 @@ if (aType==EEventKey) { if (aKeyEvent.iCode==EKeyUpArrow) - if (iDoc->iBlockPos.iY>0) - iDoc->MoveBlock(iDoc->iBlockPos-TPoint(0, 1)); + iEngine->KeyRotate(1); if (aKeyEvent.iCode==EKeyDownArrow) - iDoc->MoveBlock(iDoc->iBlockPos+TPoint(0, 1)); + iEngine->KeyDrop(); if (aKeyEvent.iCode==EKeyLeftArrow) - iDoc->MoveBlock(iDoc->iBlockPos-TPoint(1, 0)); + iEngine->KeyLeft(); if (aKeyEvent.iCode==EKeyRightArrow) - iDoc->MoveBlock(iDoc->iBlockPos+TPoint(1, 0)); - - if (aKeyEvent.iCode==EKeyDevice3) - { - if (iDoc->FixBlock()) - iDoc->NewBlock(); - } + iEngine->KeyRight(); if (aKeyEvent.iCode=='1') - iDoc->RotateBlock(-1); + iEngine->KeyRotate(-1); if (aKeyEvent.iCode=='0' || aKeyEvent.iCode=='3') - iDoc->RotateBlock(1); + iEngine->KeyRotate(1); } return EKeyWasNotConsumed; } diff -urN step3/src/s60testappview.cpp step4/src/s60testappview.cpp --- step3/src/s60testappview.cpp 2004-06-19 21:19:30.000000000 +0200 +++ step4/src/s60testappview.cpp 2004-06-20 16:23:20.000000000 +0200 @@ -3,29 +3,31 @@ #include "S60TestAppView.h" #include "S60TestDocument.h" +#include "S60TestEngine.h" const TUint32 CS60TestAppView::KColors[10]= {0xffffff, 0xff0000, 0x00ff00, 0x0000ff, 0xff00ff, 0xcc00dd, 0xadbeef, 0x000000, 0xffff00, 0xaaaaaa}; -CS60TestAppView *CS60TestAppView::NewL(const TRect& aRect, CS60TestDocument *aDoc) +CS60TestAppView *CS60TestAppView::NewL(const TRect& aRect, CS60TestDocument *aDoc, CS60TestEngine *aEngine) { - CS60TestAppView *self=CS60TestAppView::NewLC(aRect, aDoc); + CS60TestAppView *self=CS60TestAppView::NewLC(aRect, aDoc, aEngine); CleanupStack::Pop(self); return self; } -CS60TestAppView* CS60TestAppView::NewLC(const TRect& aRect, CS60TestDocument *aDoc) +CS60TestAppView* CS60TestAppView::NewLC(const TRect& aRect, CS60TestDocument *aDoc, CS60TestEngine *aEngine) { - CS60TestAppView *self=new(ELeave) CS60TestAppView(aDoc); + CS60TestAppView *self=new(ELeave) CS60TestAppView(aDoc, aEngine); CleanupStack::PushL(self); self->ConstructL(aRect); return self; } -CS60TestAppView::CS60TestAppView(CS60TestDocument *aDoc) +CS60TestAppView::CS60TestAppView(CS60TestDocument *aDoc, CS60TestEngine *aEngine) { iDoc=aDoc; + iEngine=aEngine; } CS60TestAppView::~CS60TestAppView() diff -urN step3/src/s60testdocument.cpp step4/src/s60testdocument.cpp --- step3/src/s60testdocument.cpp 2004-06-19 21:20:32.000000000 +0200 +++ step4/src/s60testdocument.cpp 2004-06-20 10:27:38.000000000 +0200 @@ -41,6 +41,9 @@ { iGrid.Clear(); iBlockPos=TPoint(3, -4); + iScore=0; + iLines=0; + iLevel=1; iCurrBlock=TBlock::RandomBlock(seed); } @@ -70,6 +73,38 @@ return true; } +int CS60TestDocument::CheckRows() +{ + int offset=0, i, j; + for (i=KGridY-1; i>=0; i--) + { + if (iGrid.iMask[i]==0xffffU) + { + offset++; + iScore++; + iLines++; + continue; + } + + if (offset>0) + { + iGrid.iMask[i+offset]=iGrid.iMask[i]; + for (j=0; j0) iAppUi->UpdateBoard(); + return offset; +} + bool CS60TestDocument::RotateBlock(int dir) { iCurrBlock.Rotate(dir); diff -urN step3/src/s60testengine.cpp step4/src/s60testengine.cpp --- step3/src/s60testengine.cpp 1970-01-01 01:00:00.000000000 +0100 +++ step4/src/s60testengine.cpp 2004-06-21 18:56:10.000000000 +0200 @@ -0,0 +1,91 @@ +#include +#include + +#include "s60testdocument.h" +#include "s60testengine.h" +#include "s60test.pan" +#include "step4.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(); + iState=ERunning; + After(iInterval); +} + +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); +} +