请问这关怎么过。
codecombat吧
全部回复
仅看楼主
level 2
boo6786733 楼主
不知道怎么用语句
2015年01月06日 02点01分 1
level 2
boo6786733 楼主
loop { var yak = this.findNearestEnemy();
if (yak) {
var pos=yak.pos;
var yakX=pos.x;
var yakY=pos.y;
// A yak is above you if it's y is greater than your y.
// If the yak is above you, build a fence 10m below it.
// If the yak is below you, build a fence 10m above it.
var newX=this.pos.x;
var newY=this.pos.y;
if(yakY>newY){this.buildXY("fence",newX,newY+1);}
if(yakY<newY){this.buildXY("fence",newX,newY-1);}
} else
{
// Move right 10m towards the oasis.
var x=this.pos.x+10;
var y=this.pos.y;
this.moveXY(x,y);
}
}
2015年01月06日 09点01分 2
level 1
python写法,思路差不多呗
# Get to the oasis,
# fencing off paths with yaks on them as you go.
loop:
yak = self.findNearestEnemy()
if yak:
yakpos = yak.pos
yakx = yakpos.x
yaky = yakpos.y
# If the yak is above you, build a fence 10m below it.
if self.pos.y<yaky :
self.buildXY("fence", yakx, yaky-10)
# If the yak is below you, build a fence 10m above it.
if self.pos.y>yaky :
self.buildXY("fence", yakx, yaky+10)
pass
else:
# Move right 10m towards the oasis.
self.moveXY(self.pos.x+10, self.pos.y)
pass
2015年02月09日 13点02分 3
1