求助。。
codecombat吧
全部回复
仅看楼主
level 2
soul沐_ 楼主
我怎么看都不知道哪里写错了。。
2015年08月08日 13点08分 1
level 1
看不太清。不过显然是 item . pos 是不对的。 item = this.findNearestItem() 这样item.pos才有效
2015年08月08日 16点08分 2
哦。。。这是为啥呢。。
2015年08月08日 23点08分
是因为用finditems会没法分辨么
2015年08月08日 23点08分
level 2
soul沐_ 楼主
2015年08月08日 23点08分 3
level 12
findItems返回的是物品的*数组*,而不是单个物品,简单点可以用findNearest找出数组里和你的距离最近的对象。
另外还要注意,findItems有可能返回一个*空的*数组,所以在下一步之前要检查一下是不是为空(if 数组名)
2015年08月09日 12点08分 4
谢谢[真棒]
2015年08月09日 13点08分
level 3
@huangkuan1214 我修改了一下
// 使用你的新技能来选择你要做什么 this.now()
loop {
// 如果是头十秒,进攻。
var enemy =this.findNearest(this.findEnemies());
if (this.now() < 10) {
if (enemy) {
if (this.isReady("cleave")) {
this.cleave(enemy);
}
else {
this.attack(enemy);
this.attack(enemy);
}
}
}
else if (this.now() < 30) {
var item = this.findNearest(this.findItems());
var x = item.pos.x ;
var y = item.pos.y ;
this.moveXY(x, y);
}
// 否则的话,如果是前30秒,收集金币。
// 后30秒,加入救助。
else if (enemy) {
if (this.isReady("bash")) {
this.bash(enemy);
}
if (this.isReady("cleave")) {
this.cleave(enemy);
}
else {
this.attack(enemy);
}
}
if (this.health<this.maxHealth/2){
this.moveXY(this.pos.x-10, y-5);
}
}
2015年11月08日 17点11分 6
1