韩顺平 java 坦克大战_HTML5坦克大战(韩顺平版本)

1 //定义敌人和我们自己的坦克的颜色2 var enemyColor = new Array("#0BB","#0FF");3 var heroColor = new Array("#dc0","#ff5");4 //封装一个公用的坦克父类5 functionTank(x,y,direct){6 this.x =x;7 this.y =y;8 this.speed = 3...
摘要由CSDN通过智能技术生成

1 //定义敌人和我们自己的坦克的颜色

2 var enemyColor = new Array("#0BB","#0FF");3 var heroColor = new Array("#dc0","#ff5");4 //封装一个公用的坦克父类

5 functionTank(x,y,direct){6 this.x =x;7 this.y =y;8 this.speed = 3;9 this.direct =direct;10 this.moveUp = function(){11 if (hero.y>0) {12 hero.y -=hero.speed;13 }14 hero.direct = 0;15 }16 this.moveRight = function(){17 if (hero.x+30<500) {18 hero.x +=hero.speed;19 }20 hero.direct = 1;21 }22 this.moveBottom = function(){23 if (hero.y+30<300) {24 hero.y +=hero.speed;25 }26 hero.direct = 2;27 }28 this.moveLeft = function(){29 if (hero.x>0) {30 hero.x -=hero.speed;31 }32 hero.direct = 3;33 }34 }35

36 //英雄坦克类

37 functionHero(x,y,direct,color){38 //将坦克类的构造方法赋给hero

39 this.hero =Tank;40 //调用,拥有坦克类的所有的属性和方法

41 this.hero(x,y,direct);42 this.color =color;43 this.direct =direct;44 this.isLive = true;45 this.shotEnemy = function(){46 switch(this.direct){47 case 0:48 heroBullet = new Bullet(this.x+9,this.y,this.direct);49 break;50 case 1:51 heroBullet = new Bullet(this.x+30,this.y+9,this.direct);52 break;53 case 2:54 heroBullet = new Bullet(this.x+9,this.y+30,this.direct);55 break;56 case 3:57 heroBullet = new Bullet(this.x,this.y+9,this.direct);58 break;59 }60 heroBullets.push(heroBullet);61 heroBullets[heroBullets.length-1].timer = window.setInterval("

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值