int i, j;
TFixedArray
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; i
iDoc->GetRowContent(i, arr);
for (j=0; j
gc.SetBrushColor(KColors[arr[j]]);
if (arr[j])
gc.DrawRect(TRect(KBoardOffset+KCellSize*j, KBoardOffset+KCellSize*i,
KBoardOffset+KCellSize*(j+1)+1, KBoardOffset+KCellSize*(i+1)+1));
}
}
}
我们用TGrid获得方块类型,用DrawLine和DrawRect来画背板,用SetPenColor来控制边框和线条的颜色,用SetBrushStyle/SetBrushColor来控制背板小方块的颜色,所以CWindowGc的方法可以查看SDK帮助文件。
我们需要对每个按键起作用,每次按键产生一个事件,该事件首先送给CS60TestAppView处理,将压到AddStackL栈顶部,缺省执行是返回EKeyWasNoConsumed,接下来此事件将送给CS60TestAppUi处理,在这个类中将用HandlKeyEventL来处理对应的按键.
KeyResponse 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;
}
但方格有变化时,我们将重画屏幕,CS60TestAppUi::UpdateBroad里的DrawDeferred来刷新整个屏幕。
好的设计是对每个按键都用EKeyWasConsumed来响应,我们会用EKeyWasNotConsumed来处理一些无用的按键。
最后在菜单里加入“new game”选项.
MENU_ITEM {command = ES60TestNewGame; txt = "New Game";}