c 语言小游戏坦克大战,用c做的简单的坦克大战小游戏(给初学者点动力)

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

amy[i].fire.x=amy[i].x;

amy[i].fire.y=amy[i].y;

}

break;

}

}

if(lose)/*因为失败而跳出循环显示失败*/

{GameOver();break;}

if(GetKey(KEY_ESC))

break;

if(GetKey(KEY_UP))/*往上*/

{

if(Playone.direction==1&&map[Playone.x-1][Playone.y]!=1&&map[Playone.x-1][Playone.y]!=2)

{

if(map[Playone.x-1][Playone.y]==3)

continue;

DrawBlack(Playone.y,Playone.x);/*这个if是移动,前提是方向与按下的到向一致*/

Playone.x--;

Playone.direction=1;

DrawPlay(Playone.y,Playone.x);

}

else/*只调整炮头方向*/

{

DrawBlack(Playone.y,Playone.x);

Playone.direction=1;

DrawPlay(Playone.y,Playone.x);

}

}

else if(GetKey(KEY_DOWN))/*往下*/

{

if(Playone.direction==3&&map[Playone.x+1][Playone.y]!=1&&map[Playone.x+1][Playone.y]!=2)

{

if(map[Playone.x+1][Playone.y]==3)

continue;

DrawBlack(Playone.y,Playone.x);

Playone.x++;

Playone.direction=3;

DrawPlay(Playone.y,Playone.x);

}

else

{

DrawBlack(Playone.y,Playone.x);

Playone.direction=3;

DrawPlay(Playone.y,Playone.x);

}

}

if(GetKey(KEY_RIGHT))/*往右*/

{

if(Playone.direction==2&&map[Playone.x][Playone.y+1]!=1&&map[Playone.x][Playone.y+1]!=2)

{

if(map[Playone.x][Playone.y+1]==3)

continue;

DrawBlack(Playone.y,Playone.x);

Playone.y++;

Playone.direction=2;

DrawPlay(Playone.y,Playone.x);

}

else

{

DrawBlack(Playone.y,Playone.x);

Playone.direction=2;

DrawPlay(Playone.y,Playone.x);

}

}

if(GetKey(KEY_LEFT))/*往左*/

{

if(Playone.direction==4&&map[Playone.x][Playone.y-1]!=1&&map[Playone.x][Playone.y-1]!=2)

{

if(map[Playone.x][Playone.y-1]==3)

continue;

DrawBlack(Playone.y,Playone.x);

Playone.y--;

Playone.direction=4;

DrawPlay(Playone.y,Playone.x);

}

else

{

DrawBlack(Playone.y,Playone.x);

Playone.direction=4;

DrawPlay(Playone.y,Playone.x);

}

}

if(GetKey(KEY_SPACE))/*发射子弹*/

{

for(i=0;i<5;i++)/*用循环来找是否有子弹可以用*/

if(Playone.fire[i].direction<0)

{

sound(300);

Playone.fire[i].direction=Playone.direction;/*子弹方向与坦克方向一致*/

Playone.fire[i].x=Playone.x;

Playone.fire[i].y=Playone.y;

break;/*找到后就跳出循环*/

}

}

if(map[Playone.x][Playone.y]==5)/*玩家自己撞到老家*/

lose=1;

for(i=0;i<5;i++)/*判断是否因自己控制撞到敌人*/

{

if(amy[i].direction<0)

continue;

if(amy[i].x==Playone.x&&amy[i].y==Playone.y)/*相撞*/

lose=1;

}

if(lose)/*因为失败而跳出循环显示失败*/

{GameOver();break;}

t++;/*加到一定的程序就出现新的敌人*/

if(t==30) /*到了增加敌人的时候*/

{t=0;

for(i=0;i<5;i++)

if(amy[i].direction<0)

{

amy[i].direction=amy[i].directiontwo=3;

amy[i].x=1;

amy[i].y=random(3);/*方向随机*/

if(amy[i].y==0)

amy[i].y=1;

else if(amy[i].y==1)

amy[i].y=9;

else/*这里和上面的两个判断是判断敌人的初始位置*/

amy[i].y=18;

amy[i].color=random(3)+12;/*颜色随机*/

DrawAmy(amy[i].y,amy[i].x,i);

break;/*找到一个后就出循环*/

}

}

}

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值