极客战记 刚爪间隙攻略

本攻略可以获得奖励,关键点在求余(%),计算机称为模运算(%),本关卡主要的知识点在于通过模运算如何知道数组的位置,通过数组下标(index)的运用,关键是这句话 # 根据friendIndex使用%来环绕防卫点
DP=defendPoints[i%len(defendPoints)],翻译一直是被吐槽的对象,建议保留英文,才是更好的选择,还有一定要学好英语,不会可以问度娘

defendPoints = [{"x": 35, "y": 63},{"x": 61, "y": 63},{"x": 32, "y": 26},{"x": 64, "y": 26}]

summonTypes = ["soldier","soldier","soldier","soldier","archer","archer","archer","archer"]

# 你用360金开始建造一个士兵和弓箭手的混合体。
# Self.Bug是你曾经建造的一个部队数组。
# 在这里,我们使用"len(self.built) % len(summonTypes)"来环绕召唤类型数组。
def summonTroops():
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold >= hero.costOf(type):
        hero.summon(type)
    

def commandTroops():
    friends = hero.findFriends()
    for i in range(len(friends)):
        friend = friends[i]
        # 根据friendIndex使用%来环绕防卫点
        DP=defendPoints[i%len(defendPoints)]
        # 命令你的手下捍卫防卫点
        hero.command(friend, "defend",DP )
        enemy = friend.findNearestEnemy()
        if enemy:
            if friend.distanceTo(enemy) < 25:
                hero.command(friend, "attack", enemy)
        if friend.health < friend.maxHealth / 3:
            hero.command(friend, "move", {"x":50, "y":50})


while True:
    summonTroops()
    commandTroops()

猜你喜欢

转载自blog.csdn.net/weixin_42861040/article/details/85199957