⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colorlinezuitwplay.cpp

📁 使用CarbideC++编程工具
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					}
				}
			break;
			}
		case '1':
		//	ThreeColorBallsRandom();
			break;
		default:			
			break;
		}
	}
	if ( iFocusControl != NULL
		&& iFocusControl->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed )
		{
		return EKeyWasConsumed;
		}
	return CCoeControl::OfferKeyEventL( aKeyEvent, aType );
	}
				
// [[[ begin generated function: do not modify
/**
 *	Initialize each control upon creation.
 */				
void CColorLinezUITwPlay::InitializeControlsL()
	{
	iImage1 = new ( ELeave ) CEikImage;
		{
		CFbsBitmap *bitmap, *mask;
		AknIconUtils::CreateIconL( bitmap, mask,
				KColorLinezUITwo_aifFile, EMbmColorlinezuitwo_aif6, -1 );
		AknIconUtils::SetSize( bitmap, TSize( 29, 29 ), EAspectRatioPreserved );
		iImage1->SetPicture( bitmap );
		}
	iImage1->SetAlignment( EHCenterVTop );
	iImage2 = new ( ELeave ) CEikImage;
		{
		CFbsBitmap *bitmap, *mask;
		AknIconUtils::CreateIconL( bitmap, mask,
				KColorLinezUITwo_aifFile, EMbmColorlinezuitwo_aif2, -1 );
		AknIconUtils::SetSize( bitmap, TSize( 29, 29 ), EAspectRatioPreserved );
		iImage2->SetPicture( bitmap );
		}
	iImage2->SetAlignment( EHCenterVTop );
	iImage3 = new ( ELeave ) CEikImage;
		{
		CFbsBitmap *bitmap, *mask;
		AknIconUtils::CreateIconL( bitmap, mask,
				KColorLinezUITwo_aifFile, EMbmColorlinezuitwo_aif1, -1 );
		AknIconUtils::SetSize( bitmap, TSize( 29, 29 ), EAspectRatioPreserved );
		iImage3->SetPicture( bitmap );
		}
	iImage3->SetAlignment( EHCenterVTop );
	
	}
// ]]] end generated function

/** 
 * Handle global resource changes, such as scalable UI or skin events (override)
 */
void CColorLinezUITwPlay::HandleResourceChange( TInt aType )
	{
	CCoeControl::HandleResourceChange( aType );
	SetRect( iAvkonViewAppUi->View( TUid::Uid( EColorLinezUITwPlayViewId ) )->ClientRect() );
	// [[[ begin generated region: do not modify [Generated Contents]
	// ]]] end generated region [Generated Contents]	
	}

/**
 *	Draw container contents.
 */				
void CColorLinezUITwPlay::Draw( const TRect& aRect ) const
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	CWindowGc& gc = SystemGc();
	gc.Clear( aRect );
	
	// ]]] end generated region [Generated Contents]
	gc.BitBlt(TPoint(68,49),iBkgBitmap);
	gc.BitBlt(TPoint(68,49),iBkgMovePaneBitmap);	
	}

/**
 * draw the bitmap when needed
 */
void CColorLinezUITwPlay::DrawBitmap(const TPoint& aPoint,const CFbsBitmap* aBitmap,const TSize& aSize)
	{
	CWindowGc& gc = SystemGc();
	TRect rect = TRect(aPoint,aSize);
	ActivateGc();
	Window().Invalidate(rect);
	Window().BeginRedraw(rect);	
	gc.BitBlt(aPoint,aBitmap);
	Window().EndRedraw();
	DeactivateGc();
	}

void CColorLinezUITwPlay::ThreeColorBallsRandom()
	{
	short RandomPosX,RandomPosY,RandomBall;
	short RandomCount;//随机计数,初始值是3
	TTime *TheTime = new(ELeave)TTime;
	TheTime->UniversalTime();
	TInt64 RandSeed = TheTime->Int64();
	TInt64 RandBall = TheTime->Int64();
	RandomCount = 3;
	while(RandomCount!=0)
		{
		RandomPosX = Math::Rand(RandSeed)%7;
		RandomPosY = Math::Rand(RandSeed)%7;
		RandomBall = Math::Rand(RandBall)%3;
		if(!iPaneStatus[RandomPosX][RandomPosY])
			{				
			iPaneStatus[RandomPosX][RandomPosY] = ETrue;	
		//	iModel.SetBlock(RandomPosX,RandomPosY);
			--RandomCount;
			DrawBitmap(TPoint(iImagePointX[RandomPosX],iImagePointY[RandomPosY]),iBkgBallsBitmap[RandomBall],TSize(29,29));	
			iModel.SetCurrentBitmap(TPoint(iImagePointX[RandomPosX],iImagePointY[RandomPosY]),iBkgBallsBitmap[RandomBall]);
			}		
		}
	}
