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

📄 eluoshiview.cpp

📁 看书后
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	int x1,x2,x3,x4,y1,y2,y3,y4;
	   x1 = ActiveStatus[0][0];
	   x2 = ActiveStatus[1][0];
	   x3 = ActiveStatus[2][0];
	   x4 = ActiveStatus[3][0];
	   y1 = ActiveStatus[0][1];
	   y2 = ActiveStatus[1][1];
	   y3 = ActiveStatus[2][1];
	   y4 = ActiveStatus[3][1]; 
	   switch(m_currentRect)
	   {
	   case 1:
		   if(GameStatus[x1][y1-1] || GameStatus[x2][y2-1] ||
			   GameStatus[x3][y3-1] ||GameStatus[x4][y4-1])
			   return FALSE;
		   break;
	   case 11:
		   if(GameStatus[x1][y1-1])
			   return FALSE;
		   break;
	   case 2:
		   if(GameStatus[x1][y1-1] || GameStatus[x2][y2-1])
			   return FALSE;
		   break;
	   case 3:
		   if(GameStatus[x1][y1-1] || GameStatus[x2][y2-1])
			   return FALSE;
		   break;
	   case 31:
		   if(GameStatus[x1][y1-1] || GameStatus[x2][y2-1] ||
			   GameStatus[x3][y3-1])
			   return FALSE;
		   break;
	   case 32:
		   if(GameStatus[x1][y1-1] ||GameStatus[x3][y3-1] )
			   return FALSE;
		   break;
	   case 33:
		   if(GameStatus[x1][y1-1] || GameStatus[x2][y2-1] ||GameStatus[x4][y4-1])
			   return FALSE;
		   break;
	   case 4:
		   if(GameStatus[x1][y1-1] || GameStatus[x2][y2-1] ||GameStatus[x4][y4-1])
			   return FALSE;
		   break;
	   case 41:
		   if(GameStatus[x1][y1-1] || GameStatus[x2][y2-1])
			   return FALSE;
		   break;
	   case 5:
		   if(GameStatus[x1][y1-1] || GameStatus[x2][y2-1] || GameStatus[x3][y3-1])
			   return FALSE;
		   break;
	   case 51:
		   if(GameStatus[x1][y1-1] || GameStatus[x3][y3-1])
			   return FALSE;
		   break;
	   case 6:
		   if(GameStatus[x1][y1-1] ||  GameStatus[x3][y3-1] ||GameStatus[x4][y4-1])
			   return FALSE;
		   break;
	   case 61:
		   if(GameStatus[x1][y1-1] || GameStatus[x2][y2-1])
			   return FALSE;
		   break;
	   case 62:
		   if(GameStatus[x1][y1-1] || GameStatus[x2][y2-1] || GameStatus[x3][y3-1] )
			   return FALSE;
		   break;
	   case 63:
		   if(GameStatus[x1][y1-1] ||GameStatus[x3][y3-1])
			   return FALSE;
		   break;
	   case 7:
		   if(GameStatus[x1][y1-1] || GameStatus[x2][y2-1] || GameStatus[x3][y3-1])
			   return FALSE;
		   break;
	   case 71:
		   if(GameStatus[x1][y1-1] || GameStatus[x2][y2-1])
			   return FALSE;
		   break;
	   case 72:
		   if(GameStatus[x1][y1-1] || GameStatus[x2][y2-1] ||GameStatus[x3][y3-1] )
			   return FALSE;
		   break;
	   case 73:
		   if(GameStatus[x1][y1-1] ||GameStatus[x4][y4-1])
			   return FALSE;
		   break;
		   
	   }
	   return TRUE;
	   
}

