11、跃火林中
# 在这关,别碰恶魔石!往其他方向移动避开它们!
while True:
evilstone = hero.findNearestItem()
if evilstone:
pos = evilstone.pos
if pos.x == 46:
# 如果恶魔石在右边,走到左边。
hero.moveXY(34, 22)
pass
else:
# 如果恶魔石在左边,走到左边。
hero.moveXY(46, 22)
pass
else:
# If there's no evilstone, go to the middle.
hero.moveXY(40, 22)
pass
这关的提示有一个地方错误了
12、村庄漫游者
这关有开始定义函数
# This defines a function called findAndAttackEnemy
def findAndAttackEnemy():
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
# This code is not part of the function.
while True:
# Now you can patrol the village using findAndAttackEnemy
hero.moveXY(35, 34)
findAndAttackEnemy()
# Now move to the right entrance.
hero.moveXY(60,31)

本文介绍了CodeCombat游戏中的Python编程挑战,包括'跃火林中'和'村庄漫游者'两个关卡,特别强调了开始定义函数的运用,虽然遇到困难,但最终完成了挑战。
最低0.47元/天 解锁文章
4万+

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



