块语言编程游戏 : 水战——游戏攻略

代码写的可能不是很好,可以帮我提出改进意见,有一两个bug,还不清楚为啥

鸭子属性:

闪避:90%

准度:60%

生命:80%

友好:0%

擅长进攻静止目标、远距离目标

游戏任务是通过编写JavaScript代码使鸭子检测敌鸭并发射炮弹击败敌鸭,让自己存活下来。

var cs1 = 270;
var health1 = health();
while(true){
  cs1 = shut();
  if(cs1 === Infinity || cs1 >= 720){  
    cs1 = 0;
  }
  move();
  avoid(health1);
  detect(loc_x(),loc_y(),false);
}
//移动函数
function move(){
  if(scan(cs1) > 30){ //判断与敌人距离大于30则快速接近
    swim(cs1,90);
  }
  stop();
  if(scan(cs1) <= 20){ //判断与敌人距离小于等于20则快速远离
    swim(-cs1,90);
  }
  else swim(cs1+90);  //围绕敌人转圈走位
}
//躲避函数:墙体、与敌人卡住和受伤检测
function detect(x,y,hurt){
  if (loc_x() < 10 || loc_x() > 90 ||
    loc_y() < 10 || loc_y() > 90) { //对靠近墙体进行检测,对四个角进行移动
    if (loc_x() < 10 && loc_y() < 50 ) {
      swim(80);
    }
    else if (loc_x() < 10 && loc_y() > 50) {
      swim(-10);
    }
    else if(loc_x() > 90 && loc_y() > 50){
      swim(260);
    }
    else if(loc_x() > 90 && loc_y() < 50){
      swim(160);
    }
    else if(loc_y() < 10 && loc_x() > 50){
      swim(80);
    }
    else if(loc_y() < 10 && loc_x() < 50){
      swim(160);
    }
    else if(loc_y() > 90 && loc_x() > 50){
      swim(-10);
    }
    else if(loc_y() > 90 && loc_x() < 50){
      swim(260);
    }
    else swim(270);
  }
  else if(hurt === true){ //受伤监测
    var angles1 = 0;
    while(speed()<45){  //速度监测,防止和敌人卡住
      swim(angles1);    
      if(Math.abs(loc_x() - x) < 5 && Math.abs(loc_y() - y) < 5){  //有效移动检测
        swim(angles1,90);
      }
      angles1 += 45;  //尝试往多个方向突围
    }
    angles1 = 0;
    // swim(cs1+90);
    
    
  }

}
//受击检测
function avoid(health1){
  var x = loc_x();
  var y = loc_y();
  if(health() < health1){
    health1 = health();
    detect(x,y,true);//受伤时进行躲避
  }
}
//射击函数精度20->10->5
function shut(){ 
  
  while(scan(cs1,20) > 70){ //围绕自身做20度的最高效率扫描敌人
    cs1 += 20;  //加20度 
    if(cs1===450){
      cs1=90; //防止溢出
    }
    detect(loc_x(),loc_y(),false); 
  }
  //扫描到后开始缩小范围
  if(scan(cs1-5,10) <= 70){  //右半区缩减为左右各为5的两个半区 
    if(scan(cs1-7.5,5) <= 70){//右半区缩减为左右各为2.5的两个半区
      cannon(cs1-7.5,scan(cs1-7.5,5)); //锁定目标,左右半区和为最小精度5
      cs1 -=7.5
      return cs1;
    }
    else if(scan(cs1-2.5,5) <= 70){//左半区缩减为左右各为2.5的两个半区
      cannon(cs1-2.5,scan(cs1-2.5,5));//锁定目标,左右半区和为最小精度5
      cs1 -= 2.5;
      return cs1;
    }
    else return cs1;
  }
  else if(scan(cs1+5,10) <= 70){  //左半区缩减为左右各为5的两个半区
    if(scan(cs1+2.5,5) <= 70){  //右半区缩减为左右各为2.5的两个半区
      cannon(cs1+2.5,scan(cs1+2.5,5));//锁定目标,左右半区和为最小精度5
      cs1 +=2.5;
      return cs1;
    }
    else if(scan(cs1+7.5,5) <= 70){  //左半区缩减为左右各为2.5的两个半区
      cannon(cs1+7.5,scan(cs1+7.5,5));//锁定目标,左右半区和为最小精度5
      cs1 +=7.5;
      return cs1;
    }
    else return cs1;
  }
  else return cs1;

}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zzl_Kevin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值