zoukankan      html  css  js  c++  java
  • 「网易官方」极客战记(codecombat)攻略-山峰-动物园管理员-zoo-keeper

    (点击图片进入关卡)

    保护雪人的笼子免遭食人魔的蓄意破坏。

    简介

    不要让食人魔打开盒子!

    默认代码

    # 保护笼子。
    # 放一个士兵在每一个 X 的位置
    points = []
    points[0] = {"x": 33, "y": 42}
    points[1] = {"x": 47, "y": 42}
    points[2] = {"x": 33, "y": 26}
    points[3] = {"x": 47, "y": 26}
    # 1.收集80金币。
    # 2.建造4个士兵。
    for i in range(4):
        hero.summon("soldier")

     

    # 3.派你的士兵到特定的位置上。
    while True:
        friends = hero.findFriends()
        for j in range(len(friends)):
            point = points[j]
            friend = friends[j]
            enemy = friend.findNearestEnemy()
            if enemy and enemy.team == "ogres" and friend.distanceTo(enemy) < 5:
                # 命令友方攻击。
                pass

     

            else:
                # 命令的朋友移动到特定点上。
                pass

    概览

    这个关卡显示了如何在 for 循环中使用一系列数字来访问多个相关数组。

    你还会看到如何让士兵保卫某个地点。

    收集硬币时,可以停在 80,因为每个士兵的费用为 20。

    动物园管理员解法

    # 保护笼子。
    # 放一个士兵在每一个 X 的位置
    points = []
    points[0] = {"x": 33, "y": 42}
    points[1] = {"x": 47, "y": 42}
    points[2] = {"x": 33, "y": 26}
    points[3] = {"x": 47, "y": 26}
    # 1.收集80金币。
    while hero.gold < 80:
        coin = hero.findNearest(hero.findItems())
        if coin:
            hero.move(coin.pos)
    # 2.建造4个士兵。
    for i in range(4):
        hero.summon("soldier")

     

    # 3.派你的士兵到特定的位置上。
    while True:
        friends = hero.findFriends()
        for j in range(len(friends)):
            point = points[j]
            friend = friends[j]
            enemy = friend.findNearestEnemy()
            if enemy and enemy.team == "ogres" and friend.distanceTo(enemy) < 5:
                # 命令友方攻击。
                hero.command(friend, "attack", enemy)

     

            else:
                # 命令的朋友移动到特定点上。
                hero.command(friend, "move", point)
     
    本攻略发于极客战记官方教学栏目,原文地址为:
  • 相关阅读:
    异常处理
    PAT——1048. 数字加密
    PAT——1047. 编程团体赛
    PAT——1046. 划拳
    PAT——1045. 快速排序(25)
    PAT——1044. 火星数字
    PAT——1043. 输出PATest
    PAT——1042. 字符统计
    PAT——1041. 考试座位号
    PAT——1040. 有几个PAT
  • 原文地址:https://www.cnblogs.com/codecombat/p/13563393.html
Copyright © 2011-2022 走看看