void CEluoshiView::RectTangle()
{
	int xx1,xx2,xx3,xx4,yy1,yy2,yy3,yy4;
	int m_lscurrentRect;
	CString lsStr;
	int x1,x2,x3,x4,y1,y2,y3,y4;
	   x1 = ActiveStatus[0][0];
	   x2 = ActiveStatus[1][0];
	   x3 = ActiveStatus[2][0];
	   x4 = ActiveStatus[3][0];
	   y1 = ActiveStatus[0][1];
	   y2 = ActiveStatus[1][1];
	   y3 = ActiveStatus[2][1];
	   y4 = ActiveStatus[3][1]; 
	   xx1 = x1;xx2 = x2;xx3 = x3;xx4 = x4;
	   yy1 = y1;yy2 = y2;yy3 = y3;yy4 = y4;
	   switch(m_currentRect)
	   {
	   case 1:
		   xx1 = x1+1;yy1 = y1-1;xx3 =x3-1;yy3 =y3+1;xx4 = x4-2;yy4 = y4+2;
		   m_lscurrentRect = 11;
		   break;
	   case 11: 
		   xx1 = x1-1;yy1 = y1+1;xx3 =x3+1;yy3 =y3-1;xx4 = x4+2;yy4 = y4-2;
		   m_lscurrentRect = 1;
		   break;
	   case 2:
		   break;
	   case 3:
		   xx1 = xx1 -1;xx2 = x2+1;yy2 = y2 -1;xx3 = x3 +1;yy3 = y3-1;yy4 = y4 -1;
           m_lscurrentRect = 31;
		   break;
	   case 31:
           xx2 = x2-1;yy2 = y2 +1;xx3 = x3 -1;yy3 = y3+1;xx4 = x4-1;yy4 = y4 +1;
           m_lscurrentRect = 32;
		   break;
	   case 32:
           xx1 = xx1+1;xx4 = x4+2;yy4 = y4-1;
           m_lscurrentRect = 33;
		   break;
	   case 33:
           xx4 = x4-1;yy4 = y4 +1;
           m_lscurrentRect = 3;
		   break;
	   case 4:
		   xx1 = x1 +1;xx2 = x2 -1;yy2 = y2 +1;xx4 = x4-2;yy4 = y4+1;
		   m_lscurrentRect = 41;
		   break;
	   case 41:
		   xx1 = x1 -1;xx2 = x2 +1;yy2 = y2 -1;xx4 = x4+2;yy4 = y4-1;
		   m_lscurrentRect = 4;
		   break;
	   case 5:
		   xx1 = x1 -1;xx2 = x2-2;yy2 = y2+1;xx3 = x3 +1;yy4 = y4 +1;
		   m_lscurrentRect = 51;
		   break;
	   case 51:
		   xx1 = x1 +1;xx2 = x2+2;yy2 = y2-1;xx3 = x3 -1;yy4 = y4 -1;
		   m_lscurrentRect = 5;
		   break;
	   case 6:
		   xx1 = x1+1;xx2 = x2+1;xx3 = x3-1;yy3 = y3+1;xx4 = x4-1;yy4 = y4+1;
		   m_lscurrentRect = 63;
		   break;
	   case 61 :
		   xx2 = x2 -1;yy2 = y2+1;xx3 = x3+1;xx4 = x4+2;yy4 = y4-1;
		   m_lscurrentRect = 6;
		   break;
	   case 62:
		   xx3 = x3-2;yy3 = y3+1;xx4 = x4 -2;yy4 = y4 +1;
		   m_lscurrentRect = 61;
		   break;
	   case 63:
		   xx1 = x1 -1;yy2 = y2 -1;xx3 = x3+2;yy3 = y3-2;xx4 = x4+1;yy4 = y4-1;
		   m_lscurrentRect = 62;
		   break;
	   case 7:
		   xx2 = x2-1;yy2 = y2+1;xx3 = x3 -2;yy3 = y3+2;xx4 = x4+1;yy4 = y4+1;
		   m_lscurrentRect = 73;
		   break;
	   case 71:
		   xx1 = x1-1;xx2 = x2-1;yy3 = y3-1;xx4 = x4-2;yy4 = y4-1;
		   m_lscurrentRect = 7;
		   break;
	   case 72:
		   xx1 = x1-1;xx2 = x2+2;yy2 = y2-1;xx3=x3+1;yy4 = y4-1;
		   m_lscurrentRect = 71;
		   break;
	   case 73:
		   xx1 = x1 +2;xx3 = x3+1;yy3 = y3-1;xx4 = x4+1;yy4=y4 -1;
		   m_lscurrentRect = 72;
		   break;
	   }
		   GameStatus[x1][y1] = MAP_STATE_EMPTY;
		   GameStatus[x2][y2] = MAP_STATE_EMPTY;
		   GameStatus[x3][y3] = MAP_STATE_EMPTY;
		   GameStatus[x4][y4] = MAP_STATE_EMPTY;
		   if( GameStatus[xx1][yy1] == MAP_STATE_EMPTY&&
			   GameStatus[xx2][yy2] == MAP_STATE_EMPTY&&
			   GameStatus[xx3][yy3] == MAP_STATE_EMPTY&&
			   GameStatus[xx4][yy4] == MAP_STATE_EMPTY
			   && yy1>=0 && yy4 <= m_iCol &&
			   !(xx1<0 ||xx2<0 ||xx3<0 ||xx4<0 )&&
			   !(xx1>m_iCol ||xx2>m_iCol ||xx3>m_iCol ||xx4>m_iCol)
			   )
		   {
 		   InvalidateCurrent();
		   ActiveStatus[0][0] = xx1;
		   ActiveStatus[1][0] = xx2;
		   ActiveStatus[2][0] = xx3;
		   ActiveStatus[3][0] = xx4;
		   ActiveStatus[0][1] = yy1;
		   ActiveStatus[1][1] = yy2;
		   ActiveStatus[2][1] = yy3;
		   ActiveStatus[3][1] = yy4;
		   
		   GameStatus[xx1][yy1] = MAP_STATE_NOT_EMPTY;
		   GameStatus[xx2][yy2] = MAP_STATE_NOT_EMPTY;
		   GameStatus[xx3][yy3] = MAP_STATE_NOT_EMPTY;
		   GameStatus[xx4][yy4] = MAP_STATE_NOT_EMPTY;
 		   InvalidateCurrent();
		   m_currentRect = m_lscurrentRect;
		   
	   }
	   else
	   {
		   GameStatus[x1][y1] = MAP_STATE_NOT_EMPTY;
		   GameStatus[x2][y2] = MAP_STATE_NOT_EMPTY;
		   GameStatus[x3][y3] = MAP_STATE_NOT_EMPTY;
		   GameStatus[x4][y4] = MAP_STATE_NOT_EMPTY;
	   }
	   ISBottom();
	   
}

void CEluoshiView::DcEnvInitial()
{
    CDC*  pWindowDC = GetDC();
	CRect windowRect;
	GetClientRect(&windowRect);
	m_nWidth = windowRect.Width();
	m_nHeight = windowRect.Height();
	m_memDC.CreateCompatibleDC(pWindowDC);
	m_memBmp.CreateCompatibleBitmap(pWindowDC,m_nWidth,m_nHeight);
	m_memDC.SelectObject(&m_memBmp);
	m_memRectDC.CreateCompatibleDC(pWindowDC);
//	m_hMemRectBmp = (HBITMAP)LoadImage(NULL,"IDB_BITMAP2",IMAGE_BITMAP,150,30,LR_LOADFROMFILE);
	m_memRectBmp.LoadBitmap(IDB_BITMAP1);
//	SelectObject(m_memRectDC.m_hDC,m_hMemRectBmp);
	m_memRectDC.SelectObject(&m_memRectBmp);
	m_pBlackPen = new CPen(PS_SOLID,1,RGB(0,0,0));
	m_pGrayBrush = new CBrush(RGB(66,66,66));
	m_pBlackBrush = new CBrush(RGB(0,0,0));
	
}

void CEluoshiView::DCEnvClear()
{
    m_memDC.DeleteDC();
	m_memRectDC.DeleteDC();
	DeleteObject(m_memBmp);
	DeleteObject(m_memRectBmp);
//	DeleteObject(m_hMemRectBmp);
	delete(m_pBlackPen);
	delete(m_pGrayBrush);
	delete(m_pBlackBrush);
}

