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

📄 programview.cpp

📁 飞行棋游戏
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				}
			}
		}
	}
//如果用户点击的是飞机场
	if(!isOntimer && control==0)//首先进行判断此时点飞机场时候有效
	{
		bool t=false;//用来记录DoMsg判断后是否需要发生改变,true则需要改变
		//点击为绿色飞机场
		if(mx>=82&&my>=435&&mx<=196&&my<=547)
			{	
					t=manager.DoMsg(51,0,1,roll);//次函数在后面会有详细介绍
			}
		//点击为红色飞机场
		else	if(mx>=83&&my>=54&&mx<=195&&my<=168)
			{
					t=manager.DoMsg(12,0,1,roll);
			}
		//点击为黄色飞机场
		else	if(mx>=463&&my>=54&&mx<=577&&my<=168)
			{
					t=manager.DoMsg(25,0,1,roll);
			}
		//点击为蓝色飞机场
		else	if(mx>=463&&my>=435&&mx<=575&&my<=547)
			{
					t=manager.DoMsg(38,0,1,roll);
			}
		if(t)//如果DoMsg生效,即需要改变
		{	
			PlaneUpdata();
			PrintAll(pdc);
			PrintState(pdc);
			control++;//control不为0
		}

	}
	ReleaseDC(pdc);//释放无用的CDC
	CView::OnLButtonDown(nFlags, point);
}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:Roll()
* 函数介绍:产生一个随机数
* 输入参数:无
* 输出参数:一个1~6的随机数
* 返回值  :int
*/
int CProgramView::Roll()
{
	srand(time( NULL ));
	return	rand()%6+1;//返回一个为1~6的随机数
}

////////////////////////////////////////////////////////////////////////
/*
* 函数名称:Drawback(int i, 当前飞机的号数
					Chess plane, 当前传入的飞机
					CDC pdc,)绘图用pdc
* 函数介绍:对返回飞行点的飞机进行绘图
* 输入参数:同上
* 输出参数:无
* 返回值  :无
*/
void CProgramView::Drawback(int i, Chess plane, CDC *pdc)
{
//当飞机是被撞回去的时候,plane.state会被重置为0
	if(plane.state==0)
	{
		if(plane.Color==0)//画的为绿色飞机
		{	pdc->BitBlt(90+(i%2)*50,500-(i/2)*50,41,35,&Greenmask,0,0,MERGEPAINT);
			pdc->BitBlt(90+(i%2)*50,500-(i/2)*50,41,35,&Greenplane,0,0,SRCAND);
		}
		else	if(plane.Color==1)//画的为红色飞机
		{	pdc->BitBlt(95+(i%2)*50,120-(i/6)*50,41,35,&Redmask,0,0,MERGEPAINT);
			pdc->BitBlt(95+(i%2)*50,120-(i/6)*50,41,35,&Redplane,0,0,SRCAND);
		}
		else	if(plane.Color==2)//画的为黄色飞机
		{	pdc->BitBlt(470+(i%2)*50,120-(i/10)*50,41,35,&Yellowmask,0,0,MERGEPAINT);
			pdc->BitBlt(470+(i%2)*50,120-(i/10)*50,41,35,&Yellowplane,0,0,SRCAND);
		}
		else	if(plane.Color==3)//画的为蓝色飞机
		{	pdc->BitBlt(470+(i%2)*50,500-(i/14)*50,41,35,&Bluemask,0,0,MERGEPAINT);
			pdc->BitBlt(470+(i%2)*50,500-(i/14)*50,41,35,&Blueplane,0,0,SRCAND);
		}
	}
}
///////////////////////////////////////////////////////////////////
/*
*函数名称:printAll(CDC	*pdc)
*函数介绍:重绘所有16架飞机
*输入参数:CDC *pdc 绘图用CDC
*输出参数:无
*返回值	 :无
*/
void CProgramView::PrintAll(CDC	*pdc)
{
	pdc->BitBlt(0,0,800,600,&Background,0,0,SRCCOPY);//首先重绘背景图片
	//便历所有16架飞机
	int	i;
	for(i=0;i<=15;i++)
	{	if(plthis[i].state==0)//如果该飞机仍然在飞机场,或者被打了回去
			Drawback(i,plthis[i],pdc);
		else
			Drawplane(plthis[i],pdc);//如果该飞机处于1~4状态
	}
	m_cflash.Play();
}
/////////////////////////////////////////////////////////////////////
/*
*函数名称:PlaneUpdata()
*函数介绍:更新lastplane[16]
*输入参数:无
*输出参数:无
*返回值	 :无
*/
void CProgramView::PlaneUpdata()
{
	int	i;
	for(i=0;i<=15;i++)
		lastplane[i]=plthis[i];//用manager中发生改变后的Planes对lastplane进行
								//更新,保证绘图的即使性,同时lastplane可以记
								//发生改变的前一次的飞机状态
}										

