📄 colorlinezuitwplay.cpp
字号:
/*
========================================================================
Name : ColorLinezUITwPlay.cpp
Author :
Copyright :
Description :
========================================================================
*/
// [[[ begin generated region: do not modify [Generated System Includes]
#include <barsread.h>
#include <eikimage.h>
#include <eikenv.h>
#include <aknviewappui.h>
#include <eikappui.h>
#include <akniconutils.h>
#include <ColorLinezUITwo_aif.mbg>
#include <ColorLinezUITwo.rsg>
// ]]] end generated region [Generated System Includes]
#include <e32math.h>
// [[[ begin generated region: do not modify [Generated User Includes]
#include "ColorLinezUITwPlay.h"
#include "ColorLinezUITwPlayView.h"
#include "ColorLinezUITwo.hrh"
#include "ColorLinezUITwoInitial.hrh"
#include "ColorLinezUITwPlay.hrh"
// ]]] end generated region [Generated User Includes]
// [[[ begin generated region: do not modify [Generated Constants]
_LIT( KColorLinezUITwo_aifFile, "\\resource\\apps\\ColorLinezUITwo_aif.mif" );
// ]]] end generated region [Generated Constants]
const TInt KTimeoutValue = 1000000;
/**
* First phase of Symbian two-phase construction. Should not
* contain any code that could leave.
*/
CColorLinezUITwPlay::CColorLinezUITwPlay(CColorLinezUITwoModel& aModel)
:iModel(aModel)
{
// [[[ begin generated region: do not modify [Generated Contents]
iImage1 = NULL;
iImage2 = NULL;
iImage3 = NULL;
// ]]] end generated region [Generated Contents]
GetLastBitmap = NULL;
iScore = 0;
}
/**
* Destroy child controls.
*/
CColorLinezUITwPlay::~CColorLinezUITwPlay()
{
delete iBkgBitmap;
iBkgBitmap = NULL;
delete iBkgBasicPaneBitmap;
delete iBkgBallsBitmap[0];
delete iBkgBallsBitmap[1];
delete iBkgBallsBitmap[2];
delete iBkgBallsSelectedBmp[0];
delete iBkgBallsSelectedBmp[1];
delete iBkgBallsSelectedBmp[2];
delete iBkgBallsPassedBmp[0];
delete iBkgBallsPassedBmp[1];
delete iBkgBallsPassedBmp[2];
delete GetCurrentBitmap;
delete GetLastBitmap;
delete iTempCurrentBmp;
delete iLastBmp;
delete iCurrentBmp;
delete iNaviDecorator;
delete iNaviPane;
iTempCurrentBmp = NULL;
iBkgBasicPaneBitmap = NULL;
// [[[ begin generated region: do not modify [Generated Contents]
delete iImage1;
iImage1 = NULL;
delete iImage2;
iImage2 = NULL;
delete iImage3;
iImage3 = NULL;
// ]]] end generated region [Generated Contents]
}
/**
* Construct the control (first phase).
* Creates an instance and initializes it.
* Instance is not left on cleanup stack.
* @param aRect bounding rectangle
* @param aParent owning parent, or NULL
* @param aCommandObserver command observer
* @return initialized instance of CColorLinezUITwPlay
*/
CColorLinezUITwPlay* CColorLinezUITwPlay::NewL(
const TRect& aRect,
const CCoeControl* aParent,
MEikCommandObserver* aCommandObserver,
CColorLinezUITwoModel& aModel)
{
CColorLinezUITwPlay* self = CColorLinezUITwPlay::NewLC(
aRect,
aParent,
aCommandObserver,
aModel);
CleanupStack::Pop( self );
return self;
}
/**
* Construct the control (first phase).
* Creates an instance and initializes it.
* Instance is left on cleanup stack.
* @param aRect The rectangle for this window
* @param aParent owning parent, or NULL
* @param aCommandObserver command observer
* @return new instance of CColorLinezUITwPlay
*/
CColorLinezUITwPlay* CColorLinezUITwPlay::NewLC(
const TRect& aRect,
const CCoeControl* aParent,
MEikCommandObserver* aCommandObserver,
CColorLinezUITwoModel& aModel)
{
CColorLinezUITwPlay* self = new ( ELeave ) CColorLinezUITwPlay(aModel);
CleanupStack::PushL( self );
self->ConstructL( aRect, aParent, aCommandObserver );
return self;
}
/**
* Construct the control (second phase).
* Creates a window to contain the controls and activates it.
* @param aRect bounding rectangle
* @param aCommandObserver command observer
* @param aParent owning parent, or NULL
*/
void CColorLinezUITwPlay::ConstructL(
const TRect& aRect,
const CCoeControl* aParent,
MEikCommandObserver* aCommandObserver )
{
// initialize the points of panes
for(TInt pointX=0;pointX!=7;++pointX)
{
iImagePointX[pointX] = pointX*29 + 68;
for(TInt pointY=0;pointY!=7;++pointY)
{
iImagePointY[pointY] = pointY*29 + 49;
iPaneStatus[pointX][pointY] = EFalse;
}
}
iCursorPosX = 0;
iCursorPosY = 0;
iDirection = 0;
if ( aParent == NULL )
{
CreateWindowL();
}
else
{
SetContainerWindowL( *aParent );
}
iFocusControl = NULL;
iCommandObserver = aCommandObserver;
iBkgBitmap = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aifColorlinezboard);
// iBkgRedBallBitmap = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aif1);
// iBkgGreenBallBitmap = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aif2);
// iBkgBlueBallBitmap = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aif6);
iBkgBasicPaneBitmap = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aifColorlinezbasicboard);
iBkgMovePaneBitmap = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aifColorlinezbasicboardii);
iBkgBallsBitmap[0] = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aif1);
iBkgBallsBitmap[1] = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aif2);
iBkgBallsBitmap[2] = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aif6);
iBkgBallsSelectedBmp[0] = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aif1_selected);
iBkgBallsSelectedBmp[1] = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aif2_selected);
iBkgBallsSelectedBmp[2] = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aif6_selected);
iBkgBallsPassedBmp[0] = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aif1_passed);
iBkgBallsPassedBmp[1] = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aif2_passed);
iBkgBallsPassedBmp[2] = AknIconUtils::CreateIconL(KColorLinezUITwo_aifFile,EMbmColorlinezuitwo_aif6_passed);
iLastBmp = NULL;
iCurrentBmp = NULL;
IsBallsAppear = ETrue;
iIsFirstClick = ETrue;
CEikStatusPane* statusPane = iAvkonViewAppUi->StatusPane();
iNaviPane = (CAknNavigationControlContainer*)statusPane->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
iModel.SetScore(0);
UpdateNaviPaneL();
iActiveTimer = CCActiveTimer::NewL(*this);
InitializeControlsL();
SetRect( aRect );
ActivateL();
// [[[ begin generated region: do not modify [Post-ActivateL initializations]
// ]]] end generated region [Post-ActivateL initializations]
}
/**
* Return the number of controls in the container (override)
* @return count
*/
TInt CColorLinezUITwPlay::CountComponentControls() const
{
return ( int ) ELastControl;
}
/**
* Get the control with the given index (override)
* @param aIndex Control index [0...n) (limited by #CountComponentControls)
* @return Pointer to control
*/
CCoeControl* CColorLinezUITwPlay::ComponentControl( TInt aIndex ) const
{
// [[[ begin generated region: do not modify [Generated Contents]
switch ( aIndex )
{
case EImage1:
return iImage1;
case EImage2:
return iImage2;
case EImage3:
return iImage3;
}
// ]]] end generated region [Generated Contents]
// handle any user controls here...
return NULL;
}
/**
* Handle resizing of the container. This implementation will lay out
* full-sized controls like list boxes for any screen size, and will layout
* labels, editors, etc. to the size they were given in the UI designer.
* This code will need to be modified to adjust arbitrary controls to
* any screen size.
*/
void CColorLinezUITwPlay::SizeChanged()
{
CCoeControl::SizeChanged();
LayoutControls();
TInt error = AknIconUtils::SetSize(iBkgBitmap,TSize(203,203),EAspectRatioNotPreserved);
TInt error1 = AknIconUtils::SetSize(iBkgBallsBitmap[0],TSize(29,29),EAspectRatioNotPreserved);
TInt error2 = AknIconUtils::SetSize(iBkgBallsBitmap[1],TSize(29,29),EAspectRatioNotPreserved);
TInt error3 = AknIconUtils::SetSize(iBkgBallsBitmap[2],TSize(29,29),EAspectRatioNotPreserved);
TInt error6 = AknIconUtils::SetSize(iBkgBallsSelectedBmp[0],TSize(29,29),EAspectRatioNotPreserved);
TInt error7 = AknIconUtils::SetSize(iBkgBallsSelectedBmp[1],TSize(29,29),EAspectRatioNotPreserved);
TInt error8 = AknIconUtils::SetSize(iBkgBallsSelectedBmp[2],TSize(29,29),EAspectRatioNotPreserved);
TInt error4 = AknIconUtils::SetSize(iBkgBasicPaneBitmap,TSize(29,29),EAspectRatioNotPreserved);
TInt error5 = AknIconUtils::SetSize(iBkgMovePaneBitmap,TSize(29,29),EAspectRatioNotPreserved);
TInt error9 = AknIconUtils::SetSize(iBkgBallsPassedBmp[0],TSize(29,29),EAspectRatioNotPreserved);
TInt error10 = AknIconUtils::SetSize(iBkgBallsPassedBmp[1],TSize(29,29),EAspectRatioNotPreserved);
TInt error11 = AknIconUtils::SetSize(iBkgBallsPassedBmp[2],TSize(29,29),EAspectRatioNotPreserved);
// [[[ begin generated region: do not modify [Generated Contents]
// ]]] end generated region [Generated Contents]
}
// [[[ begin generated function: do not modify
/**
* Layout components as specified in the UI Designer
*/
void CColorLinezUITwPlay::LayoutControls()
{
iImage1->SetExtent( TPoint( 127, 20 ), TSize( 29, 29 ) );
iImage2->SetExtent( TPoint( 156, 20 ), TSize( 29, 29 ) );
iImage3->SetExtent( TPoint( 185, 20 ), TSize( 29, 29 ) );
}
// ]]] end generated function
/**
* Handle key events.
*/
TKeyResponse CColorLinezUITwPlay::OfferKeyEventL(
const TKeyEvent& aKeyEvent,
TEventCode aType )
{
if(IsBallsAppear)
{
ThreeColorBallsRandom();
IsBallsAppear = EFalse;
}
// [[[ begin generated region: do not modify [Generated Contents]
// ]]] end generated region [Generated Contents]
if(aType == EEventKey)
{
switch(aKeyEvent.iCode)
{
case EKeyLeftArrow:
case '4':
{
--iCursorPosX;
if(!iPaneStatus[iCursorPosX+1][iCursorPosY])
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX+1],iImagePointY[iCursorPosY]),iBkgBasicPaneBitmap,TSize(29,29));
}
else
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX+1],iImagePointY[iCursorPosY]),iLastBmp,TSize(29,29));
}
if(iCursorPosX==-1) { iCursorPosX = 6;}
if(!iPaneStatus[iCursorPosX][iCursorPosY])
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgMovePaneBitmap,TSize(29,29));
iLastBmp = NULL;
}
else
{
iCurrentBmp = iModel.GetCurrentBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]));
iLastBmp = iCurrentBmp;
if(iCurrentBmp == iBkgBallsBitmap[0])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgBallsPassedBmp[0],TSize(29,29));
if(iCurrentBmp == iBkgBallsBitmap[1])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgBallsPassedBmp[1],TSize(29,29));
if(iCurrentBmp == iBkgBallsBitmap[2])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgBallsPassedBmp[2],TSize(29,29));
}
break;
}
case EKeyRightArrow:
case '6':
{
++iCursorPosX;
if(!iPaneStatus[iCursorPosX-1][iCursorPosY])
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX-1],iImagePointY[iCursorPosY]),iBkgBasicPaneBitmap,TSize(29,29));
}
else
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX-1],iImagePointY[iCursorPosY]),iLastBmp,TSize(29,29));
}
if(iCursorPosX==7) { iCursorPosX = 0;}
if(!iPaneStatus[iCursorPosX][iCursorPosY])
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgMovePaneBitmap,TSize(29,29));
iLastBmp = NULL;
}
else
{
iCurrentBmp = iModel.GetCurrentBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]));
iLastBmp = iCurrentBmp;
if(iCurrentBmp == iBkgBallsBitmap[0])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgBallsPassedBmp[0],TSize(29,29));
if(iCurrentBmp == iBkgBallsBitmap[1])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgBallsPassedBmp[1],TSize(29,29));
if(iCurrentBmp == iBkgBallsBitmap[2])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgBallsPassedBmp[2],TSize(29,29));
}
break;
}
case EKeyUpArrow:
case '2':
{
--iCursorPosY;
if(!iPaneStatus[iCursorPosX][iCursorPosY+1])
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY+1]),iBkgBasicPaneBitmap,TSize(29,29));
}
else
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY+1]),iLastBmp,TSize(29,29));
}
if(iCursorPosY==-1) { iCursorPosY = 6;}
if(!iPaneStatus[iCursorPosX][iCursorPosY])
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgMovePaneBitmap,TSize(29,29));
iLastBmp = NULL;
}
else
{
iCurrentBmp = iModel.GetCurrentBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]));
iLastBmp = iCurrentBmp;
if(iCurrentBmp == iBkgBallsBitmap[0])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgBallsPassedBmp[0],TSize(29,29));
if(iCurrentBmp == iBkgBallsBitmap[1])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgBallsPassedBmp[1],TSize(29,29));
if(iCurrentBmp == iBkgBallsBitmap[2])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgBallsPassedBmp[2],TSize(29,29));
}
break;
}
case EKeyDownArrow:
case '8':
{
++iCursorPosY;
if(!iPaneStatus[iCursorPosX][iCursorPosY-1])
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY-1]),iBkgBasicPaneBitmap,TSize(29,29));
}
else
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY-1]),iLastBmp,TSize(29,29));
}
if(iCursorPosY==7) { iCursorPosY = 0;}
if(!iPaneStatus[iCursorPosX][iCursorPosY])
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgMovePaneBitmap,TSize(29,29));
iLastBmp = NULL;
}
else
{
iCurrentBmp = iModel.GetCurrentBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]));
iLastBmp = iCurrentBmp;
if(iCurrentBmp == iBkgBallsBitmap[0])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgBallsPassedBmp[0],TSize(29,29));
if(iCurrentBmp == iBkgBallsBitmap[1])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgBallsPassedBmp[1],TSize(29,29));
if(iCurrentBmp == iBkgBallsBitmap[2])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),iBkgBallsPassedBmp[2],TSize(29,29));
}
break;
}
// case EKeyNull:
case EKeyDevice3:
case '5':
{
if(iPaneStatus[iCursorPosX][iCursorPosY])
{
iLastX = iCursorPosX;
iLastY = iCursorPosY;
GetCurrentBitmap =
iModel.GetCurrentBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]));
if(GetCurrentBitmap != NULL)
{
if(iIsFirstClick)
{
if(GetCurrentBitmap == iBkgBallsBitmap[0])
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX],
iImagePointY[iCursorPosY]),iBkgBallsSelectedBmp[0],TSize(29,29));
}
else if(GetCurrentBitmap == iBkgBallsBitmap[1])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],
iImagePointY[iCursorPosY]),iBkgBallsSelectedBmp[1],TSize(29,29));
else if(GetCurrentBitmap == iBkgBallsBitmap[2])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],
iImagePointY[iCursorPosY]),iBkgBallsSelectedBmp[2],TSize(29,29));
iIsFirstClick = EFalse;
}
else
{
DrawBitmap(lastBmpPos,GetLastBitmap,TSize(29,29));
if(GetCurrentBitmap == iBkgBallsBitmap[0])
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX],
iImagePointY[iCursorPosY]),iBkgBallsSelectedBmp[0],TSize(29,29));
}
else if(GetCurrentBitmap == iBkgBallsBitmap[1])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],
iImagePointY[iCursorPosY]),iBkgBallsSelectedBmp[1],TSize(29,29));
else if(GetCurrentBitmap == iBkgBallsBitmap[2])
DrawBitmap(TPoint(iImagePointX[iCursorPosX],
iImagePointY[iCursorPosY]),iBkgBallsSelectedBmp[2],TSize(29,29));
}
GetLastBitmap = GetCurrentBitmap;
lastBmpPos = TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]);
}
}
else
{
for(short x=0;x!=7;++x)
{
for(short y=0;y!=7;++y)
{
if(iPaneStatus[x][y])
iModel.SetBlock(x,y);
else
iModel.RemoveBlock(x,y);
}
}
if(GetLastBitmap !=NULL)
{
if(iModel.FindPath(iLastX,iLastY,iCursorPosX,iCursorPosY))
{
DrawBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),GetLastBitmap,TSize(29,29));
iModel.SetCurrentBitmap(TPoint(iImagePointX[iCursorPosX],iImagePointY[iCursorPosY]),GetLastBitmap);
iPaneStatus[iCursorPosX][iCursorPosY] = ETrue;
TBool judge = JudgeLine(iCursorPosX,iCursorPosY,GetLastBitmap);
if(judge)
{
ClearLine(iTimesForward,iTimesBehind,iDirection,iCursorPosX,iCursorPosY);
}
else
{
ThreeColorBallsRandom();
}
GetLastBitmap = NULL;
iIsFirstClick = ETrue;
DrawBitmap(lastBmpPos,iBkgBasicPaneBitmap,TSize(29,29));
short x = (lastBmpPos.iX - 68)/29;
short y = (lastBmpPos.iY - 49)/29;
iPaneStatus[x][y] = EFalse;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -