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

📄 fanview.cpp

📁 俄罗斯方块源码。很经典的一款VC开发程序。程序有详细解释。供参考和学习。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			}
			SetTimer(IDC_TIMER,time,NULL);

		}
	}
	CMainFrame * frame=(CMainFrame *)AfxGetMainWnd();
	UINT nID,nStyle;
	int cxwidth;
	frame->m_wndStatusBar.GetPaneInfo(0,nID,nStyle,cxwidth);
	frame->m_wndStatusBar.SetPaneInfo(0,nID,SBPS_STRETCH|SBPS_NORMAL,cxwidth);
	CString cs;
	cs.Format("得分=%d",count);
	frame->m_wndStatusBar.SetPaneText(0,cs);
}

void CFanView::Star()
{
	for(int i=0;i<4;i++)
	{
		aa[i].x=0;
		aa[i].y=0;
	}
//	KillTimer(IDC_TIMER);
//	SetTimer(IDC_TIMER,time,NULL);
	R=0;
	H=5;
	index=rand()%7;
	switch(index)
	{
		case 1:
				aa[0].x=R;
				aa[0].y=H;
				aa[1].x=R;
				aa[1].y=H+1;
				aa[2].x=R;
				aa[2].y=H-1;
				aa[3].x=R;
				aa[3].y=H-2;
				tempcolor=RGB(80,154,175);
				
				/*//cor[R][H]=1;//----//
				cor[R][H+1]=1;
				cor[R][H-1]=1;
				cor[R][H-2]=1;*/
				break;
		case 2:
				aa[0].x=R;
				aa[0].y=H;
				aa[1].x=R;
				aa[1].y=H+1;
				aa[2].x=R+1;
				aa[2].y=H+1;
				aa[3].x=R+1;
				aa[3].y=H+2;
				tempcolor=RGB(43,213,140);
				
			/*	cor[R][H]=1;
				cor[R][H+1]=1;	//|_
				cor[R+1][H+1]=1;//  |
				cor[R+1][H+2]=1;*/
				break;
		case 3:
				aa[0].x=R;
				aa[0].y=H;
				aa[1].x=R;
				aa[1].y=H+1;
				aa[2].x=R-1;
				aa[2].y=H+1;
				aa[3].x=R-1;
				aa[3].y=H+2;
				tempcolor=RGB(233,149,22);
				/*cor[R][H]=1;		//	_|
				cor[R+1][H]=1;	//     |
				cor[R+1][H-1]=1;
				cor[R+2][H-1]=1;*/
				break;
		case 4:
				aa[0].x=R;
				aa[0].y=H;
				aa[1].x=R;
				aa[1].y=H+1;
				aa[2].x=R;
				aa[2].y=H+2;
				aa[3].x=R+1;
				aa[3].y=H+2;
				tempcolor=RGB(210,23,191);
				/*cor[R][H]=1;	//|
				cor[R+1][H]=1;//  |
				cor[R+2][H]=1;//  |__
				cor[R+2][H+1]=1;*/
				break;
		case 5:
				aa[0].x=R;
				aa[0].y=H;
				aa[1].x=R;
				aa[1].y=H+1;
				aa[2].x=R;
				aa[2].y=H+2;
				aa[3].x=R-1;
				aa[3].y=H+2;
				tempcolor=RGB(9,24,225);
				/*cor[R][H]=1;	//|
				cor[R+1][H]=1;//  |
				cor[R+2][H]=1;//__|
				cor[R+2][H-1]=1;*/
				break;
		case 6:
				aa[0].x=R;
				aa[0].y=H;
				aa[1].x=R+1;
				aa[1].y=H;
				aa[2].x=R+1;
				aa[2].y=H+1;
				aa[3].x=R+1;
				aa[3].y=H-1;
				tempcolor=RGB(5,228,211);
				/*cor[R][H]=1;//  |
				cor[R+1][H]=1;// _|_
				cor[R+1][H+1]=1;// 
				cor[R+1][H-1]=1;*/
				break;
		case 0:
				aa[0].x=R;
				aa[0].y=H;
				aa[1].x=R;
				aa[1].y=H+1;
				aa[2].x=R+1;
				aa[2].y=H;
				aa[3].x=R+1;
				aa[3].y=H+1;
				tempcolor=RGB(77,68,70);
				/*cor[R][H]=1;	//|----|
				cor[R][H+1]=1;//  |____|
				cor[R+1][H]=1;//  
				cor[R+1][H+1]=1;*/
				break;


	}	
	myDraw();
//	Invalidate();
//	OnPaint();
		K=1;
}