/**
 * set the iCursorPosX=0 and iCursorPosY=0
 */
void CColorLinezUITwPlay::ResumePos()
	{
	iCursorPosX = 0;
	iCursorPosY = 0;
	for(short pointX=0;pointX!=7;++pointX)
		{
		for(short pointY=0;pointY!=7;++pointY)
			{
			iPaneStatus[pointX][pointY] = EFalse;
			}
		}
	IsBallsAppear = ETrue;
	iIsFirstClick = ETrue;
	iScore = 0;
	iModel.SetScore(0);
	UpdateNaviPaneL();

	}
/**
 * 
 */
void CColorLinezUITwPlay::UpdateNaviPaneL()
	{
	if(iNaviDecorator)
		{
		iNaviPane->Pop(iNaviDecorator);
		delete iNaviDecorator;
		iNaviDecorator= NULL;
		}
	TBuf<100> naviText;
	_LIT(KNaviText,"Score %d");
	naviText.Format(KNaviText,iModel.GetScore());
	
	iNaviDecorator = iNaviPane->CreateNavigationLabelL(naviText);
	iNaviPane->PushL(*iNaviDecorator);
	}
/**
 * 2 		3		 4
 * 1  (aPosX,aPosY)  5
 * 8		7		 6 
 */
TBool CColorLinezUITwPlay::JudgeLine(TInt aPosX,TInt aPosY,const CFbsBitmap* aCurrentBitmap)
	{
	//从1方向开始
	iTemX = aPosX -1;
	iTemY = aPosY;
	iTimesForward = 0;
	while(ETrue)
		{
		if(iPaneStatus[iTemX][iTemY]&&(iTemX>=0))
			{
			iTempCurrentBmp = iModel.GetCurrentBitmap(TPoint(iImagePointX[iTemX],iImagePointY[iTemY]));
			if(iTempCurrentBmp == aCurrentBitmap)
				{
				++iTimesForward;
				--iTemX;		
				iTempCurrentBmp = NULL;
				continue;
				}
			else
				{
				break;
				}
			}
		else
			{
			break;
			}
		}
	//从5方向开始
	iTemX = aPosX+1;
	iTemY = aPosY;
	iTimesBehind = 0;
	while(ETrue)
		{
		if((iPaneStatus[iTemX][iTemY])&&(iTemX<=6))
			{
			iTempCurrentBmp = iModel.GetCurrentBitmap(TPoint(iImagePointX[iTemX],iImagePointY[iTemY]));
			if(iTempCurrentBmp == aCurrentBitmap)
				{
				++iTimesBehind;
				++iTemX;
				iTempCurrentBmp = NULL;
				continue;
				}
			else
				{
				break;
				}
			}
		else
			{
			break;
			}
		}
	if((iTimesForward + iTimesBehind)>=4)
		{
		iDirection = 1;
		return ETrue;		
		}
	//2方向
	iTemX = iCursorPosX-1;
	iTemY = iCursorPosY-1;
	iTimesForward = 0;
	while(ETrue)
		{		
		if(iPaneStatus[iTemX][iTemY] && (iTemX>=0)&& (iTemY>=0))
			{
			iTempCurrentBmp = iModel.GetCurrentBitmap(TPoint(iImagePointX[iTemX],iImagePointY[iTemY]));
			if(iTempCurrentBmp == aCurrentBitmap)
				{
				++iTimesForward;
				--iTemX;
				--iTemY;		
				iTempCurrentBmp = NULL;
				continue;
				}
			else
				{
				break;
				}
			}
		else
			{
			break;
			}
		}
	//6方向
	iTemX = iCursorPosX + 1;
	iTemY = iCursorPosY + 1;
	iTimesBehind = 0;
	while(ETrue)
		{
		if(iPaneStatus[iTemX][iTemY] && (iTemX<=6)&& (iTemY<=6))
			{
			iTempCurrentBmp = iModel.GetCurrentBitmap(TPoint(iImagePointX[iTemX],iImagePointY[iTemY]));
			if(iTempCurrentBmp == aCurrentBitmap)
				{
				++iTimesBehind;
				++iTemX;
				++iTemY;
				iTempCurrentBmp = NULL;
				continue;
				}
			else
				{
				break;
				}
			}
		else
			{
			break;
			}		
		}
	if((iTimesForward + iTimesBehind)>=4)
		{
		iDirection = 2;
		return ETrue;
		}
	
	//3方向
		iTemX = iCursorPosX;
		iTemY = iCursorPosY-1;
		iTimesForward = 0;
		while(ETrue)
			{		
			if(iPaneStatus[iTemX][iTemY]&& (iTemY>=0))
				{
				iTempCurrentBmp = iModel.GetCurrentBitmap(TPoint(iImagePointX[iTemX],iImagePointY[iTemY]));
				if(iTempCurrentBmp == aCurrentBitmap)
					{
					++iTimesForward;
					--iTemY;
					iTempCurrentBmp = NULL;
					continue;
					}
				else
					{
					break;
					}
				}
			else
				{
				break;
				}
			}
		//7方向
		iTemX = iCursorPosX;
		iTemY = iCursorPosY + 1;
		iTimesBehind = 0;
		while(ETrue)
			{
			if(iPaneStatus[iTemX][iTemY]&& (iTemY<=6))
				{
				iTempCurrentBmp = iModel.GetCurrentBitmap(TPoint(iImagePointX[iTemX],iImagePointY[iTemY]));
				if(iTempCurrentBmp == aCurrentBitmap)
					{
					++iTimesBehind;
					++iTemY;		
					iTempCurrentBmp = NULL;
					continue;
					}
				else
					{
					break;
					}
				}
			else
				{
				break;
				}		
			}
	if((iTimesForward + iTimesBehind)>=4)
		{
		iDirection = 3;
		return ETrue;
		}	
	//4方向
		iTemX = iCursorPosX + 1;
		iTemY = iCursorPosY - 1;
		iTimesForward = 0;
		while(ETrue)
			{		
			if(iPaneStatus[iTemX][iTemY] && (iTemX<=6)&& (iTemY>=0))
				{
				iTempCurrentBmp = iModel.GetCurrentBitmap(TPoint(iImagePointX[iTemX],iImagePointY[iTemY]));
				if(iTempCurrentBmp == aCurrentBitmap)
					{
					++iTimesForward;
					++iTemX;
					--iTemY;
					iTempCurrentBmp = NULL;
					continue;
					}
				else
					{
					break;
					}
				}
			else
				{
				break;
				}
			}
		//8方向
		iTemX = iCursorPosX - 1;
		iTemY = iCursorPosY + 1;
		iTimesBehind = 0;
		while(ETrue)
			{
			if(iPaneStatus[iTemX][iTemY] && (iTemX>=0)&& (iTemY<=6))
				{
				iTempCurrentBmp = iModel.GetCurrentBitmap(TPoint(iImagePointX[iTemX],iImagePointY[iTemY]));
				if(iTempCurrentBmp == aCurrentBitmap)
					{
					++iTimesBehind;
					--iTemX;
					++iTemY;		
					iTempCurrentBmp = NULL;
					continue;
					}
				else
					{
					break;
					}
				}
			else
				{
				break;
				}		
			}
	if((iTimesForward + iTimesBehind)>=4)
		{
		iDirection = 4;
		return ETrue;
		}
	return EFalse;
	}
