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

📄 square.cpp

📁 symcodes.rar a game code in symbian
💻 CPP
字号:
/*****************************************************************************

 
 COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2007.

 

 The software is the copyrighted work of Sony Ericsson Mobile Communications AB.

 The use of the software is subject to the terms of the end-user license 

 agreement which accompanies or is included with the software. The software is 

 provided "as is" and Sony Ericsson specifically disclaim any warranty or 

 condition whatsoever regarding merchantability or fitness for a specific 

 purpose, title or non-infringement. No warranty of any kind is made in 

 relation to the condition, suitability, availability, accuracy, reliability, 

 merchantability and/or non-infringement of the software provided herein.

 

 *****************************************************************************/
 
#include "Square.h"
#include "minesBaseView.h" 
#include <eikenv.h> 
 
#include "Board.h" 
 
 
 
/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
void CSquare::SetValue(userValue val)
{
	iValue = val;
	DrawNow();
}

 
 
/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/ 
TSize CSquare::MinimumSize()
{
	return TSize(100,100);
}

 
 
/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/ 
void CSquare::DrawEmpty(CWindowGc& gc) const
{ 
	TRect  drawRect = Rect(); 

  	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);   		
    gc.SetBrushColor(TRgb(210,210,210));
  	gc.SetPenColor(TRgb(0,0,0));        
	gc.DrawRect(drawRect);				
}




/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/ 
void CSquare::DrawBomb(CWindowGc& gc) const
{  		
	TRect  drawRect = Rect(); 
	
  	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);   		
	gc.SetBrushColor(TRgb(210,210,210));
  	gc.SetPenColor(TRgb(0,0,0));
	gc.DrawRect(drawRect);

    gc.SetBrushColor(TRgb(0,0,0));
  	gc.SetPenColor(TRgb(0,0,0)); 
  	TRect  bombdrawRect(drawRect); 
	bombdrawRect.Shrink(2,2);
	gc.DrawEllipse(bombdrawRect);	
}



/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
void CSquare::DrawFlag(CWindowGc& gc) const
{  		
	TRect  drawRect = Rect();
	
	TRect otherrect(drawRect);
  	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);  
	
	gc.SetBrushColor(TRgb(210,210,210));
  	gc.SetPenColor(TRgb(0,0,0));
	gc.DrawRect(drawRect);

    gc.SetBrushColor(TRgb(255,0,0));
  	gc.SetPenColor(TRgb(0,0,0));        
	
	TRect  mydrawRect = drawRect;

	TInt x = mydrawRect.Height()/4;
	mydrawRect.Shrink(3,x); //5 -5
	mydrawRect.Move(-2,-1*x);
	gc.DrawRect(mydrawRect);		

	otherrect.Shrink(8,0); 
	otherrect.Move(4,0);

	gc.DrawRect(otherrect);	  	
}




/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/ 
void CSquare::DrawNum(CWindowGc& gc, int num) const
{  
  TRect  drawRect = Rect();  
 
  gc.SetBrushStyle(CGraphicsContext::ESolidBrush);   		
  gc.SetBrushColor(TRgb(210,210,210));
  gc.SetPenColor(TRgb(0,0,0));        
  gc.DrawRect(drawRect);	


  if(num == 0)
    {
      DrawEmpty(gc); 
	  return;
    }


  if(num == 1)
    {
      gc.SetPenColor(KRgbBlue);  
    }
  else if(num == 2)
    {
      gc.SetPenColor(KRgbGreen);      
    }
  else if(num == 3)
    {
      gc.SetPenColor(KRgbRed);      
    }
  else if(num == 4)
    {
      gc.SetPenColor(KRgbYellow);      
    }    
  else if(num == 5)
    {
      gc.SetPenColor(KRgbBlack);      
    }    
  else if(num == 6)
    {
      gc.SetPenColor(KRgbDarkCyan);      
    }    
  else if(num == 7)
    {
      gc.SetPenColor(KRgbDarkRed);      
    }    
  else if(num == 8)
    {
      gc.SetPenColor(KRgbDarkMagenta);      
    }        
  else
    {
       gc.SetPenColor(KRgbMagenta);      
    }

	TBuf<16> num_str(_L("abcdefg"));
	num_str.Num(num); 

  	drawRect.Shrink(1,1); 
  	const CFont* font = iEikonEnv->TitleFont();
  	gc.UseFont(font);

  	TInt baseline = Rect().Height()*4/5;
 
  	gc.DrawText(num_str, drawRect, baseline, CGraphicsContext::ECenter); 
  	gc.DiscardFont();   		
}









