【网易官方】极客战记(codecombat)攻略-森林-边地炮兵军士backwoods-bombardier

结合坐标,更好地发挥炮兵的威力。

简介

敌人(和英雄!)拥有代表他们位置的 pos 属性。

pos 属性本身有两个属性: x 和 y ,它们是浮点(十进制)数字:

pos = enemy.pos
x = pos.x
y = pos.y

默认代码

# pos属性是一个具有x和y属性的对象。
# pos.x是代表地图上水平位置的数字
# pos.y是代表地图上垂直位置的数字
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        x = enemy.pos.x
        # 得到敌人的y位置!
        y = 0 # ∆ 改变这个!

 

        # 说x和y的位置用逗号隔开
        hero.say(x + "," + y)
    else:
        hero.say("停止" + " " + "开火!")

概览

敌人(和英雄!)拥有代表他们位置的 pos 属性。

pos 属性本身有两个属性: x 和 y ,它们是浮点(十进制)数字:

pos = enemy.pos
x = pos.x
y = pos.y
hero.say(x + "," + y)

X 代表敌人的 horizontal 位置。

Y 代表敌人的 vertical 位置。

边地炮兵军士 解法

# pos属性是一个具有x和y属性的对象。
# pos.x是代表地图上水平位置的数字
# pos.y是代表地图上垂直位置的数字
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        x = enemy.pos.x
        y = enemy.pos.y
        # 说x和y的位置用逗号隔开
        hero.say(x + "," + y)
    else:
        hero.say("停止" + " " + "开火!")
 
 
 
本攻略发于极客战记官方教学栏目,原文地址为:
原文地址:https://www.cnblogs.com/codecombat/p/12324796.html