void CFanView::On1() 
{
	time=1000;
}

void CFanView::OnUpdate1(CCmdUI* pCmdUI) 
{
	if(time==1000)
	{
		pCmdUI->SetCheck(1);
	}
	else
	{
		pCmdUI->SetCheck(0);
	}
	
}

void CFanView::On2() 
{
	time=300;
	
}

void CFanView::OnUpdate2(CCmdUI* pCmdUI) 
{
	if(time==300)
	{
		pCmdUI->SetCheck(1);
	}
	else
	{
		pCmdUI->SetCheck(0);
	}
	
}

void CFanView::On3() 
{
	time=60;	
}

void CFanView::OnUpdate3(CCmdUI* pCmdUI) 
{
	if(time==60)
	{
		pCmdUI->SetCheck(1);
	}
	else
	{
		pCmdUI->SetCheck(0);
	}
	

	
}

void CFanView::OnStar() 
{
	Star();	
}

void CFanView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if(!Y)
	{
		K=0;
		switch(nChar)
		{
			case VK_LEFT:
			case VK_NUMPAD4:
						if(!(Isout(1)==2))
						{
							flag=1;
							clean(0);
							H--;
							for(int a=0;a<4;a++)
							{
										aa[a].y--;
							}
						//	Invalidate();
						}
						break;

			case VK_RIGHT:
			case VK_NUMPAD6:	
						if(!(Isout(2)==1))
						{
								flag=1;
								clean(0);
								H++;
								for(int a=0;a<4;a++)
								{
									aa[a].y++;
								}
							//	Invalidate();
						}
								break;
		
			case VK_DOWN:
			case VK_NUMPAD2:
//					KillTimer(IDC_TIMER);
						clean(0);
						dop();
						Isover();
						Star();
						break;
			case VK_UP:
			case VK_NUMPAD8:
			case VK_NUMPAD5:
					clean(0);
					k++;
					round(k);
				//	Invalidate();
					break;
						

		}
			K=1;				
	}
	myDraw();
//	OnPaint();
	CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CFanView::OnPaint() 
{
	

	CPaintDC pdc(this); // device context for painting
	
	//	ShowWindow(SW_HIDE);
	
	COLORREF clrTopLeft = RGB(68, 71, 140);
	COLORREF clrBottomRight = RGB(70, 166,152);
	COLORREF clrTopLeft2 = ::GetSysColor(COLOR_BTNHILIGHT);
	COLORREF clrBottomRight2 = ::GetSysColor(COLOR_BTNSHADOW);
	CRect rect;
	CMemDC dc(&pdc);


	register const UINT wide =20;
	register const UINT hight = 20;

	// paint the board itself
	
	if(flag)
	{
		for(int a=0;a<4;a++)
		{
				cor[aa[a].x][aa[a].y]=1;
		}
		for(int x=0;x<20;x++)
		{
			for(int j=0;j<10;j++)
			{
				if(cor[x][j]==1)
				{
				dc.FillSolidRect(100+20+j*20,x*20,wide,hight,clrTopLeft);
				dc.Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft, clrBottomRight);
				}
			}
		}

	}

	for(int x=0;x<20;x++)
	{
		for(int j=0;j<10;j++)
		{
				dc.FillSolidRect(100+20+j*20,x*20,wide,hight,clrTopLeft2);
				dc.Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft, clrTopLeft2);
		}
	}
	for( x=0;x<20;x++)
	{
		for(int j=0;j<10;j++)
		{
			if((cor[x][j]==1)||(cor[x][j]==2))
			{
				dc.FillSolidRect(100+20+j*20,x*20,wide,hight,clrTopLeft);
				dc.Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft, clrBottomRight);
			}
		}
	}