/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
void CSquare::DrawUnknown(CWindowGc& gc) const
{  		
	TRect  drawRect = Rect(); 
	
  	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);   		
    gc.SetBrushColor(TRgb(190,190,190));
  	gc.SetPenColor(TRgb(0,0,0));        
	gc.DrawRect(drawRect);	
  		        
  		        
	TRect rect = drawRect;   
  	int xb = rect.iTl.iX;        
  	int yb = rect.iTl.iY;        

  	int xc = rect.iBr.iX;        
  	int yc = rect.iBr.iY;        
  		        
  	TPoint pointarr[4];
  	pointarr[0] = TPoint(xb+0,yb+0);
 	pointarr[1] = TPoint(xb+4,yb+4);
  	pointarr[2] = TPoint(xc-4,yb+4);
  	pointarr[3] = TPoint(xc,yb+0);
  		
	gc.SetBrushColor(TRgb(220,220,220)); 
  	gc.SetPenColor(TRgb(220,220,220));		 		
  	gc.DrawPolygon(pointarr,4);
 
   	pointarr[0] = TPoint(xb+0,yb+0);
  	pointarr[1] = TPoint(xb+4,yb+4);
  	pointarr[2] = TPoint(xb+4,yc-4);
  	pointarr[3] = TPoint(xb+0,yc);
  		
	gc.SetBrushColor(TRgb(220,220,220));  		
  	gc.SetPenColor(TRgb(220,220,220));			
  	gc.DrawPolygon(pointarr,4);

   	pointarr[0] = TPoint(xb+0,yc);
  	pointarr[1] = TPoint(xb+4,yc-4);
  	pointarr[2] = TPoint(xc-4,yc-4);
  	pointarr[3] = TPoint(xc,yc);
  		
	gc.SetBrushColor(TRgb(130,130,130)); 
  	gc.SetPenColor(TRgb(130,130,130));			 		
  	gc.DrawPolygon(pointarr,4);
 
   	pointarr[0] = TPoint(xc,yc);
  	pointarr[1] = TPoint(xc-4,yc-4);
  	pointarr[2] = TPoint(xc-4,yb+4);
  	pointarr[3] = TPoint(xc,yb+0);
  		
	gc.SetBrushColor(TRgb(130,130,130));  		
  	gc.SetPenColor(TRgb(130,130,130));			
  	gc.DrawPolygon(pointarr,4);
 
  	gc.SetBrushStyle(CGraphicsContext::ENullBrush);
  	gc.SetPenColor(TRgb(0,0,0));        
	gc.DrawRect(drawRect);
}






/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
void CSquare::Draw(const TRect& /* oldRect */) const
{  
  	CWindowGc& gc = SystemGc();


	gc.SetBrushColor(TRgb(255,255,255)); 
    gc.SetPenColor(TRgb(0,0,0));  
  		  			
	if(iValue == unknown)
	{  		 	
		DrawUnknown(gc); 		
	}	  		
	else if(iValue == flag)
  	{  		
		DrawFlag(gc); 		
	}
	else 
	{
		if(iType == mine)
  		{  		
	  		DrawBomb(gc);		
		}
		else
		{
			DrawNum(gc, iBoard->NumClose(iX, iY));
		}
	}	
}







/*-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
void CSquare::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
	// check whether we're interested
	if (aPointerEvent.iType != TPointerEvent::EButton1Down &&
		aPointerEvent.iType != TPointerEvent::EButton1Up)
	{
		return;
	}

	if(aPointerEvent.iType==TPointerEvent::EButton1Down)
	{
		iBoard->PointerDown(iY, iY);
	}
	else if(aPointerEvent.iType==TPointerEvent::EButton1Up)
	{
		iBoard->PointerUp(iX, iY);	
	}
}




⌨️ 快捷键说明

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