本文整理汇总了C++中Tank::Judge方法的典型用法代码示例。如果您正苦于以下问题:C++ Tank::Judge方法的具体用法?C++ Tank::Judge怎么用?C++ Tank::Judge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tank
的用法示例。
在下文中一共展示了Tank::Judge方法的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;
}
//.........这里部分代码省略.........
示例2: TankRuning
/*************************敌人线程函数***************************/
DWORD WINAPI TankRuning(LPVOID lpParameter)
{
Sleep(400);
int Pos;
int Start[2];//敌人起始地址
int typ;
int fire;
int spe;
while(1)
{
if(GameOver==1)
return 0;
srand((int)time(0));//随机出敌人起始地址
Pos=rand()%4;
if(Pos==0)
{
Start[0]=2;
Start[0]=2;
}
else if(Pos==1)
{
Start[0]=2;
Start[1]=18;
}
else if(Pos==2)
{
Start[0]=18;
Start[1]=2;
}
else if(Pos==3)
{
Start[0]=18;
Start[1]=18;
}
if(player.Judge(Start[0],Start[1],Down)==0)
break;
}
WaitForSingleObject(Mutex,INFINITE);
srand((int)time(0));
typ=rand()%3+1;//随机出敌人的种类
if(typ==Blue)
{
spe=1+level;
fire=1+level;
}
else if(typ==Red)
{
spe=1+level;
fire=3+level;
}
else if(typ==Green)
{
spe=3+level;
fire=1+level;
}
enemy=Tank(Down,Start[0],Start[1],typ,spe,fire);//重新生成敌人坦克
enemy.ID=Enemy;
enemy.Life=1;
enemy.FireEnable=1;
ReleaseMutex(Mutex);
enemy.Running();
return 0;
}