【网易官方】极客战记(codecombat)攻略-森林-有用的对手useful-competitors

战场上满是硬币和毒药。 使用 peons 过滤毒药并收集硬币!

简介

检查物品的 type ,确保英雄没捡到 "poison" (毒药)。

默认代码

# 这片金币地中暗藏了致命的毒药。
# 兽人正在进攻,而苦力尝试偷你的金币!
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        # 只在敌人类型不是 "peon" 的时候攻击。
        if enemy.type != "peon":
            hero.attack(enemy)
        item = hero.findNearestItem()
        if item:
            # 只在物品的类型不是 "poison" 的时候收集。

 

        pass

概览

在这关你需要用到 非(not) 操作符筛选敌人和物品!

非(not) 取一个值的逻辑相反 (logical inverse) 然后返回:

# 非(Not) 在 Python 里写作: "not".
hero.say(not False) # The hero says 'True'
hero.say(not True) # The hero says 'False'

在条件中使用可以这样:

if not hero.isReady('cleave'):
    # 在 cleave 还在冷却时做点啥
else:
    # Cleave 准备好啦。

有用的对手 解法

# 这片金币地中暗藏了致命的毒药。
# 兽人正在进攻,而苦力尝试偷你的金币!
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        # 只在敌人类型不是 "peon" 的时候攻击。
        if enemy.type != "peon":
            hero.attack(enemy)
        item = hero.findNearestItem()
        if item:
            # 只在物品的类型不是 "poison" 的时候收集。
            if item.type != "poison":
                hero.moveXY(item.pos.x, item.pos.y)
 
 
本攻略发于极客战记官方教学栏目,原文地址为:
原文地址:https://www.cnblogs.com/codecombat/p/12360110.html