码迷,mamicode.com
首页 > 其他好文 > 详细

codecombat 严峻的决心

时间:2016-12-28 19:21:42      阅读:364      评论:0      收藏:0      [点我收藏+]

标签:codecombat

# 你的目标是保护 Reynaldo

# 找到生命值最低的武士
def lowestHealthPaladin():
    lowestHealth = 99999
    lowestFriend = None
    friends = hero.findFriends()
    for friend in friends:
        if friend.type != "paladin":
            continue
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend

    return lowestFriend

def commandPeasant(peasant):
    item = peasant.findNearestItem()
    if item:
        hero.command(peasant, "move", item.pos)

def commandGriffin(griffin):
    target = hero.findNearest(hero.findByType(‘warlock‘))
    if target:
        hero.command(griffin, "attack", target)
    else:
        target = griffin.findNearestEnemy()

def commandPaladin(paladin):
    # 使用函数 lowestHealthPaladin() 找到生命值最低的武士,并治疗
    # 你能使用 paladin.canCast("heal") 和 command(paladin, "cast", "heal", target)
    # 武士也能防御:command(paladin, "shield")
    # 不要忘了他们还能攻击
    target = hero.findNearest(hero.findByType(‘warlock‘))
    if paladin.health < 250:
        hero.command(paladin, "shield")
    else:
        if paladin.canCast("heal"):
            healtarget = lowestHealthPaladin()
            # and healtarget and healtarget.health < 400:
            if healtarget:
                hero.command(paladin, "cast", "heal", healtarget)
        
        else:
            target = paladin.findNearestEnemy()
            hero.command(paladin, "attack", target)
            


def commandFriends():
    # 指挥你的队友
    friends = hero.findFriends()
    for friend in friends:
        if friend.type == "peasant":
            commandPeasant(friend)
            
        if friend.type == "griffin-rider":
            commandGriffin(friend)
            
        if friend.type == "paladin":
            commandPaladin(friend)

while True:
    commandFriends()
    # 召唤 格里芬骑士
    if hero.gold >= hero.costOf("griffin-rider"):
        hero.summon("griffin-rider")


本文出自 “运维新手” 博客,请务必保留此出处http://67263992.blog.51cto.com/3718090/1886941

codecombat 严峻的决心

标签:codecombat

原文地址:http://67263992.blog.51cto.com/3718090/1886941

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!