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

📄 gameview.cpp

📁 这是一个连连看的游戏源程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	//pDC->Rectangle(x,y,x+MyGame->m_dx, y+MyGame->m_dy) ;
	pDC->SelectObject(&OldPen) ; 
}

void CGameView::DrawData(CDC *pDC, int xw, int yw)
{
	int x, y ;
	MyGame->TranToXY(&x, &y, xw, yw) ;
	CString str ;
	if ( MyGame->m_Data[xw][yw] != 0 )
	{
		str.Format("%#2d",MyGame->m_Data[xw][yw]) ;
		pDC->TextOut(x+2,y+2,str);
	}
}

void CGameView::DrawGraph()
{
	switch(MyGame->m_Layer)
	{
	case M_NO :			//不变化
	case M_OUT :		//向外扩散,未完成
	case M_IN :			//向内集中,未完成
	case M_DOWN :		//向下
	case M_UP :			//向上
	case M_UPDOWN :		//上下分离
	case M_UPDOWN1 :	//上下集中 
	case M_UPDOWN2 :	//左下右上
		DrawGraphY(MyGame->m_xw[0]) ;
		DrawGraphY(MyGame->m_xw[1]) ;
		break ;
	case M_LEFT :		//向左
	case M_RIGHT :		//向右
	case M_LEFTRIGHT :	//左右分离
	case M_LEFTRIGHT1 :	//左右集中
	case M_LEFTRIGHT2 :	//上左下右
		DrawGraphX(MyGame->m_yw[0]) ;
		DrawGraphX(MyGame->m_yw[1]) ;
		break ;
	}
}

void CGameView::DrawGraphX(int yw)
{
	for( int xw = 0 ; xw<MyGame->m_Xsize; xw++ )
		DrawFrame(DRAW, xw, yw) ;
}

void CGameView::DrawGraphY(int xw)
{
	for( int yw = 0 ; yw<MyGame->m_Ysize; yw++ )
		DrawFrame(DRAW, xw, yw) ;
}

void CGameView::DrawBackground(CDC *pDC, UINT nIDResource)
{
	CBitmap bmp;
	if (bmp.LoadBitmap(nIDResource))
	{
		BITMAP bmpInfo;
		bmp.GetBitmap(&bmpInfo);
		
		CDC dcMemory;
		dcMemory.CreateCompatibleDC(pDC);
		
		CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);
		
		CRect rect;
		GetClientRect(&rect);
		int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2;
		int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2;
		
		pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory, 
			0, 0, SRCCOPY);
		
		dcMemory.SelectObject(pOldBitmap);
		bmp.DeleteObject() ;
	}
	else
		TRACE("ERROR: Can not load bitmap!");
}

/***************菜单响应设计***************/

void CGameView::OnEasy() 
{
	// TODO: Add your command handler code here
	MyGame->m_Class = EASY ;
	MyGame->SetClass() ;
	MyGame->InitData() ;
	Invalidate() ;
}

void CGameView::OnNormal() 
{
	// TODO: Add your command handler code here
	MyGame->m_Class = NORMAL ;
	MyGame->SetClass() ;
	MyGame->InitData() ;
	Invalidate() ;	
}

void CGameView::OnHard() 
{
	// TODO: Add your command handler code here
	MyGame->m_Class = HARD ;
	MyGame->SetClass() ;
	MyGame->InitData() ;
	Invalidate() ;	
}

void CGameView::OnPrompt() 
{
	// TODO: Add your command handler code here
	if (MyGame->m_Class==EMPTY)
		return ;
	if ( MyGame->m_Prompt==0 ) return ;
	else
	{
		MyGame->m_Prompt-- ;
		DispPrompt() ;	
	}
	GameMode = AUTO ;
	if (MyGame->TestAll())
	{
		DrawFrame(EDIT, MyGame->m_xw[0], MyGame->m_yw[0]) ;
		DrawFrame(EDIT, MyGame->m_xw[1], MyGame->m_yw[1]) ;
		MyGame->m_num = -1 ;
	}
}

void CGameView::OnTest() 
{
	// TODO: Add your command handler code here
	TestGame = TEST ;
	Invalidate() ;
}

void CGameView::OnGame() 
{
	// TODO: Add your command handler code here
	TestGame = GAME ;
	Invalidate() ;
}

void CGameView::OnMode() 
{
	// TODO: Add your command handler code here
	TestGame ^= 1 ;
	Invalidate() ;
}

void CGameView::OnRestart() 
{
	// TODO: Add your command handler code here
	MyGame->m_Look-- ;
	MyGame->ReInitData() ;
	GameMode = DRAW ;
	Invalidate() ;
}

void CGameView::OnPause() 
{
	// TODO: Add your command handler code here
	MyGame->m_Pause ^= 1 ;
	if ( MyGame->m_Pause )
	{	CClientDC dc(this) ;
		DrawBack0(&dc, BACK, MyGame->m_xc,MyGame->m_yc,
			MyGame->m_xc+(MyGame->m_Xsize)*MyGame->m_dx,
			MyGame->m_yc+(MyGame->m_Ysize)*MyGame->m_dy) ;
		DrawBackground(&dc, IDB_PAUSE) ;}
	else
		Invalidate() ;
}