void CEluoshiView::DrawGame(CDC *pDC)
{
	int i,j;
	pDC->SelectObject(m_pBlackBrush);
	CRect rect;
	GetClientRect(&rect);
	pDC->Rectangle(rect);
	pDC->SelectObject(m_pGrayBrush);
	pDC->Rectangle(m_iStartY,m_iStartX,m_iStartY+301,m_iStartX+360);
	pDC->SelectObject(m_pBlackPen);
	if(TRUE)
	{
		for(i=0;i<m_iRow;i++)
		{
			pDC->MoveTo(m_iStartY,m_iStartX+i*m_iLarge);
			pDC->LineTo(m_iStartY+300,m_iStartX+i*m_iLarge);
		}
		for(i=0;i<m_iCol;i++)
		{
			pDC->MoveTo(m_iStartY+i*m_iLarge,m_iStartX);
			pDC->LineTo(m_iStartY+i*m_iLarge,m_iStartX+360);
		}
	}
	int x,y,nW,nH;
	for(i=0;i<m_iRow;i++)
		for(j=0;j<m_iCol;j++)
		{
			if(GameStatus[i][j] == MAP_STATE_NOT_EMPTY)
			{
				x = m_iStartY+j*m_iLarge +2;
				y = m_iStartX+i*m_iLarge +2;
				nW = m_iLarge-4;
				nH = m_iLarge-4;
				pDC->BitBlt(x,y,nW,nH,&m_memRectDC,0,0,SRCCOPY);
			}
		}
		if(!m_bGameEnd)
		{
			pDC->SetBkColor(RGB(0,0,0));
			pDC->SetTextColor(RGB(255,255,255));
			pDC->TextOut(m_iStartY+320,m_iStartX+220,"游戏区域大小:");
			pDC->TextOut(m_iStartY+320,m_iStartX+240,"24行20列");
			pDC->TextOut(m_iStartY+320,m_iStartX+280,"游戏级别:");
			pDC->TextOut(m_iStartY+320,m_iStartX+300,"1");
			
		}
		if(!m_bGameEnd)
		{
			CString lsStr;
			lsStr.Format("总分为:%d分",m_iPerformance);
			pDC->SetBkColor(RGB(0,0,0));
			pDC->SetTextColor(RGB(255,255,255));
			pDC->TextOut(m_iStartY+320,m_iStartX+180,lsStr);
		}
			if(!m_bGameEnd)
			{
				pDC->SetBkColor(RGB(0,0,0));
				pDC->SetTextColor(RGB(255,255,255));
				pDC->TextOut(m_iStartY+320,m_iStartX,"下一个方块:");
				
				for(int k=0;k<4;k++)
				{
					i = NextStatus[k][0];
					j = NextStatus[k][1];
					x = m_iStartY + j*15 +2+320;
					y = m_iStartX + i*15+2+30;
					nW = m_iLarge-2;
					nH = m_iLarge-2;
					pDC->BitBlt(x,y,nW,nH,&m_memRectDC,0,0,SRCCOPY);
				}
			}
			
}

