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)
     
    本攻略发于极客战记官方教学栏目,原文地址为:
     
     
  • 相关阅读:
    Ubuntu-14.04-QT开发环境搭建-(一)
    解决使用Qt creator时出现Cannot overwrite file ..Permission denied
    Github上关于大数据的开源项目、论文等合集
    Qt5.4中遇到找不到头文件<QApplication>等。
    qt的下载地址
    完整的qt安装教程
    Ubuntu14.04安装Matlab2014a
    Ubuntu14.04安装搜狗输入法的一点小问题
    把OnDraw和OnPaint弄清楚(转贴)
    Ubuntu上挂载源代码,docker容器中共享这个原代码,实现自动部署
  • 原文地址:https://www.cnblogs.com/codecombat/p/13265229.html
Copyright © 2011-2022 走看看