zoukankan      html  css  js  c++  java
  • 「网易官方」极客战记(codecombat)攻略-沙漠-炼金术的传承-continuous-alchemy

    (点击图片进入关卡)

    午夜过后不要给脱水的侦察兵供水。

    简介

    使用 continue 语句停止循环的当前迭代,并在下一个循环的开始处重新开始。

    while True:
        if not enemy:
            continue
        hero.say("我看见了一个敌人!")

    默认代码

    # 把 munchkins赶往Omarn Brewstone提制出来的水!
    # 使用 `continue`验证丛林中的条件。
    while True:
        enemy = hero.findNearestEnemy()
        item = hero.findNearestItem()

     

        # 如果没有敌人,跳出循环继续。
        if not enemy:
            continue

     

        # 如果有敌人却没物品,要一瓶药,跳到下次循环。
        if not item:
            hero.say("把喝的拿来!")
            continue

     

        # 使用 if 语句检查物品的类型。如果类型是 "poison",跳出循环继续运行。

     

        # 如果不是,那瓶子里装的是水,所以走向它,返回出发点!
        # 所以把XY移到魔药,然后回到开始!

    概览

    这关教你 continue 语句的使用方法。程序执行到 continue 时,这一轮循环就被跳过,继续下一轮循环。

    Omarn Brewstone 是个重要人物。需要留意有没有敌人埋伏,以及地面有没有什么东西。

    确保检查 item.type 避开毒药!

    Continue 可以和条件搭配跳过一块代码:

    while True:
        if not enemy:
            continue
        hero.say("我看见敌人了!")

    别让食人魔到达水源!喝水后他们会变得更强!

    炼金术的传承 解法

    # 把 munchkins赶往Omarn Brewstone提制出来的水!
    # 使用 `continue`验证丛林中的条件。
    while True:
        enemy = hero.findNearestEnemy()
        item = hero.findNearestItem()

     

        # 如果没有敌人,跳出循环继续。
        if not enemy:
            continue

     

        # 如果有敌人却没物品,要一瓶药,跳到下次循环。
        if not item:
            hero.say("把喝的拿来!")
            continue

     

        # 使用 if 语句检查物品的类型。如果类型是 "poison",跳出循环继续运行。
        if item.type is "poison":
            continue
        # 如果不是,那瓶子里装的是水,所以走向它,返回出发点!
        # 所以把XY移到魔药,然后回到开始!
        hero.moveXY(44, 35)
        hero.moveXY(34, 47)
     
    本攻略发于极客战记官方教学栏目,原文地址为:
     
     
  • 相关阅读:
    CompoundButton.OnCheckedChangeListener与RadioGroup.OnCheckedChangeListener冲突
    C# String.Format格式化json字符串中包含"{" "}"报错问题
    在IHttpHandler中获取session
    你真的会玩SQL吗?删除重复数据且只保留一条
    activity结束之后刷新之前的activity的内容
    jQuery打造智能提示插件二(可编辑下拉框)
    byte数组转float 以及byte转其他类型时为什么要&0xff
    为什么byte的取值范围是-128到127
    MySQL修改表、字段、库的字符集及字符集说明
    MySQL分布式jdbc连接
  • 原文地址:https://www.cnblogs.com/codecombat/p/13265229.html
Copyright © 2011-2022 走看看