BOOL CEluoshiView::IsRightLimit()
{
	int x1,x2,x3,x4,y1,y2,y3,y4;
	   x1 = ActiveStatus[0][0];
	   x2 = ActiveStatus[1][0];
	   x3 = ActiveStatus[2][0];
	   x4 = ActiveStatus[3][0];
	   y1 = ActiveStatus[0][1];
	   y2 = ActiveStatus[1][1];
	   y3 = ActiveStatus[2][1];
	   y4 = ActiveStatus[3][1]; 
	   switch(m_currentRect)
	   {
	   case 1:
		   if(GameStatus[x1][y1+1] || GameStatus[x2][y2+1] ||
			   GameStatus[x3][y3+1] ||GameStatus[x4][y4+1])
			   return FALSE;
		   break;
	   case 11:
		   if(GameStatus[x4][y4+1])
			   return FALSE;
		   break;
	   case 2:
		   if(GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
			   return FALSE;
		   break;
	   case 3:
		   if(GameStatus[x2][y2+1] || GameStatus[x4][y4+1])
			   return FALSE;
		   break;
	   case 31:
		   if(GameStatus[x1][y1+1] || GameStatus[x4][y4+1] ||
			   GameStatus[x3][y3+1])
			   return FALSE;
		   break;
	   case 32:
		   if(GameStatus[x4][y4+1] ||GameStatus[x3][y3+1] )
			   return FALSE;
		   break;
	   case 33:
		   if(GameStatus[x3][y3+1] || GameStatus[x2][y2+1] ||GameStatus[x4][y4+1])
			   return FALSE;
		   break;
	   case 4:
		   if(GameStatus[x1][y1+1] || GameStatus[x3][y3+1] ||GameStatus[x4][y4+1])
			   return FALSE;
		   break;
	   case 41:
		   if(GameStatus[x3][y3+1] || GameStatus[x4][y4+1])
			   return FALSE;
		   break;
	   case 5:
		   if(GameStatus[x2][y2+1] || GameStatus[x4][y4+1] || GameStatus[x3][y3+1])
			   return FALSE;
		   break;
	   case 51:
		   if(GameStatus[x2][y2+1] || GameStatus[x4][y4+1])
			   return FALSE;
		   break;
	   case 6:
		   if(GameStatus[x2][y2+1] ||  GameStatus[x3][y3+1] ||GameStatus[x4][y4+1])
			   return FALSE;
		   break;
	   case 61:
		   if(GameStatus[x4][y4+1] || GameStatus[x2][y2+1])
			   return FALSE;
		   break;
	   case 62:
		   if(GameStatus[x1][y1+1] || GameStatus[x2][y2+1] || GameStatus[x4][y4+1] )
			   return FALSE;
		   break;
	   case 63:
		   if(GameStatus[x4][y4+1] ||GameStatus[x3][y3+1])
			   return FALSE;
		   break;
	   case 7:
		   if(GameStatus[x4][y4+1] || GameStatus[x2][y2+1] || GameStatus[x3][y3+1])
			   return FALSE;
		   break;
	   case 71:
		   if(GameStatus[x1][y1+1] || GameStatus[x4][y4+1])
			   return FALSE;
		   break;
	   case 72:
		   if(GameStatus[x4][y4+1] || GameStatus[x2][y2+1] ||GameStatus[x3][y3+1] )
			   return FALSE;
		   break;
	   case 73:
		   if(GameStatus[x3][y3+1] ||GameStatus[x4][y4+1])
			   return FALSE;
		   break;
		   
	   }
	   return TRUE;
	   
}

void CEluoshiView::GameInitnal()
{
	int i,j;
	for(i=0;i<24;i++)
		for(j=0;j<20;j++)
			GameStatus[i][j] = 0;
		for(i =0;i<74;i++)
			for(j=0;j<4;j++)
				InterFace[i][j] = -1;
			//类型一
			InterFace[1][0] = 3;
			InterFace[11][0] = 0;
			InterFace[11][1] = 1;
			InterFace[11][2] = 2;
			InterFace[11][3] = 3;
			//类型2
			InterFace[2][0] = 1;
			InterFace[2][1] = 3;
			//类型3
			InterFace[3][0] = 0;
			InterFace[3][1] = 2;
			InterFace[3][2] = 3;
			InterFace[31][0] = 2;
			InterFace[31][1] = 3;
			InterFace[32][0] = 0;
			InterFace[32][1] = 2;
			InterFace[32][2] = 3;
			InterFace[33][0] = 0;
			InterFace[33][1] = 3;
			//类型4
			InterFace[4][0] = 1;
			InterFace[4][1] = 3;
			InterFace[41][0] = 0;
			InterFace[41][1] = 2;
			InterFace[41][2] = 3;
			//类型5
			InterFace[5][0] = 1;
			InterFace[5][1] = 3;
			InterFace[51][0] = 0;
			InterFace[51][1] = 2;
			InterFace[51][2] = 3;
			//类型6
			InterFace[6][0] = 0;
			InterFace[6][1] = 3;
			InterFace[61][0] = 1;
			InterFace[61][1] = 2;
			InterFace[61][2] = 3;
			InterFace[62][0] = 2;
			InterFace[62][1] = 3;
			InterFace[63][0] = 0;
			InterFace[63][1] = 1;
			InterFace[63][2] = 3;
			//类型7
			InterFace[7][0] = 2;
			InterFace[7][1] = 3;
			InterFace[71][0] = 1;
			InterFace[71][1] = 2;
			InterFace[71][2] = 3;
			InterFace[72][0] = 0;
			InterFace[72][1] = 3;
			InterFace[73][0] = 0;
			InterFace[73][1] = 1;
			InterFace[73][2] = 3;
            
			m_isBottom = FALSE;
			m_bGameEnd = FALSE;
			m_iStartX = 10;
			m_iStartY = 10; 
			m_iCol = 20;
			m_iRow = 24;
			m_iLevel = 1;
			m_iLarge = 15;	
            m_iPerformance = 0;
			m_currentRect = 1;
			m_icurrentStatus = 1;
			m_inextStatus = 2;
			ActiveStatus[0][0] = 0;ActiveStatus[0][1] = 8;
			ActiveStatus[1][0] = 1;ActiveStatus[1][1] = 8;
			ActiveStatus[2][0] = 2;ActiveStatus[2][1] = 8;
			ActiveStatus[3][0] = 3;ActiveStatus[3][1] = 8;
			NextStatus[0][0] = 0;NextStatus[0][1] = 1;
			NextStatus[1][0] = 1;NextStatus[1][1] = 1;
			NextStatus[2][0] = 0;NextStatus[2][1] = 2;
			NextStatus[3][0] = 1;NextStatus[3][1] = 2;
			
}

⌨️ 快捷键说明

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