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

📄 yw_playballview.cpp

📁 本程序是弹球游戏实验程序,故而
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	{
		red_varies_x=-red_varies_x;
        red_position_x+=red_varies_x;
	}

	else
		red_position_x+=red_varies_x;

	if((red_position_y>((RECT)ViewRect).bottom-20)
		||(red_position_y<((RECT)ViewRect).top))
	{
		red_varies_y=-red_varies_y;
        red_position_y+=red_varies_y;
	}
	else
		red_position_y+=red_varies_y;
	
	dc.BitBlt(red_position_x,red_position_y,3200,3200,pMemDC2,0,0,SRCCOPY);
	//pMemDC->SelectObject(Old_Bitmap);//恢复设备环境
	delete pMemDC2;
    //***** ***** ***** ***** *****
	//////////////////////////////////////////////////////////////////
	//&&&&& &&&&& &&& 用于判断两球相撞 &&& &&&&& &&&&&
	if(((locatx+(25/2))>=(red_position_x+(25/2)))
		&&((locaty+(25/2))>=(red_position_y+(25/2)))
	    &&(((locatx+(25/2))-(red_position_x+(25/2)))<=25)
		&&((locaty+(25/2))-(red_position_y+(25/2))<=25))
		{
		  /*CString cs;
		  cs.Format("%d , %d,\n%d , %d",locatx,locaty,red_position_x,red_position_y);
		  dc.TextOut(50,50,cs);*/
		  process=-1;
		  //this->MessageBox(">>程序出现故障!!!!!");
		}
		  
	else if(((locatx+(25/2))>=(red_position_x+(25/2)))
		&&((locaty+(25/2))<(red_position_y+(25/2)))
		&&((locatx+(25/2))-(red_position_x+(25/2))<=25)
		&&((red_position_y+(25/2))-(locaty+(25/2))<=25))
          //this->MessageBox("><程序出现故障!!!!!");
		{
		  /*CString cs;
		  cs.Format("%d , %d,\n%d , %d",locatx,locaty,red_position_x,red_position_y);
		  dc.TextOut(50,50,cs);*/
		  process=-1;
		  //this->MessageBox("><程序出现故障!!!!!");
		}
	else if(((locatx+(25/2))<(red_position_x+(25/2)))
		&&((locaty+(25/2))>=(red_position_y+(25/2)))
		&&((red_position_x+(25/2))-(locatx+(25/2))<=25)
		&&((locaty+(25/2))-(red_position_y+(25/2))<=25))
		{
		  /*CString cs;
		  cs.Format("%d , %d,\n%d , %d",locatx,locaty,red_position_x,red_position_y);
		  dc.TextOut(50,50,cs);*/
		  process=-1;
		  //this->MessageBox("<>程序出现故障!!!!!");
		}
          //this->MessageBox("<>程序出现故障!!!!!");
	else if(((locatx+(25/2))<(red_position_x+(25/2)))
		&&((locaty+(25/2))<(red_position_y+(25/2)))
		&&((red_position_x+(25/2))-(locatx+(25/2))<=25)
		&&(((red_position_y+(25/2))-(locaty+(25/2))<=25)))
		{
		  /*CString cs;
		  cs.Format("%d , %d,\n%d , %d",locatx,locaty,red_position_x,red_position_y);
		  dc.TextOut(50,50,cs);*/
		  process=-1;
		  //this->MessageBox("<<程序出现故障!!!!!");
		}
	else;
	   //this->MessageBox("程序出现故障!!!!!");
   //&&&&& &&&&& &&&&& &&&&& &&&&& &&&&& &&&&&
	if((locatx==yw_x)&&(locaty==yw_y))//加分判断
	{
	 pingmu_count+=10;//加十分
	}
	CScrollView::OnTimer(nIDEvent);
}

void CYw_PlayBallView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CClientDC dc(this);
	CString str;
	if(g_Cursor_Flags==1)//鼠标按下时
	{
	 SetCursor(AfxGetApp()->LoadCursor(IDC_YW_CUR1));//加载自定义光标
	 str.LoadString(ID_YW1);
	 dc.TextOut(0,0,str);//将字符串输出到用户区 
	 dc.TextOut(0,20,str);
     
	}
	else//鼠标抬起时
	{
     SetCursor(AfxGetApp()->LoadCursor(IDC_YW_CUR2));//加载自定义光标
	 str.LoadString(ID_YW2);
	 CString score,speed;
	 CMainFrame *pa=(CMainFrame *)AfxGetMainWnd();
	 score.Format("您当前的成绩为:%d",pa->now_mark);
	 speed.Format("小球当前的速度为:%.2f",sqrt(values_x*values_x+values_y*values_y));
	 dc.TextOut(0,0,str+"  "+score);//将字符串输出到用户区
	 dc.TextOut(0,20,speed);
	}
	CScrollView::OnMouseMove(nFlags, point);
}