////////////////////////////////////////////////////////////////////////
/*
*函数名称:SelectPlane(Chess plane, int mx, int my)
*函数介绍:用来判断当前用户的点击时候选种了状态为1~3的飞机
*输入参数:plane 飞机,mx 点击时的横坐标,my 点击时的纵坐标
*输出参数:bool	
*返回值  :如果为TRUE,则当前选中的为状态为1~3的飞机的飞机,为FALSE则没有选中
*/
bool CProgramView::SelectPlane(Chess plane, int mx, int my)
{
	//记录当前飞机的坐标	
		int	x;
		int	y;
//根据飞机的状态和所处格子数来获取当前飞机的坐标

//当飞机处于状态2,即飞行状态时
	if(plane.state==2)
	{
		//第一分区的格子(左下),为0~12格
		if(plane.step/13==0)
		{	
		//第0~3格,记录当前坐标
			if(plane.step/4==0)
			{	
				x=215+plane.dou;
				y=497-plane.step*31;
			}
		//第4~7格,记录当前坐标
			else	if(plane.step/4==1)
			{
				x=190+plane.dou-(plane.step-4)*31;
				y=385;
			}
		//第8~12格,记录当前坐标
			else
			{
				x=90+plane.dou;
				y=350-(plane.step-8)*31;
			}
		}
		//第二分区的格子(左上),为13~25格
		else if(plane.step/13==1)
		{
			plane.step-=13;	//做相对变换,方便同第一区最相同的处理
			//第13~16格,可以同第一区的第0~3格做内似处理
			if(plane.step/4==0)
			{
				x=100+plane.dou+plane.step*31;
				y=190;
			}
			//第17~20格,可以同第一区的第4~6格做内似处理
			else	if(plane.step/4==1)
			{
				x=210+plane.dou;
				y=172-(plane.step-4)*31;
			}
			//第21~25格,可以同第一区的第8~12格做内似处理
			else
			{
				x=250+plane.dou+(plane.step-8)*31;
				y=65;
			}
		}
		//第三分区的格子(右上),为26~38格
		else if(plane.step/13==2)
		{
			plane.step-=26;	//做相对变换,方便同第一区最相同的处理
			//第26~29格
			if(plane.step/4==0)
			{
				x=405+plane.dou;
				y=82+plane.step*31;
			}
			//第30~33格
			else	if(plane.step/4==1)
			{
				x=425+plane.dou+(plane.step-4)*31;
				y=190;
			}
			//第34~38格
			else
			{
				x=530+plane.dou;
				y=225+(plane.step-8)*31;
			}
		}
		//第四分区的格子(右下),为39~51格
		else if(plane.step/13==3)
		{
			plane.step-=39;	//做相对变换,方便同第一区最相同的处理
			//第39~42格
			if(plane.step/4==0)
			{
				x=520+plane.dou-plane.step*31;
				y=385;
			}
			//第43~46格
			else	if(plane.step/4==1)
			{
				x=405+plane.dou;
				y=405+(plane.step-4)*31;
			}
			//第47~51格
			else
			{
				x=370+plane.dou-(plane.step-8)*31;
				y=505;
			}
		}

	}
//飞机进入状态1,即准备起飞状态
	else	if(plane.state==1)
	{
		if(plane.step==51)//表示此时的plane为绿色飞机
		{
			x=200+plane.dou;
			y=516;
		}
		else	if(plane.step==12)//表示此时的plane为红色飞机
		{
			x=86+plane.dou;
			y=174;
		}
		else	if(plane.step==25)//表示此时的plane为黄色飞机
		{
			x=420+plane.dou;
			y=55;
		}
		else	if(plane.step==38)//表示此时的plane为蓝色飞机
		{
			x=540+plane.dou;
			y=400;
		}
	}
//飞机进入状态3,即准备降落状态
	else	if(plane.state==3)
	{
		
		if(plane.step>=11&&plane.step<=15)//表示飞机处于红色跑道
		{
			x=130+plane.dou+(plane.step-11)*32;
			y=290;
		}
		else	if(plane.step>=24&&plane.step<=28)//表示飞机处于黄色跑道
		{	x=310+plane.dou;
			y=100+(plane.step-24)*32;
		}
		else	if(plane.step>=37&&plane.step<=41)//表示飞机处于蓝色跑道
		{
			x=490+plane.dou-(plane.step-37)*32;
			y=290;
		}
		else	if(plane.step>=50&&plane.step<=54)//表示飞机处于绿色跑道
		{	
			x=310+plane.dou;
			y=465-(plane.step-50)*32;
		}
	
	}
//飞机处于状态4,即已经降落
	else	if(plane.state==4)
	{
		if(plane.Color==0)//如果是绿色飞机降落
			{
				x=310+plane.dou;
				y=310;
			}
		else	if(plane.Color==1)//如果是红色飞机降落
			{
				x=285;
				y=280;
			}
		else	if(plane.Color==2)//如果是黄色飞机降落
			{
				x=310;
				y=260;
			}
		else	if(plane.Color==3)//如果是蓝色飞机降落
			{
				x=335;
				y=285;
			}
	}
	else
	{

	}
//在原有飞机位图坐标的基础上产生一定偏移,使点击在飞机中央的时候才能生效
	if(mx>=x+16&&mx<=x+27&&my>=y+7&&my<=y+20)
		return	TRUE;
	else
		return	FALSE;
}
///////////////////////////////////////////////////////////////////////
/*
*函数名称:PrintState(CDC *pdc)
*函数介绍:打印当前的游戏状态
*输入参数:CDC *pdc 绘图用CDC
*输出参数:无
*返回值  :无
*/
void CProgramView::PrintState(CDC *pdc)
{	
	//骰子状态
//	if(control==0)//如果骰子还没被掷
//		pdc->BitBlt(690,80,40,40,&Num,0,0,SRCCOPY);
//	else//如果骰子已被掷
//		pdc->BitBlt(690,80,40,40,&Num,roll*35,0,SRCCOPY);

	pdc->BitBlt(400,10,50,40,&Background,350,10,SRCCOPY);//覆盖之前的飞机
	//玩家状态
	if(manager.Game_State==0)//到绿色玩家掷骰子
	{
		pdc->BitBlt(400,10,41,35,&Greenmask,0,0,MERGEPAINT);
		pdc->BitBlt(400,10,41,35,&Greenplane,0,0,SRCAND);
	}
	else if(manager.Game_State==1)//到红色玩家掷骰子
	{
		pdc->BitBlt(400,10,41,35,&Redmask,0,0,MERGEPAINT);
		pdc->BitBlt(400,10,41,35,&Redplane,0,0,SRCAND);
	}
	else if(manager.Game_State==2)//到黄色玩家掷骰子
	{
		pdc->BitBlt(400,10,41,35,&Yellowmask,0,0,MERGEPAINT);
		pdc->BitBlt(400,10,41,35,&Yellowplane,0,0,SRCAND);
	}
	else if(manager.Game_State==3)//到蓝色玩家掷骰子
	{
		pdc->BitBlt(400,10,41,35,&Bluemask,0,0,MERGEPAINT);
		pdc->BitBlt(400,10,41,35,&Blueplane,0,0,SRCAND);
	}

}