void CColorLinezUITwPlay::ClearLine(TInt aTimesForward,TInt aTimesBehind,short aDirection,TInt aPosX,TInt aPosY)
	{
	TInt tempPosX,tempPosY;
	iPaneStatus[aPosX][aPosY] = EFalse;
	DrawBitmap(TPoint(iImagePointX[aPosX],iImagePointY[aPosY]),iBkgBasicPaneBitmap,TSize(29,29));
	if((aDirection == 1)||(aDirection == 5))//如果是1方向,则清除1和5方向上的所有
		{
		tempPosX = aPosX;
		tempPosY = aPosY;
		while(aTimesForward!=0)
			{
			--tempPosX;
			iPaneStatus[tempPosX][tempPosY] = EFalse;
		//	iModel.RemoveBlock(tempPosX,tempPosY);
			DrawBitmap(TPoint(iImagePointX[tempPosX],iImagePointY[tempPosY]),iBkgBasicPaneBitmap,TSize(29,29));
			--aTimesForward;
			}
		tempPosX = aPosX;
		tempPosY = aPosY;
		while(aTimesBehind!=0)
			{
			++tempPosX;
			iPaneStatus[tempPosX][tempPosY] = EFalse;
		//	iModel.RemoveBlock(tempPosX,tempPosY);
			DrawBitmap(TPoint(iImagePointX[tempPosX],iImagePointY[tempPosY]),iBkgBasicPaneBitmap,TSize(29,29));
			--aTimesBehind;
			}
		}
	
	if((aDirection == 2)|| (aDirection == 6))//如果是2或6方向
		{
		tempPosX = aPosX;
		tempPosY = aPosY;
		while(aTimesForward!=0)//清除2方向
			{
			--tempPosX;
			--tempPosY;
			iPaneStatus[tempPosX][tempPosY] = EFalse;
	//		iModel.RemoveBlock(tempPosX,tempPosY);
			DrawBitmap(TPoint(iImagePointX[tempPosX],iImagePointY[tempPosY]),iBkgBasicPaneBitmap,TSize(29,29));
			--aTimesForward;
			}
		tempPosX = aPosX;
		tempPosY = aPosY;
		while(aTimesBehind!=0)
			{
			++tempPosX;
			++tempPosY;
			iPaneStatus[tempPosX][tempPosY] = EFalse;
		//	iModel.RemoveBlock(tempPosX,tempPosY);
			DrawBitmap(TPoint(iImagePointX[tempPosX],iImagePointY[tempPosY]),iBkgBasicPaneBitmap,TSize(29,29));
			--aTimesBehind;
			}
		}
	if((aDirection == 3)|| (aDirection == 7))//如果是3或7方向
		{
		tempPosX = aPosX;
		tempPosY = aPosY;
		while(aTimesForward!=0)//清除3方向
			{		
			--tempPosY;
			iPaneStatus[tempPosX][tempPosY] = EFalse;
		//	iModel.RemoveBlock(tempPosX,tempPosY);
			DrawBitmap(TPoint(iImagePointX[tempPosX],iImagePointY[tempPosY]),iBkgBasicPaneBitmap,TSize(29,29));
			--aTimesForward;
			}
		tempPosX = aPosX;
		tempPosY = aPosY;
		while(aTimesBehind!=0)//清除7方向
			{			
			++tempPosY;
			iPaneStatus[tempPosX][tempPosY] = EFalse;
		//	iModel.RemoveBlock(tempPosX,tempPosY);
			DrawBitmap(TPoint(iImagePointX[tempPosX],iImagePointY[tempPosY]),iBkgBasicPaneBitmap,TSize(29,29));
			--aTimesBehind;
			}
		}
	if((aDirection == 4)|| (aDirection == 8))//如果是4或8方向
		{
		tempPosX = aPosX;
		tempPosY = aPosY;
		while(aTimesForward!=0)//清除4方向
			{
			++tempPosX;
			--tempPosY;
			iPaneStatus[tempPosX][tempPosY] = EFalse;
		//	iModel.RemoveBlock(tempPosX,tempPosY);
			DrawBitmap(TPoint(iImagePointX[tempPosX],iImagePointY[tempPosY]),iBkgBasicPaneBitmap,TSize(29,29));
			--aTimesForward;
			}
		tempPosX = aPosX;
		tempPosY = aPosY;
		while(aTimesBehind!=0)
			{
			--tempPosX;
			++tempPosY;
			iPaneStatus[tempPosX][tempPosY] = EFalse;
		//	iModel.RemoveBlock(tempPosX,tempPosY);
			DrawBitmap(TPoint(iImagePointX[tempPosX],iImagePointY[tempPosY]),iBkgBasicPaneBitmap,TSize(29,29));
			--aTimesBehind;
			}
		}
	iScore+=10;
	iModel.SetScore(iScore);
	UpdateNaviPaneL();
	}

void CColorLinezUITwPlay::TimerComplete(TInt aError)
	{
	
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -