diff -urN step2/group/S60test.mmp step3/group/S60test.mmp --- step2/group/S60test.mmp 2004-06-19 21:24:26.000000000 +0200 +++ step3/group/S60test.mmp 2004-06-19 21:12:32.000000000 +0200 @@ -1,7 +1,7 @@ -TARGET Step2.app +TARGET Step3.app TARGETTYPE app -UID 0x100039CE 0x04545FF2 -TARGETPATH \system\apps\Step2 +UID 0x100039CE 0x04545FF3 +TARGETPATH \system\apps\Step3 LANG SC SOURCEPATH ..\src @@ -14,7 +14,7 @@ SOURCE Grid.cpp SOURCEPATH ..\group -RESOURCE Step2.rss +RESOURCE Step3.rss USERINCLUDE ..\inc diff -urN step2/inc/s60testappui.h step3/inc/s60testappui.h --- step2/inc/s60testappui.h 2004-06-19 21:34:16.000000000 +0200 +++ step3/inc/s60testappui.h 2004-06-19 21:06:08.000000000 +0200 @@ -14,9 +14,12 @@ void ConstructL(); CS60TestAppUi(CS60TestDocument *aDoc); ~CS60TestAppUi(); + void UpdateBoard(); public: // from CAknAppUi void HandleCommandL(TInt aCommand); + TKeyResponse HandleKeyEventL(const TKeyEvent& /*aKeyEvent*/, + TEventCode /*aType*/); private: CS60TestAppView *iAppView; diff -urN step2/inc/s60testappview.h step3/inc/s60testappview.h --- step2/inc/s60testappview.h 2004-06-20 10:05:38.000000000 +0200 +++ step3/inc/s60testappview.h 2004-06-20 10:12:48.000000000 +0200 @@ -13,6 +13,8 @@ static CS60TestAppView* NewLC(const TRect& aRect, CS60TestDocument *aDoc); ~CS60TestAppView(); + static const TUint32 KColors[10]; + public: // from CCoeControl void Draw(const TRect& aRect) const; diff -urN step2/inc/s60testdocument.h step3/inc/s60testdocument.h --- step2/inc/s60testdocument.h 2004-06-20 17:39:24.000000000 +0200 +++ step3/inc/s60testdocument.h 2004-06-19 21:23:20.000000000 +0200 @@ -22,6 +22,8 @@ void NewBlock(); void Reset(); bool IsBlock(const TPoint &p) const; + bool MoveBlock(const TPoint &p); + bool RotateBlock(int dir); bool FixBlock(); TGrid iGrid; diff -urN step2/src/s60testapplication.cpp step3/src/s60testapplication.cpp --- step2/src/s60testapplication.cpp 2004-06-20 10:06:46.000000000 +0200 +++ step3/src/s60testapplication.cpp 2004-06-20 10:13:08.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 = {0x04545FF2}; +static const TUid KUidS60TestApp = {0x04545FF3}; CApaDocument* CS60TestApplication::CreateDocumentL() { diff -urN step2/src/s60testappui.cpp step3/src/s60testappui.cpp --- step2/src/s60testappui.cpp 2004-06-19 21:34:22.000000000 +0200 +++ step3/src/s60testappui.cpp 2004-06-19 21:17:30.000000000 +0200 @@ -31,6 +31,11 @@ } } +void CS60TestAppUi::UpdateBoard() +{ + iAppView->DrawDeferred(); +} + // handle any menu commands void CS60TestAppUi::HandleCommandL(TInt aCommand) { @@ -41,9 +46,47 @@ Exit(); break; + case ES60TestNewGame: + iDoc->Reset(); + UpdateBoard(); + break; + default: Panic(ES60TestBasicUi); break; } } +TKeyResponse CS60TestAppUi::HandleKeyEventL(const TKeyEvent &aKeyEvent, + TEventCode aType) +{ + if (aType==EEventKey) + { + if (aKeyEvent.iCode==EKeyUpArrow) + if (iDoc->iBlockPos.iY>0) + iDoc->MoveBlock(iDoc->iBlockPos-TPoint(0, 1)); + + if (aKeyEvent.iCode==EKeyDownArrow) + iDoc->MoveBlock(iDoc->iBlockPos+TPoint(0, 1)); + + if (aKeyEvent.iCode==EKeyLeftArrow) + iDoc->MoveBlock(iDoc->iBlockPos-TPoint(1, 0)); + + if (aKeyEvent.iCode==EKeyRightArrow) + iDoc->MoveBlock(iDoc->iBlockPos+TPoint(1, 0)); + + if (aKeyEvent.iCode==EKeyDevice3) + { + if (iDoc->FixBlock()) + iDoc->NewBlock(); + } + + if (aKeyEvent.iCode=='1') + iDoc->RotateBlock(-1); + + if (aKeyEvent.iCode=='0' || aKeyEvent.iCode=='3') + iDoc->RotateBlock(1); + } + return EKeyWasNotConsumed; +} + diff -urN step2/src/s60testappview.cpp step3/src/s60testappview.cpp --- step2/src/s60testappview.cpp 2004-06-19 21:59:56.000000000 +0200 +++ step3/src/s60testappview.cpp 2004-06-19 21:19:30.000000000 +0200 @@ -4,6 +4,10 @@ #include "S60TestAppView.h" #include "S60TestDocument.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 *self=CS60TestAppView::NewLC(aRect, aDoc); @@ -35,15 +39,37 @@ ActivateL(); } +const int KCellSize=7; +const int KBoardOffset=2; + void CS60TestAppView::Draw(const TRect& /*aRect*/) const { CWindowGc &gc=SystemGc(); TRect rect=Rect(); gc.Clear(rect); - TBuf<64> napis; - _LIT(format, "Drawing area %dx%d"); - napis.Format(format, rect.Width(), rect.Height()); - gc.UseFont(iCoeEnv->NormalFont()); - gc.DrawText(napis, TPoint(5, 50)); + int i, j; + TFixedArray arr; + gc.SetPenColor(TRgb(0)); + gc.SetBrushStyle(CWindowGc::ESolidBrush); + + for (i=0; i<=KGridY; i++) + gc.DrawLine(TPoint(KBoardOffset, KBoardOffset+KCellSize*i), + TPoint(KBoardOffset+KGridX*KCellSize, KBoardOffset+KCellSize*i)); + + for (i=0; i<=KGridX; i++) + gc.DrawLine(TPoint(KBoardOffset+KCellSize*i, KBoardOffset), + TPoint(KBoardOffset+KCellSize*i, KBoardOffset+KGridY*KCellSize)); + + for (i=0; iGetRowContent(i, arr); + for (j=0; jUpdateBoard(); + return true; +} + bool CS60TestDocument::FixBlock() { int i; @@ -62,6 +70,18 @@ return true; } +bool CS60TestDocument::RotateBlock(int dir) +{ + iCurrBlock.Rotate(dir); + if (iGrid.DoesCollide(iCurrBlock, iBlockPos)) + { + iCurrBlock.Rotate(-dir); + return false; + } + iAppUi->UpdateBoard(); + return true; +} + bool CS60TestDocument::IsBlock(const TPoint &p) const { if (p.iX>=iBlockPos.iX && p.iX