zoukankan      html  css  js  c++  java
  • 「网易官方」极客战记(codecombat)攻略-山峰-猎手和猎物-hunters-and-prey

    (点击图片进入关卡)

    食人妖们在猎捕你的驯鹿。究竟是谁在猎杀谁呢?

    简介

    高效地指挥一组部队!

    弓箭手只能攻击距离小于比 25m 敌人。

    士兵应该攻击任何人。

    使用函数收集硬币。

    默认代码

    # 食人魔正试图除掉你的驯鹿!
    # 当召唤士兵进攻时,让弓箭手回来。
    def pickUpCoin():
        # 收集硬币。

     

        pass
    def summonTroops():
        # 如果你有黄金就召唤士兵。
        pass

     

    # 这个函数有一个名为士兵的参数。
    # 参数就像变量一样。
    # 调用函数时确定参数的值。
    def commandSoldier(soldier):
        # 士兵要攻击敌人。

     

        pass
    # 编写一个命令弓箭手的函数来告诉你的弓箭手怎么做!
    # 它应该有一个参数将表示在被调用时传递给函数的射手。
    # 弓箭手应该只攻击距离25米以内的敌人,否则原地待命。
    while True:
        pickUpCoin()
        summonTroops()
        friends = hero.findFriends()
        for friend in friends:
            if friend.type == "soldier":
                # 这位朋友将被分配给commandSoldier函数中的士兵变量
                commandSoldier(friend)
            elif friend.type == "archer":
                # 务必指挥你的弓箭手。

     

                pass

    概览

    如果你的弓箭手里你的驯鹿过远,食人妖就会在周围的山丘上伏击你的驯鹿。所以时刻保持弓箭手跟紧驯鹿。

    因此,你需要使用 command(archer, "move", archer.pos) 命令来控制弓箭手呆在原地。如果不这样,当你的弓箭手受到敌人进攻时会主动上前进攻敌人而不是呆在原地保护驯鹿。

    弓箭手的攻击范围是 25 米,如果敌人进入攻击范围,弓箭手就可以进行攻击。

    猎手和猎物解法

    # 食人魔正试图除掉你的驯鹿!
    # 当召唤士兵进攻时,让弓箭手回来。
    def pickUpCoin():
        # 收集硬币。
        coin = hero.findNearest(hero.findItems())
        if coin:
            hero.move(coin.pos)
    def summonTroops():
        # 如果你有黄金就召唤士兵。
        if hero.costOf('soldier') <= hero.gold:
            hero.summon('soldier')

     

    # 这个函数有一个名为士兵的参数。
    # 参数就像变量一样。
    # 调用函数时确定参数的值。
    def commandSoldier(soldier):
        # 士兵要攻击敌人。
        enemy = soldier.findNearestEnemy()
        if enemy:
            hero.command(soldier, "attack", enemy)
    # 编写一个命令弓箭手的函数来告诉你的弓箭手怎么做!
    # 它应该有一个参数将表示在被调用时传递给函数的射手。
    # 弓箭手应该只攻击距离25米以内的敌人,否则原地待命。
    def commandArcher(archer):
        enemy = archer.findNearestEnemy()
        if enemy and archer.distanceTo(enemy) < 25:
            hero.command(archer, "attack", enemy)
        else:
            hero.command(archer, "move", archer.pos)
    while True:
        pickUpCoin()
        summonTroops()
        friends = hero.findFriends()
        for friend in friends:
            if friend.type == "soldier":
                # 这位朋友将被分配给commandSoldier函数中的士兵变量
                commandSoldier(friend)
            elif friend.type == "archer":
                # 务必指挥你的弓箭手。
                commandArcher(friend)
     
    本攻略发于极客战记官方教学栏目,原文地址为:
  • 相关阅读:
    Maven实战(六)依赖
    Maven实战(五)坐标详解
    Maven实战(四)生命周期
    Maven实战(三)Eclipse构建Maven项目
    Maven实战(二)构建简单Maven项目
    Maven实战(一)安装与配置
    哈佛图书馆自习室墙上的训言——觉得为时已晚的时候,恰恰是最早的时候——不是缺乏时间,而是缺乏努力
    JQuery中国省市区无刷新三级联动查询
    思科VSS配置指南
    思科IS-IS多区域和汇总配置
  • 原文地址:https://www.cnblogs.com/codecombat/p/13569680.html
Copyright © 2011-2022 走看看