/*		if(x==19)
		{
			pDC->BitBlt(100+200,400,wide,hight,&pcd2,0,0,SRCCOPY);
			//wait.Restore();

			pDC->BitBlt(100+220,400,wide,hight,&pcd2,0,0,SRCCOPY);
			//wait.Restore();

		}
	}
		

				dc.FillSolidRect(j*m_nSquareWidth, i*m_nSquareHeight, m_nSquareWidth, m_nSquareHeight, m_Board[i][j]);
				dc.Draw3dRect(j*m_nSquareWidth, i*m_nSquareHeight, m_nSquareWidth, m_nSquareHeight, clrTopLeft, clrBottomRight);
			}
		}
		
	// now paint the current piece ...
	if( m_pCurPiece != 0 ) {
		register const int nLines = m_pCurPiece->GetLines();
		register const int nCols  = m_pCurPiece->GetColumns();

		for( register int l = nLines-1 ; l >= 0 ; --l )
			for( register int c = 0 ; c < nCols ; ++c ) {
				int nL = m_nCurLine - ((nLines-1) & l);
				int nC = m_nCurCol + c;
				if( nL >= 0 && nL < Height() &&
					nC >= 0 && nC < Width() )
					if( m_pCurPiece->IsSquare(l, c) ) {
						dc.FillSolidRect(nC*m_nSquareWidth, nL*m_nSquareHeight, m_nSquareWidth, m_nSquareHeight, m_clrCurPiece);
						dc.Draw3dRect(nC*m_nSquareWidth, nL*m_nSquareHeight, m_nSquareWidth, m_nSquareHeight, clrTopLeft, clrBottomRight);
					}
			}
	}

	// draw the grid
	if( m_bShowGrid ) {
		// draw vertical lines
		for( register h = m_nSquareWidth; h < rect.Width(); h += m_nSquareWidth ) {
			dc.MoveTo(h, 0);
			dc.LineTo(h, rect.bottom);
		}

		// draw horizontal lines
		for( register v = m_nSquareHeight; v < rect.Height(); v += m_nSquareHeight ) {
			dc.MoveTo(0, v);
			dc.LineTo(rect.right, v);
		}*/
	//ShowWindow(SW_SHOW);
}


void CFanView::OnDraw(CDC* pDC) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	
}

void CFanView::myDraw()
{
	CDC* dc=GetDC();
	COLORREF clrTopLeft = RGB(68, 71, 140);
	COLORREF clrBottomRight = RGB(70, 166,152);
	COLORREF clrTopLeft2 = ::GetSysColor(COLOR_BTNHILIGHT);
	COLORREF clrBottomRight2 = ::GetSysColor(COLOR_BTNSHADOW);
	
	register const UINT wide =20;
	register const UINT hight = 20;

	// paint the board itself
		for(int a=0;a<4;a++)
		{
				dc->FillSolidRect(100+20+dd[a].y*20,dd[a].x*20,wide,hight,clrTopLeft2);
				dc->Draw3dRect(100+20+dd[a].y*20,dd[a].x*20,wide,hight,clrTopLeft2, clrBottomRight2);
				dc->FillSolidRect(100+20+dd[a].y*20,dd[a].x*20,wide,hight,clrTopLeft2);
				dc->Draw3dRect(100+20+dd[a].y*20,dd[a].x*20,wide,hight,clrTopLeft, clrTopLeft2);
		}

	if(flag)
	{
		for(int a=0;a<4;a++)
		{
				cor[aa[a].x][aa[a].y]=1;
		}
		for(int x=0;x<20;x++)
		{
			for(int j=0;j<10;j++)
			{
				if(cor[x][j]==1)
				{
				dc->FillSolidRect(100+20+j*20,x*20,wide,hight,tempcolor);
				dc->Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft, tempcolor);
				}
			}
		}

	}
	if(flag2)
	{
			for(int x=0;x<20;x++)
			{
				for(int j=0;j<10;j++)
				{
						dc->FillSolidRect(100+20+j*20,x*20,wide,hight,clrTopLeft2);
						dc->Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft, clrTopLeft2);
				}
			}
			for( x=0;x<20;x++)
			{
				for(int j=0;j<10;j++)
				{
					if((cor[x][j]==1)||(cor[x][j]==2))
					{
						dc->FillSolidRect(100+20+j*20,x*20,wide,hight,color[x][j]);
						dc->Draw3dRect(100+20+j*20,x*20,wide,hight,clrTopLeft, color[x][j]);
					}
				}
			}
			flag2=0;
	}


}

void CFanView::OnKillFocus(CWnd* pNewWnd) 
{
	CView::OnKillFocus(pNewWnd);
//	KillTimer(IDC_TIMER);
	// TODO: Add your message handler code here
	
}

void CFanView::OnSetFocus(CWnd* pOldWnd) 
{
	CView::OnSetFocus(pOldWnd);
//	SetTimer(IDC_TIMER,time,NULL);	
}

⌨️ 快捷键说明

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