void CProgramView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
		CDC	*pdc=GetDC();
		static int isgo = 1;	//记录下一次是向前飞还是向后飞

		timer--;	//记数器减一
		if(timer>=0)
			isgo = manager.OneStep(isgo, roll);	
		else if(timer==-1)	
		{
			manager.UpData(roll);	//更新
			isgo = 1;
			isOntimer = false;
			KillTimer(1);	//删除定时器
		}
		PrintAll(pdc);


		ReleaseDC(pdc);
	CView::OnTimer(nIDEvent);
}


int CProgramView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;

	//获取程序当前运行路径
	TCHAR szFilePath[MAX_PATH + 1];
	GetModuleFileName(NULL, szFilePath, MAX_PATH);
	(_tcsrchr(szFilePath, '\\'))[1] = '\0'; //删除文件名,只获得路径
	CString str_url =  szFilePath;
	str_url += "roll.swf";
	
	//创建ActiveX对象
	m_cflash.Create(NULL,NULL, WS_CHILD|WS_VISIBLE, CRect(650, 50, 770, 168), this, FLASHID);
	m_cflash.SetMovie(str_url);
	m_cflash.Stop();
	m_cflash.SetScaleMode(1);
	
	return 0;
}

BEGIN_EVENTSINK_MAP(CProgramView, CView)
	ON_EVENT(CProgramView, FLASHID, 150 /* FSCommand */, OnFSCommandFlash, VTS_BSTR VTS_BSTR)
