zoukankan      html  css  js  c++  java
  • 「网易官方」极客战记(codecombat)攻略-山峰-双生花-the-two-flowers

    (点击图片进入关卡)

    如果花匠死了,双生花将会凋零

    简介

    写一个 commandSoldiers 和一个 pickUpNearestCoin 函数使得在攻击中能存活下来。

    记住调用你在 while-true 循环中写入的函数。

    默认代码

    # 如果花匠受伤了,双生花会缩小!
    def summonSoldiers():
        if hero.gold >= hero.costOf("soldier"):
            hero.summon("soldier")
    # 定义函数:commandSoldiers
    # 定义函数:pickUpNearestCoin
    peasant = hero.findByType("peasant")[0]
    while True:
        summonSoldiers()
        # commandSoldiers()
        # pickUpNearestCoin()

    概览

    在这关里, 双生花和花匠之间互相连接着.

    如果花匠受伤了, 双生花会缩小.

    如果他没受伤, 花会生长. 如果双生花已经缩小到普通花朵的大小, 花匠会在被攻击时死亡.

    为了成功, 你需要补充 commandSoldiers 和 pickUpNearestCoin 函数的内容. 我们已经为你提供了函数 summonSoldiers , 让你记得怎么定义一个函数.

    当你准备好时,记得给循环里的函数取消注释!

    双生花解法

    # 如果花匠受伤了,双生花会缩小!
    def summonSoldiers():
        if hero.gold >= hero.costOf("soldier"):
            hero.summon("soldier")
    # 定义函数:commandSoldiers
    def commandSoldiers():
        for soldier in hero.findByType("soldier"):
            enemy = soldier.findNearestEnemy()
            if enemy:
                hero.command(soldier, "attack", enemy)
    # 定义函数:pickUpNearestCoin
    def pickUpNearestCoin():
        coin = hero.findNearest(hero.findItems())
        if coin:
            hero.move(coin.pos)
    peasant = hero.findByType("peasant")[0]
    while True:
        summonSoldiers()
        commandSoldiers()
        pickUpNearestCoin()
     
    本攻略发于极客战记官方教学栏目,原文地址为:
  • 相关阅读:
    从Ecma规范深入理解js中的this的指向
    js中继承的几种用法总结(apply,call,prototype)
    缓存 Array.length 是老生常谈的小优化
    spark app
    source code spark
    spark dev by IDEA
    编译spark-0.9.1
    图解GIT,ZT
    Spark分布式安装
    倒排索引(Inverted Index)
  • 原文地址:https://www.cnblogs.com/codecombat/p/13569648.html
Copyright © 2011-2022 走看看