Exemplo n.º 1
0
void Updata()//更新界面信息
{
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
	int i;
	SetPos(53,0);
	cout<<"生命值:";
	SetPos(53,1);
	for(i=0;i<5;i++)
	{
		if(i<player.Life)
			cout<<"■";
		else
			cout<<" ";
	}
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY| FOREGROUND_GREEN);
	SetPos(53,3);
	cout<<"移动速度:";
	SetPos(53,4);
	for(i=0;i<5;i++)
	{
		if(i<player.GetSpeed())
			cout<<"■";
		else
			cout<<" ";
	}
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY| FOREGROUND_RED);
	SetPos(53,5);
	cout<<"火力:";
	SetPos(53,6);
	for(i=0;i<5;i++)
	{
		if(i<player.GetFire())
			cout<<"■";
		else
			cout<<" ";
	}
    SetPos(53,8);
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
	cout<<"杀敌数:"<<Kill;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY| FOREGROUND_RED);
	SetPos(53,9);
	cout<<"杀死红坦克:"<<KillRed;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY| FOREGROUND_GREEN);
	SetPos(53,10);
	cout<<"杀死绿坦克:"<<KillGreen;

}
Exemplo n.º 2
0
/*********************子弹线程函数*******************/
DWORD WINAPI Bulletfly(LPVOID lpParameter)
{
	int *ID=(int *)lpParameter;//ID用来获取发射子弹坦克的ID
	int Pos[2];//子弹活动点
	int direction;
	int Speed;
	int type;
	int hit=0;//击中标记
	int oldx,oldy;//旧活动点
	int flag=0;//子弹是否有移动的标记
	if(*ID==Player)//如果是玩家坦克
	{
		type=PlayerBullet;
		direction=player.GetDirection();
		Speed=player.GetFire();
		Pos[0]=player.GetHotX();
		Pos[1]=player.GetHotY();
	}
    else if(*ID==Enemy)//如果是敌人坦克
	{
		type=EnemyBullet;
		direction=enemy.GetDirection();
		Speed=enemy.GetFire();
		Pos[0]=enemy.GetHotX();
		Pos[1]=enemy.GetHotY();
	}
	if(direction==Up)//根据坦克的位置和方向确定子弹的初始坐标
	{
		Pos[0]--;
		Pos[1]++;
	}
	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;
}