
(点击图片进入关卡)
什么玩意惊动了牦牛们!!跑!用尽吃奶的力气!快跑!
简介
啊哦,快逃! 移动躲避那些恐怖的牦牛!
对于躲避牦牛生存下来有一些简单的规则:
- 保持向右移动: hero.pos.x + 5
- 当牦牛在你的上面时,在你的y坐标上减去3( enemy.pos.y > hero.pos.y )
- 当牦牛在你的上面时,在你的y坐标上加上3( enemy.pos.y < hero.pos.y )
默认代码
# 继续往前走,但你要上下左右调整。
while True:
enemy = hero.findNearestEnemy()
xPos = hero.pos.x + 5
yPos = 17
if enemy:
# 调整y值,使其向上或向下以摆脱牦牛。
if enemy.pos.y > hero.pos.y:
# 如果牦牛在你上面,从yPos中减去3。
pass
elif enemy.pos.y < hero.pos.y:
# 如果牦牛在你下面,给yPos加上3。
pass
hero.moveXY(xPos, yPos)
概览
记住‘Y’控制一个单位在游戏地图上能移动多长的距离。
低的数字更低。高的数字更高,
所以如果 enemy.pos.y 大于 hero.pos.y ,那么这个敌人就是在英雄的上方 。
在这种情况下,这意味着英雄需要通过减去 yPos 来向下移动逃离敌人。
如果 enemy.pos.y 小于 hero.pos.y ,那么这个敌人就是英雄的上方。 所以英雄要加上 yPos 通过向下移动来逃脱。
盆地逃亡 解法
# 继续往前走,但你要上下左右调整。
while True:
enemy = hero.findNearestEnemy()
xPos = hero.pos.x + 5
yPos = 17
if enemy:
# 调整y值,使其向上或向下以摆脱牦牛。
if enemy.pos.y > hero.pos.y:
# 如果牦牛在你上面,从yPos中减去3。
yPos = yPos-3
pass
elif enemy.pos.y < hero.pos.y:
# 如果牦牛在你下面,给yPos加上3。
yPos = yPos+3
pass
hero.moveXY(xPos, yPos)
「网易官方」极客战记(codecombat)攻略-沙-_盆地逃亡-basin-stampede
原文:https://www.cnblogs.com/codecombat/p/13131527.html