zoukankan      html  css  js  c++  java
  • 「网易官方」极客战记(codecombat)攻略-沙漠-Sarven 牧羊人-sarven-shepherd

    (点击图片进入关卡)

    从食人魔手中保护绿洲。

    简介

    使用 “while” 循环来检查 “敌人” 阵列。 如果它的类型不是 `沙牦牛' ,攻击敌人!

    默认代码

    # 使用 while 循环来对付食人魔。
    while True:
        enemies = hero.findEnemies()
        enemyIndex = 0
        # 将攻击逻辑放到 while 循环里来攻击所有的敌人。
        # 查找数组的长度: len(enemies)
        enemy = enemies[enemyIndex]
        # "!=" 意思是 "不等于"
        if enemy.type != "sand-yak":
            # 当敌人的健康值大于0,攻击它!

     

            pass
        # 在两波敌人之间,移动回中央。

    概览

    使用 while 迭代数组 enemies :

    while enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        if enemy.type != "sand-yak":
            # 当敌人的生命值大于 0 时攻击
        enemyIndex += 1

    攻击时,使用 while 和这个条件: enemy.health 大于 0 ,确保敌人被击败前一直攻击。

    提示: moveXY() 命令应该在 while enemyIndex 循环的 后面 (外面),但 在 while-true 主循环的 里面 。

    Sarven 牧羊人解法

    # 使用 while 循环来对付食人魔。
    while True:
        enemies = hero.findEnemies()
        enemyIndex = 0
        # 将攻击逻辑放到 while 循环里来攻击所有的敌人。
        # 查找数组的长度: len(enemies)
        while enemyIndex < len(enemies):
            enemy = enemies[enemyIndex]
            # "!=" 意思是 "不等于"
            if enemy.type != "sand-yak":
                # 当敌人的健康值大于0,攻击它!
                while enemy.health > 0:
                    hero.attack(enemy)
            enemyIndex += 1
        # 在两波敌人之间,移动回中央。
        hero.moveXY(40, 32)
     
    本攻略发于极客战记官方教学栏目,原文地址为:
  • 相关阅读:
    场景法设计测试用例
    编写边界条件测试用例原则
    CSS
    JavaScript
    HTML
    lamp安装教程
    Linux(lamp安装)
    oracle sqlplus常用命令
    利用同步器实现互斥锁
    工厂模式--简单工厂模式
  • 原文地址:https://www.cnblogs.com/codecombat/p/13403495.html
Copyright © 2011-2022 走看看