void CGameView::OnQuit() 
{
	// TODO: Add your command handler code here
	MyGame->m_Class = EMPTY ;
	Invalidate() ;
}

void CGameView::OnNo() 
{
	// TODO: Add your command handler code here
	MyGame->m_Layer = M_NO ;
	MyGame->InitData() ;		//重新初始化
	Invalidate() ;
}

void CGameView::OnDown() 
{
	// TODO: Add your command handler code here
	MyGame->m_Layer = M_DOWN ;
	MyGame->InitData() ;		//重新初始化
	Invalidate() ;
}

void CGameView::OnLeft() 
{
	// TODO: Add your command handler code here
	MyGame->m_Layer = M_LEFT ;
	MyGame->InitData() ;		//重新初始化
	Invalidate() ;
}

void CGameView::OnUpdown() 
{
	// TODO: Add your command handler code here
	MyGame->m_Layer = M_UPDOWN ;
	MyGame->InitData() ;		//重新初始化
	Invalidate() ;
}

void CGameView::OnLeftright() 
{
	// TODO: Add your command handler code here
	MyGame->m_Layer = M_LEFTRIGHT ;
	MyGame->InitData() ;		//重新初始化
	Invalidate() ;
}

void CGameView::OnLeftright1() 
{
	// TODO: Add your command handler code here
	MyGame->m_Layer =M_LEFTRIGHT1 ;
	MyGame->InitData() ;		//重新初始化
	Invalidate() ;		
}

void CGameView::OnUpdown1() 
{
	// TODO: Add your command handler code here
	MyGame->m_Layer = M_UPDOWN1 ;
	MyGame->InitData() ;		//重新初始化
	Invalidate() ;
}

void CGameView::OnLeftright2() 
{
	// TODO: Add your command handler code here
	MyGame->m_Layer = M_LEFTRIGHT2 ;
	MyGame->InitData() ;		//重新初始化
	Invalidate() ;
}

void CGameView::OnUpdown2() 
{
	// TODO: Add your command handler code here
	MyGame->m_Layer = M_UPDOWN2 ;
	MyGame->InitData() ;		//重新初始化
	Invalidate() ;
}

void CGameView::OnPrevLayer() 
{
	// TODO: Add your command handler code here
	if (MyGame->m_Layer==0)
		MyGame->m_Layer=M_IN ;
	else MyGame->m_Layer-- ;
	MyGame->InitData() ;		//重新初始化
	Invalidate() ;
}

void CGameView::OnNextLayer() 
{
	// TODO: Add your command handler code here
	if (MyGame->m_Layer==M_IN)
		MyGame->m_Layer=M_NO ;
	else MyGame->m_Layer++ ;
	MyGame->InitData() ;		//重新初始化
	Invalidate() ;
}

/***************定时器设计***************/

int CGameView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	SetTimer(1,667,NULL) ;	//设置定时器
	return 0;
}

void CGameView::OnDestroy() 
{
	CView::OnDestroy();
	
	// TODO: Add your message handler code here
	KillTimer(1) ;			//消除定时器
}

void CGameView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if ((!MyGame->m_Pause)&&(MyGame->m_Class!=EMPTY)&&(!MyGame->m_GameOver)||(MyGame->m_Count==0))
		if (MyGame->m_Time!=0)
		{	MyGame->m_Time-- ;
			CClientDC dc(this) ;
			DispProgress(&dc) ;
		}
		else
		{	CString str ;
			AfxMessageBox("时间已用完,游戏结束!") ;
			MyGame->m_GameOver = true ;
			MyGame->m_Class = EMPTY ;
			Invalidate() ;
		}
	CView::OnTimer(nIDEvent);
}

/***************对于菜单灰化的处理***************/

void CGameView::OnUpdateQuit(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ( MyGame->m_Class == EMPTY )
		pCmdUI->Enable(false) ;
}

void CGameView::OnUpdatePrompt(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Prompt==0)||(MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;
}

void CGameView::OnUpdateRestart(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Look==0)||(MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;
}

void CGameView::OnUpdatePause(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ( MyGame->m_Class == EMPTY )
		pCmdUI->Enable(false) ;
}

void CGameView::OnUpdateNo(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;
}

void CGameView::OnUpdateLeftright(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;	
}

void CGameView::OnUpdateLeftright1(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;	
}

void CGameView::OnUpdateLeftright2(CCmdUI* pCmdUI) 
{
	if ((MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;
	// TODO: Add your command update UI handler code here
}

void CGameView::OnUpdateMode(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;	
}

void CGameView::OnUpdateNextLayer(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;	
}

void CGameView::OnUpdatePrevLayer(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;	
}

void CGameView::OnUpdateTest(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;	
}

void CGameView::OnUpdateUpdown(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;	
}

void CGameView::OnUpdateUpdown1(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;	
}

void CGameView::OnUpdateUpdown2(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;	
}

void CGameView::OnUpdateLeft(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;	
}

void CGameView::OnUpdateGame(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;	
}

void CGameView::OnUpdateDown(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if ((MyGame->m_Class==EMPTY)||MyGame->m_Pause )
		pCmdUI->Enable(false) ;	
}

⌨️ 快捷键说明

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