END_EVENTSINK_MAP()


///////////////////////////////////////////////////////////////////////
/*
*函数名称:OnFSCommandFlash(LPCTSTR command, LPCTSTR args)
*函数介绍:flash消息响应函数
*输入参数:LPCTSTR command, LPCTSTR args  (FSCommand传递的参数)
*输出参数:无
*返回值  :无
*/
void CProgramView::OnFSCommandFlash(LPCTSTR command, LPCTSTR args)
{
	UCHAR com,arg;
    com = *command;
    arg = *args;
	CDC *pdc = GetDC();
	int Num;	//纪录当前的flash播放帧数
	if(!isOntimer && (control!=0))
	{
		switch(com) 
			{
			case '1':
			{
				switch(arg) 
				{
				 case '1':	
					 if(m_cflash.GetPlaying())	//如果flash在播放
					 {
						 m_cflash.StopPlay();	//停止播放flash
						 char str[20];
						 Num = (int)m_cflash.GetFrameNum();	//得到flash播放到的帧数
						 sprintf(str, "%c", m_cflash.num[Num]);
						 roll = atoi(str);	//得到色子数
						 PrintState(pdc);	//打印当前游戏状态;
					 }
					 else
					 {
						 m_cflash.Play();
					 }
					 break;
				 default:
					 break;
				}
			}
				 break;
			default:
				 break;
			}
			control = 0;
			ischange = manager.Game_State;
			if(manager.DoMsg(1,1,3,roll))//如果此时DoMsg返回为TRUE的时候,即需
			{							 //要发生改变的时候
				if(manager.PlAuto == NULL)
				{
					m_cflash.GotoFrame(Num);	//定位Flash到Num帧
					m_cflash.Stop();	//停止播放Flash
					control++;//control++,则不再0
					if(manager.Game_State != ischange)	//判断是否该下个玩家丢色字
					{
						CString st;
						st.Format("你丢了%d点,不能产生任何动作,该下个玩家丢色子",roll);
						MessageBox(st);	//提示玩家,该下个玩家丢色子了
						m_cflash.Play();	//播放Flash
					}
					PrintState(pdc);;	//打印当前游戏状态;
				}
				else
				{
					timer = roll;
					SetTimer(1, 500, NULL);
					isOntimer = true;
				}
			}
			
	}
	else
	{
		m_cflash.StopPlay();	
	}
	ReleaseDC(pdc);
}

⌨️ 快捷键说明

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