code-combat Python 参考答案
mountain 安息之云山峰
borrowed-sword 借刀
https://codecombat.com/play/level/borrowed-sword?
- 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)
- 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?
- 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()
- 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?
- 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)

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

被折叠的 条评论
为什么被折叠?



