难度说明:
对一个有大概接触编程的人,
难度1:看提示能写好代码,并且通关。
难度2:需要在提示之外,加上一些已有提示的拓展。
难度3:单独看提示无法通关(需掌握其他函数之类的)。
难度4:在装备没有升级单靠逻辑无法战胜的敌人(需要装备)。
难度5:对于怎样子通关,完全没有头绪。
1、森林保卫战(#难度1)
# 建立两个围栏保护村民
# 把鼠标放在地图上得到X,Y坐标
hero.buildXY("fence", 40, 52)
hero.buildXY("fence", 40, 20)
(完全获取6个宝石 #难度2)
# 到小路的尽头去,并在那儿修一个栅栏。
# 利用你的 moveXY(x, y)坐标移动功能。
# It's the first point of the path.
hero.moveXY(36, 59)
# Move at the next points of the path.
hero.moveXY(37, 13)
hero.moveXY(72, 25)
hero.moveXY(37, 13)
hero.moveXY(6, 29)
hero.moveXY(9, 30)
hero.moveXY(11, 32)
hero.moveXY(60, 18)
# Build a fence to stop the ogre.
hero.buildXY("fence", 58, 21)
hero.buildXY("fence", 58, 17)
hero.moveXY(72, 62)
# 在丛林里头探索,但务必提高警觉!
# 这些丛林角落隔间可能会藏有ogres!
hero.moveXY(19, 33)
enemy = hero.findNearestEnemy()
# 条件判断式将会检查该变数是否参考到一个ogre
if enemy:
hero.attack(enemy)
hero.attack(enemy)
pass
hero.moveXY(49, 51)
enemy = hero.findNearestEnemy()
if enemy:
# 在这里撰写攻击敌人指令
hero.attack(enemy)
hero.attack(enemy)
# pass没有特别的意思,只是用来协助结束条件判断式,写不写都可以
pass
hero.moveXY(58, 14)
enemy = hero.findNearestEnemy()
# 使用条件判断式来确认敌人是否存在
if enemy:
# 如果敌人存在就攻击他
hero.attack(enemy)
hero.attack(enemy)
# 消灭从他们自己的营地里出来的食人魔
while True:
enemy = hero.findNearestEnemy()
# 使用一个 “if” 语句去检查是否有敌人存在:
if enemy:
# 攻击敌人如果它存在的话
hero.attack(enemy)
5、背靠背 (#难度10)
# 呆在中间防守!
while True:
enemy = hero.findNearestEnemy()
if enemy:
# 亦或主动出击...
hero.attack(enemy)
pass
else:
# 亦或回到你的阵地防守。
hero.moveXY(39, 33)
pass
6、森林劈裂者(#难度1)
# 尽可能经常使用你的新技能“cleave”
hero.moveXY(23, 23)
while True:
enemy = hero.findNearestEnemy()
if hero.isReady("cleave"):
# “Cleave”掉敌人!
hero.cleave(enemy)
pass
else:
# 否则(如果“cleave”还没准备好),就用你的普通攻击
hero.attack(enemy)
pass
7、边远地区的对峙(#难度1)
# 这些曼切堪食人魔害怕英雄!
# 说些什么,他们会吓得往后退。
# 但是,有足够的曼切堪食人魔,他们将联合起来伏击你!小心!
# 每当`cleave`(横劈)冷却时间完成,立即用它清除敌人。
while True:
# 使用 ‘isReady’ 中的一个 “if-statement” 的语句来检查 “cleave”
enemy = hero.findNearestEnemy()
if hero.isReady("cleave"):
# 劈斩!
hero.cleave(enemy)
# 或者,如果 cleave 还没准备好的话:
hero.say("Hello,World!")
# 说一点什么来吓走曼切堪食人魔
pass
8、测距仪(#难度1)
#distance返回的值为一个数值,并非坐标。
# 瘦人正在森林里头巡逻!
# 使用distanceTo方法来计算敌人与英雄间的距离
# 说出每个敌人和英雄间的距离以告知大砲要轰炸哪里
enemy1 = "Gort"
distance1 = hero.distanceTo(enemy1)
hero.say(distance1)
enemy2 = "Smasher"
distance2 = hero.distanceTo(enemy2)
# 将distance2变数作为参数,传入say()方法
hero.say(distance2)
# 测量并说出剩余敌人与英雄间的距离
# 不要向你的友军进行射击!
"""enemy3 = "Charles"
distance3 = hero.distanceTo(enemy3)
hero.say(distance3)"""
#以上是友军
enemy4 = "Gorgnub"
distance4 = hero.distanceTo(enemy4)
hero.say(distance4)
9、保护农民(#难度1)
while True:
enemy = hero.findNearestEnemy()
distance = hero.distanceTo(enemy)
if distance < 10:
# 如果他们与农民太近,就攻击他们
hero.attack(enemy)
pass
# 否则的话,呆在农民旁边!
else:
hero.moveXY(40,36)
10、疯狂的食人魔(#难度1)
# 地上另一个让英雄打开的宝箱!
# 攻击宝箱以打开它
# 有些食人魔可不会呆呆地站着挨打!
# 当食人魔离你太近时,你得学着保护你自己
while True:
enemy = hero.findNearestEnemy()
distance = hero.distanceTo(enemy)
if hero.isReady("cleave"):
# 首先,定期使用旋风斩(cleave)当技能就绪的时候:
hero.cleave(enemy)
pass
elif distance < 5:
# 攻击靠近并离你最近的食人魔
hero.attack(enemy)
pass
else:
# 否则,试着打破宝箱看看:
hero.attack("Chest")
pass