当前位置: 首页>>代码示例>>C++>>正文


C++ Tank::Redraw方法代码示例

本文整理汇总了C++中Tank::Redraw方法的典型用法代码示例。如果您正苦于以下问题:C++ Tank::Redraw方法的具体用法?C++ Tank::Redraw怎么用?C++ Tank::Redraw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tank的用法示例。


在下文中一共展示了Tank::Redraw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
	Init();
	HideCurSor();
	Welcome();
	DrawMap();
	HANDLE temp;
	int newD;
	player.DrawTank();
	while(GameOver==0)
	{
		if(GetAsyncKeyState(VK_UP))//按键上
		{
			WaitForSingleObject(Mutex,INFINITE);
			newD=Up;
			player.Redraw();
			if(player.Judge(player.GetHotX()-1,player.GetHotY(),newD)==0)//移动玩家坦克,原理和敌人函数一样
			{
				player.ChangePos(player.GetHotX()-1,player.GetHotY());
				player.ChangeDirection(newD);
			}
			else
			{
				if(player.Judge(player.GetHotX(),player.GetHotY(),newD)==0)
					player.ChangeDirection(newD);
            }
			if(GameOver==0)
			   player.DrawTank();
			ReleaseMutex(Mutex);
			Sleep(200-player.GetSpeed()*20);//按键延迟,决定玩家坦克的速度
		}
		else if(GetAsyncKeyState(VK_DOWN))//按键下,同上
		{
			WaitForSingleObject(Mutex,INFINITE);
			newD=Down;
			player.Redraw();
			if(player.Judge(player.GetHotX()+1,player.GetHotY(),newD)==0)
			{
				player.ChangePos(player.GetHotX()+1,player.GetHotY());
				player.ChangeDirection(newD);
			}
			else
			{
				if(player.Judge(player.GetHotX(),player.GetHotY(),newD)==0)
					player.ChangeDirection(newD);
            }
			if(GameOver==0)
			   player.DrawTank();
			ReleaseMutex(Mutex);
			Sleep(200-player.GetSpeed()*20);
		}
		else if(GetAsyncKeyState(VK_RIGHT))//按键右,同上
		{
			WaitForSingleObject(Mutex,INFINITE);
			newD=Right;
			player.Redraw();
			if(player.Judge(player.GetHotX(),player.GetHotY()+1,newD)==0)
			{
				player.ChangePos(player.GetHotX(),player.GetHotY()+1);
				player.ChangeDirection(newD);
			}
			else
			{
				if(player.Judge(player.GetHotX(),player.GetHotY(),newD)==0)
					player.ChangeDirection(newD);
            }
			if(GameOver==0)
			   player.DrawTank();
			ReleaseMutex(Mutex);
			Sleep(200-player.GetSpeed()*20);
		}
		else if(GetAsyncKeyState(VK_LEFT))//按键左,同上
		{
			WaitForSingleObject(Mutex,INFINITE);
			newD=Left;
			player.Redraw();
			if(player.Judge(player.GetHotX(),player.GetHotY()-1,newD)==0)
			{
				player.ChangePos(player.GetHotX(),player.GetHotY()-1);
				player.ChangeDirection(newD);
			}
			else
			{
				if(player.Judge(player.GetHotX(),player.GetHotY(),newD)==0)
					player.ChangeDirection(newD);
            }
			if(GameOver==0)
			   player.DrawTank();
			ReleaseMutex(Mutex);
			Sleep(110-player.GetSpeed()*10);
		}
		else if(GetAsyncKeyState(VK_SPACE))//按键空格,发射子弹
		{
			WaitForSingleObject(Mutex,INFINITE);
			if(player.FireEnable==1)//如果可以发射
			{
			   HANDLE bullet=CreateThread(NULL,0,Bulletfly,&(player.ID),0,NULL);//创建玩家子弹进程
			   CloseHandle(bullet);
			   player.FireEnable=0;
			}
//.........这里部分代码省略.........
开发者ID:PureMoonStudio,项目名称:Tools,代码行数:101,代码来源:源.cpp

示例2: Bulletfly


//.........这里部分代码省略.........
	}
	else if(direction==Down)
	{
		Pos[0]+=3;
		Pos[1]++;
	}
	else if(direction==Left)
	{
		Pos[0]++;
		Pos[1]--;
	}
	else if(direction==Right)
	{
		Pos[0]++;
		Pos[1]+=3;
	}
	//子弹的运行
	while(1)
	{
		WaitForSingleObject(Mutex,INFINITE);//这个不再注释了。。。。。
		if(flag==1&&hit!=1)//擦除原位置
		{
    	   map[oldx][oldy]=Empty;
		   SetPos((oldy+1)*2,oldx+1);
		   cout<<" ";
		}
		if(GameOver==1)
			return 0;
		if(hit==1||Pos[0]<0||Pos[0]>22||Pos[1]<0||Pos[1]>22)//如果击中
		{
			ReleaseMutex(Mutex);
			Sleep(500);
			if(type==PlayerBullet)
				player.FireEnable=1;
			else if(type=EnemyBullet)
				enemy.FireEnable=1;
			break;
		}
		switch(map[Pos[0]][Pos[1]])//子弹经过的MAP的标记
		{
			
		   case Empty://如果是空位置就绘制子弹
			    map[Pos[0]][Pos[1]]=type;
				SetPos((Pos[1]+1)*2,Pos[0]+1);
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
				cout<<"■";
			    break;
		   case Player://如果是玩家位置
			   if(type!=PlayerBullet)
			   {
			      player.Life--;//生命减少
				  if(player.Life<=0)
					 GameOver=1;
			    }
			    Updata();
			    hit=1;
			    break;
		   case Enemy://如果是敌人位置
			    if(type!=PlayerBullet)
					hit=1;
				else
				{
					hit=1;
					Kill++;
					if(Kill%20==0&&player.Life<5)//击杀数++
						player.Life++;
					if(enemy.Type==Red)//如果击杀红坦克
					{
						KillRed++;
						if(KillRed%10==0&&player.GetFire()<5)
							player.IncreaseFire();
					}
					if(enemy.Type==Green)///如果击杀绿坦克
					{
						KillGreen++;
						if(KillGreen%10==0&&player.GetSpeed()<5)
							player.IncreaseSpeed();
					}
					enemy.Redraw();//擦除敌人
					enemy.Life=0;//敌人死亡
				}
				Updata();
			   break;
		}
		oldx=Pos[0];
		oldy=Pos[1];
		if(direction==Up)//子弹移动
		   Pos[0]--;
	     else if(direction==Down)
	    	Pos[0]++;
	     else if(direction==Left)
	    	Pos[1]--;
	    else if(direction==Right)
	    	Pos[1]++;
		 ReleaseMutex(Mutex);
		 flag=1;
		 Sleep(60-10*Speed);
    }
	return 0;
}
开发者ID:PureMoonStudio,项目名称:Tools,代码行数:101,代码来源:源.cpp


注:本文中的Tank::Redraw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。