diff -urN step1/group/S60test.mmp step2/group/S60test.mmp --- step1/group/S60test.mmp 2004-06-19 21:37:40.000000000 +0200 +++ step2/group/S60test.mmp 2004-06-19 21:24:26.000000000 +0200 @@ -1,7 +1,7 @@ -TARGET Step1.app +TARGET Step2.app TARGETTYPE app -UID 0x100039CE 0x04545FF1 -TARGETPATH \system\apps\Step1 +UID 0x100039CE 0x04545FF2 +TARGETPATH \system\apps\Step2 LANG SC SOURCEPATH ..\src @@ -10,9 +10,11 @@ SOURCE S60TestAppView.cpp SOURCE S60TestAppUi.cpp SOURCE S60TestDocument.cpp +SOURCE Block.cpp +SOURCE Grid.cpp SOURCEPATH ..\group -RESOURCE Step1.rss +RESOURCE Step2.rss USERINCLUDE ..\inc diff -urN step1/group/step2.rss step2/group/step2.rss --- step1/group/step2.rss 2004-06-19 21:40:30.000000000 +0200 +++ step2/group/step2.rss 2004-06-19 20:58:42.000000000 +0200 @@ -67,7 +67,8 @@ { items = { - MENU_ITEM {command = ES60TestHello; txt = "Hello";}, + MENU_ITEM {command = ES60TestNewGame; txt = "New Game";}, + MENU_ITEM {command = ES60TestPause; txt = "Pause";}, MENU_ITEM {command = EAknSoftkeyExit; txt = "Exit";} }; } diff -urN step1/inc/block.h step2/inc/block.h --- step1/inc/block.h 1970-01-01 01:00:00.000000000 +0100 +++ step2/inc/block.h 2003-12-25 20:27:22.000000000 +0100 @@ -0,0 +1,24 @@ +#ifndef BLOCK_H +#define BLOCK_H + +#include + +class TBlock +{ +public: + TBlock() :iType(0), iRot(0) {} + static int BlockCount(); + static TBlock Block(int id); + static TBlock RandomBlock(TInt64 &seed); + + void Rotate(int dir); + TInt8 RowMask(int nr) const; + TInt8 Color() const; +protected: + TBlock(int aType, int aRot) :iType(aType), iRot(aRot) { } +private: + TInt8 iType; + TInt8 iRot; +}; + +#endif \ No newline at end of file diff -urN step1/inc/grid.h step2/inc/grid.h --- step1/inc/grid.h 1970-01-01 01:00:00.000000000 +0100 +++ step2/inc/grid.h 2003-11-11 22:36:08.000000000 +0100 @@ -0,0 +1,22 @@ +#ifndef GRID_H +#define GRID_H + +#include +#include "block.h" + +const int KGridX=10; +const int KGridY=20; + +class TGrid +{ +public: + TFixedArray iMask; + TFixedArray, KGridY> iContent; + + TGrid(); + bool DoesCollide(const TBlock &b, const TPoint &p) const; + void PutBlock(const TBlock &b, const TPoint &p); + void Clear(); +}; + +#endif diff -urN step1/inc/s60test.hrh step2/inc/s60test.hrh --- step1/inc/s60test.hrh 2004-06-19 21:44:42.000000000 +0200 +++ step2/inc/s60test.hrh 2004-06-20 10:06:28.000000000 +0200 @@ -3,7 +3,8 @@ enum TS60TestIds { - ES60TestHello = 1 // start value must not be 0 + ES60TestNewGame = 1, // start value must not be 0 + ES60TestPause }; diff -urN step1/inc/s60testdocument.h step2/inc/s60testdocument.h --- step1/inc/s60testdocument.h 2004-06-19 21:48:00.000000000 +0200 +++ step2/inc/s60testdocument.h 2004-06-20 17:39:24.000000000 +0200 @@ -3,19 +3,32 @@ #include +#include "grid.h" +#include "block.h" + // Forward references class CEikAppUi; class CEikApplication; class CS60TestAppUi; + class CS60TestDocument : public CAknDocument { public: static CS60TestDocument* NewL(CEikApplication& aApp); static CS60TestDocument* NewLC(CEikApplication& aApp); ~CS60TestDocument(); - + void GetRowContent(int nr, TFixedArray &row) const; + void NewBlock(); + void Reset(); + bool IsBlock(const TPoint &p) const; + bool FixBlock(); + + TGrid iGrid; + TBlock iCurrBlock; + TPoint iBlockPos; CS60TestAppUi *iAppUi; + TInt64 seed; public: // from CAknDocument CEikAppUi* CreateAppUiL(); diff -urN step1/src/block.cpp step2/src/block.cpp --- step1/src/block.cpp 1970-01-01 01:00:00.000000000 +0100 +++ step2/src/block.cpp 2003-12-25 20:27:18.000000000 +0100 @@ -0,0 +1,45 @@ +#include "block.h" +#include + +const int numBlocks=7; +const TUint16 bl_types[4][numBlocks]= +// #### ### ### ## ## ## ### +// # # ## ## ## # + {{0x4444, 0x0e20, 0x0740, 0x06c0, 0x0c60, 0x6600, 0xe400}, + {0x0f00, 0x0644, 0x4460, 0x4620, 0x2640, 0x6600, 0x8c80}, + {0x4444, 0x0470, 0x02e0, 0x06c0, 0x0c60, 0x6600, 0x04e0}, + {0x0f00, 0x2260, 0x0622, 0x4620, 0x2640, 0x6600, 0x2620}, + }; + +int TBlock::BlockCount() +{ + return numBlocks; +} + +TBlock TBlock::Block(int id) +{ + return TBlock(id, 0); +} + +TBlock TBlock::RandomBlock(TInt64 &seed) +{ + return Block(Math::Rand(seed)%numBlocks); +} + +void TBlock::Rotate(int dir) +{ + if (dir>0) iRot++; + if (dir<0) iRot+=3; + iRot%=4; +} + +TInt8 TBlock::RowMask(int nr) const +{ + return (bl_types[iRot][iType]>>(4*nr))&0xf; +} + +TInt8 TBlock::Color() const +{ + return iType+1; +} + diff -urN step1/src/grid.cpp step2/src/grid.cpp --- step1/src/grid.cpp 1970-01-01 01:00:00.000000000 +0100 +++ step2/src/grid.cpp 2004-01-11 21:46:42.000000000 +0100 @@ -0,0 +1,55 @@ +#include "grid.h" +#include "s60test.pan" + +TGrid::TGrid() +{ + Clear(); +} + +void TGrid::Clear() +{ + for (int i=0; i(b.RowMask(i-p.iY))<<(12-p.iX))&0xf003f) + return true; + } else + if (i>=KGridY) + { + if (b.RowMask(i-p.iY)) return true; + } else + { + if (iMask[i]&(b.RowMask(i-p.iY)<<(12-p.iX))) return true; + if (p.iX<0 && ((b.RowMask(i-p.iY)>>(4+p.iX)))) return true; + } + } + return false; +} + +void TGrid::PutBlock(const TBlock &b, const TPoint &p) +{ + int i, j; + int c=b.Color(); + for (i=p.iY; i=KGridY) break; + TUint16 mask=b.RowMask(i-p.iY); + iMask[i]|=mask<<(12-p.iX); + for (j=p.iX; jExecuteLD(message); - } - break; - default: Panic(ES60TestBasicUi); break; diff -urN step1/src/s60testdocument.cpp step2/src/s60testdocument.cpp --- step1/src/s60testdocument.cpp 2004-06-19 21:50:26.000000000 +0200 +++ step2/src/s60testdocument.cpp 2004-06-20 17:39:06.000000000 +0200 @@ -19,10 +19,17 @@ void CS60TestDocument::ConstructL() { + TTime time; + time.HomeTime(); + seed=time.Int64(); + Reset(); } CS60TestDocument::CS60TestDocument(CEikApplication& aApp) -:CAknDocument(aApp) +:CAknDocument(aApp), + iGrid(), + iCurrBlock(), + iBlockPos(3, -4) { } @@ -30,6 +37,49 @@ { } +void CS60TestDocument::Reset() +{ + iGrid.Clear(); + iBlockPos=TPoint(3, -4); + iCurrBlock=TBlock::RandomBlock(seed); +} + +void CS60TestDocument::NewBlock() +{ + iCurrBlock=TBlock::RandomBlock(seed); + iBlockPos=TPoint(3, -4); +} + +bool CS60TestDocument::FixBlock() +{ + int i; + // check if it is outside the board + for (i=0; i<-iBlockPos.iY; i++) + if (iCurrBlock.RowMask(i)) + return false; + + iGrid.PutBlock(iCurrBlock, iBlockPos); + return true; +} + +bool CS60TestDocument::IsBlock(const TPoint &p) const +{ + if (p.iX>=iBlockPos.iX && p.iX=iBlockPos.iY && p.iY0; + return false; +} + +void CS60TestDocument::GetRowContent(int nr, TFixedArray &row) const +{ + int i; + for (i=0; i