本文整理汇总了C++中Tank::GetHotY方法的典型用法代码示例。如果您正苦于以下问题:C++ Tank::GetHotY方法的具体用法?C++ Tank::GetHotY怎么用?C++ Tank::GetHotY使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tank
的用法示例。
在下文中一共展示了Tank::GetHotY方法的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: Bulletfly
/*********************子弹线程函数*******************/
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++;
//.........这里部分代码省略.........