void CYw_PlayBallView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	g_Cursor_Flags=0;
	CScrollView::OnLButtonDown(nFlags, point);
}

void CYw_PlayBallView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	g_Cursor_Flags=1;
	CScrollView::OnLButtonUp(nFlags, point);
}

void CYw_PlayBallView::OnMenuaccelerate()//小球水平加速 
{
	// TODO: Add your command handler code here
	CString csr;  //*********显示小球的操作于状态栏***********
	if((values_x>=0)&&(values_x<x_Max))
	{
		csr.Format("小球正在向右加速,加速度为2.");
	    CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
        (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
		values_x+=2;
	}
	else if((values_x<0)&&(values_x>-x_Max))
	{
		csr.Format("小球正在向左加速,加速度为2.");
	    CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
        (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
		values_x-=2;
	}
	else 
	{
		csr.Format("小球速度已达到最大!!!");
	    CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
        (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
		values_x=values_x;
	}
		
}

void CYw_PlayBallView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	if((nChar==VK_RIGHT)||(nChar==VK_LEFT)||(nChar==VK_UP)||(nChar==VK_DOWN))
	{
	  CString csr;  //*********显示小球的操作于状态栏***********
	  csr.Format("现在无任何操作");
	  CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
      (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
	}
	else if(yw_score_flags==1)//加分点显示撤消
	{
	 yw_score_flags=0;
	 CClientDC fen_dc(this);
	 CDC *pMemDC_fen=new CDC;
	 pMemDC_fen->CreateCompatibleDC(&fen_dc);
	 pMemDC_fen->SelectObject(m_Bit0);//将位图选入内存设备环境中
     //Old_Bitmap=m_Bit_pingkongmu;
	 fen_dc.BitBlt(yw_x,yw_y,3200,3200,pMemDC_fen,0,0,SRCCOPY);
	 //pMemDC->SelectObject(Old_Bitmap);//恢复设备环境
	 delete pMemDC_fen;
	}
	CScrollView::OnKeyUp(nChar, nRepCnt, nFlags);
}

void CYw_PlayBallView::OnMenudrag()//小球水平减速 
{
	// TODO: Add your command handler code here
	CString csr;  //*********显示小球的操作于状态栏***********
	if((values_x>0)&&(values_x<=x_Max))
	{
		csr.Format("小球正在向右减速,加速度为2.");
	    CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
        (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
		values_x-=2;
	}
	else if((values_x<0)&&(values_x>=-x_Max))
	{
		csr.Format("小球正在向左减速,加速度为2.");
	    CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
        (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
		values_x+=2;
	}
	else 
	{
		csr.Format("小球速度已达到最小!!!");
	    CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
        (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
		values_x=values_x;
	}
}

void CYw_PlayBallView::OnMenuup()//小球垂直加速  
{
	// TODO: Add your command handler code here
	CString csr;  //*********显示小球的操作于状态栏***********
	if((values_y>=0)&&(values_y<y_Max))
	{
		csr.Format("小球正在向上加速,加速度为1.");
	    CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
        (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
		values_y++;
	}
	else if((values_y<0)&&(values_y>-y_Max))
	{
		csr.Format("小球正在向下加速,加速度为1.");
	    CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
        (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
		values_y--;
	}
	else 
	{
		csr.Format("小球速度已达到最大!!!");
	    CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
        (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
		values_y=values_y;
	}
}

void CYw_PlayBallView::OnMenuidown()//小球垂直减速 
{
	// TODO: Add your command handler code here
	CString csr;  //*********显示小球的操作于状态栏***********
	if((values_y>0)&&(values_y<=y_Max))
	{
		csr.Format("小球正在向上减速,加速度为1.");
	    CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
        (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
		values_y--;
	}
	else if((values_y<0)&&(values_y>=-y_Max))
	{
		csr.Format("小球正在向下减速,加速度为1.");
	    CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
        (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
		values_y++;
	}
	else 
	{
		csr.Format("小球速度已达到最小!!!");
	    CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
        (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
		values_y=values_y;
	}
}

void CYw_PlayBallView::OnMenuYwRight() 
{
	// TODO: Add your command handler code here
	CString csr;  //*********显示小球的操作于状态栏***********
	csr.Format("小球方向变为右");
	CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
    (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
	if(values_x<0)
		values_x=-values_x;
	else
		values_x=values_x;
}

void CYw_PlayBallView::OnMenuYwLeft() 
{
	// TODO: Add your command handler code here
	CString csr;  //*********显示小球的操作于状态栏***********
	csr.Format("小球方向变为左");
	CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
    (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
	if(values_x>0)
		values_x=-values_x;
	else
		values_x=values_x;
}

void CYw_PlayBallView::OnMenuYwUp() 
{
	// TODO: Add your command handler code here
	CString csr;  //*********显示小球的操作于状态栏***********
	csr.Format("小球方向变为上");
	CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
    (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
	if(values_y>0)
		values_y=-values_y;
	else
		values_y=values_y;
}

void CYw_PlayBallView::OnMenuYwDown() 
{
	// TODO: Add your command handler code here
	CString csr;  //*********显示小球的操作于状态栏***********
	csr.Format("小球方向变为下");
	CMainFrame *parent=(CMainFrame*)AfxGetMainWnd();
    (parent->m_wndStatusBar).SetPaneText((parent->m_wndStatusBar).CommandToIndex(IDS_YW_INFORM),csr);
	if(values_y<0)
		values_y=-values_y;
	else
		values_y=values_y;
}

void CYw_PlayBallView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	if(nChar=='p'||nChar=='P')
	{
		yw_count++;
		if(yw_count%2==1)
		    this->KillTimer(2);
		else
		    this->SetTimer(2,100,NULL);
	}
	if(nChar=='z'||nChar=='Z')//加分点显示
	{
	 yw_score_flags=1;
	 CClientDC fen_dc(this);
	 CDC *pMemDC_fen=new CDC;
	 pMemDC_fen->CreateCompatibleDC(&fen_dc);
	 pMemDC_fen->SelectObject(m_ten);//将位图选入内存设备环境中
     //Old_Bitmap=m_Bit_pingkongmu;
	 fen_dc.BitBlt(yw_x,yw_y,3200,3200,pMemDC_fen,0,0,SRCCOPY);
	 //pMemDC->SelectObject(Old_Bitmap);//恢复设备环境
	 delete pMemDC_fen;
	}
	
	CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CYw_PlayBallView::OnReset() 
{
	// TODO: Add your command handler code here
	CClientDC dc(this);//***** ***** 消除小球原始路径 ***** *****
	CDC *pMemDC0=new CDC;
	pMemDC0->CreateCompatibleDC(&dc);
	pMemDC0->SelectObject(m_Bit0);//将位图选入内存设备环境中
	//Old_Bitmap=m_Bit0;
    dc.BitBlt(locatx,locaty,3200,3200,pMemDC0,0,0,SRCCOPY);
	//pMemDC->SelectObject(Old_Bitmap);//恢复设备环境
	delete pMemDC0;        //***** ***** ***** *****

	values_x=40;//水平移动变化值
    values_y=10;//垂直移动变化值
	x_Max=80;//水平移动最大速度
    y_Max=50;//垂直移动最大速度
	locatx=200; //当前水平方位
    locaty=100; //当前垂直方位
}

void CYw_PlayBallView::OnScore()//加分函数
{
	// TODO: Add your command handler code here
	yw_socre_count++;
	if(yw_socre_count%2==1)//加分点显示
	{
	 CClientDC fen_dc(this);
	 CDC *pMemDC_fen=new CDC;
	 pMemDC_fen->CreateCompatibleDC(&fen_dc);
	 pMemDC_fen->SelectObject(m_ten);//将位图选入内存设备环境中
     //Old_Bitmap=m_Bit_pingkongmu;
	 fen_dc.BitBlt(yw_x,yw_y,3200,3200,pMemDC_fen,0,0,SRCCOPY);
	 //pMemDC->SelectObject(Old_Bitmap);//恢复设备环境
	 delete pMemDC_fen;
	}
	else//加分点显示撤消
	{
	 CClientDC fen_dc(this);
	 CDC *pMemDC_fen=new CDC;
	 pMemDC_fen->CreateCompatibleDC(&fen_dc);
	 pMemDC_fen->SelectObject(m_Bit0);//将位图选入内存设备环境中
     //Old_Bitmap=m_Bit_pingkongmu;
	 fen_dc.BitBlt(yw_x,yw_y,3200,3200,pMemDC_fen,0,0,SRCCOPY);
	 //pMemDC->SelectObject(Old_Bitmap);//恢复设备环境
	 delete pMemDC_fen;
	}
}

⌨️ 快捷键说明

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