level 2
# 你掉进陷阱里了!别动!你会受伤的!
# 这个函数检查敌人是否再攻击范围。
def inAttackRange(enemy):
distance = hero.distanceTo(enemy)
# Almost all swords have attack range of 3.
if distance <= 3:
return True
else:
return False
# Attack ogres only when they're within reach.
while True:
# 找到最近的敌人,并将其储存在一个变量中。
enemy = hero.findNearestEnemy()
# 调用 inAttackRange(enemy),将 enemy 作为参数
# 把结果保存于 “canAttack” 变量中
canAttack = inAttackRange(enemy)
# If the result stored in canAttack is True, 然后下手!
if canAttack:
hero.attack(enemy)
pass
2017年01月10日 14点01分
