CodeCombat_Mountain 参考答案 code by Python

这篇博客介绍了 CodeCombat 游戏中的 '安息之云山峰' 关卡,包括 '借刀'、'双生花' 和 '山花林' 三个子任务的解决方案,提供了 Python 编程语言的解答思路和链接。
部署运行你感兴趣的模型镜像

mountain 安息之云山峰

borrowed-sword 借刀

https://codecombat.com/play/level/borrowed-sword?

  1. Solution a
while True:
    friends = hero.findFriends()
    for i in range(len(friends)):
        friend = friends[i]
        target = None
        maxHealth = 0
        enemyIndex = 0
        enemies = hero.findEnemies()
        while enemyIndex < len(enemies):
            enemy = enemies[enemyIndex]
            if enemy.health > maxHealth:
                maxHealth = enemy.health
                target = enemy
            enemyIndex +=  1
        if target:
            hero.command(friend, "attack", target)
  1. Solution b
while True:
    enemies = hero.findEnemies()
    highestHp = None 
    bestHealth= 0
    for enemy in enemies:
        if enemy.health > bestHealth:
            highestHp = enemy
            bestHealth = enemy.health
    for friend in hero.findFriends():
        hero.command(friend, "attack", highestHp)

the-two-flowers 双生花

https://codecombat.com/play/level/the-two-flowers?

  1. Solution a
# 如果花匠受伤了,双生花会缩小!

def summonSoldiers():
    if hero.gold >= hero.costOf("soldier"):
        hero.summon("soldier")

# 定义函数:commandSoldiers
def commandSoldiers():
    emeny = hero.findNearestEnemy()
    soldiers = hero.findByType("soldier")
    for index in range(len(soldiers)):
        nearnestEnemy = soldiers[index].findNearestEnemy()
        hero.command(soldiers[index], "attack", nearnestEnemy)

    
# 定义函数:pickUpNearestCoin
def pickUpNearestCoin():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)
peasant = hero.findByType("peasant")[0]

while True:
    summonSoldiers()
    commandSoldiers()
    pickUpNearestCoin()

  1. Solution b
def summonSoldiers():
    if hero.gold >= hero.costOf("soldier"):
        hero.summon("soldier")

def commandSoldiers():
    friends = hero.findByType("soldier")
    for friend in friends:
        enemy = friend.findNearestEnemy()
        if enemy:
            hero.command(friend, "attack", enemy)

def pickUpNearestCoin():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)

peasant = hero.findByType("peasant")[0]

while True:
    summonSoldiers()
    commandSoldiers()
    pickUpNearestCoin()

mountain-flower-grove 山花林

https://codecombat.com/play/level/mountain-flower-grove?

  1. Solution a
#螺旋线的画法
def drawCircle(xo,yo,a,b,z):
    i = 0
    hero.toggleFlowers(False)
    while i <= z*2*Math.PI:
        r = a + b * i
        newx = xo + r * Math.cos(i)
        newy = yo + r * Math.sin(i)
        hero.moveXY(newx, newy)
        hero.toggleFlowers(True)
        i += 0.2

drawCircle(85,70,1,1,5)

您可能感兴趣的与本文相关的镜像

Python3.9

Python3.9

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值