我们已经有了前三章的基础了,到了第四章,你会发现提示少之又少了。这时,我们大都要靠自己了!!!加油!!如果你没有思路,请仔细看下装备的说明,毕竟到了这关,你需要购买好多其他的新装备,而新装备中存在了新的函数方法。
记得:如果你觉得难,请再次打开时时代码补全功能。
注意:本关开始设计到其他人物,需要使用他们的特殊技能,这里在关卡的前面我会明确标注出来,若没有进行标注,则仍然使用开始的人物Anya Weston长官(战士)
命令召唤物执行动作的方法记录:
召唤方法记录:
英雄可以召唤的内容记录:
英雄可以使用的技能记录,法师职业:
激流回旋
# 使用对象枚举来走安全的路,并收集宝石。
# 在本关你不能够使用 moveXY()方法!使用 move()来移动
gems = hero.findItems()
while hero.pos.x < 20:
# move()移动物体通过 x 和 y 的属性,不仅仅是数字。
hero.move({'x': 20, 'y': 35})
while hero.pos.x < 25:
# 一个宝石的位置是一个对象,有 x 和 y 属性。
gem0 = gems[0]
hero.move(gem0.pos)
# 当你的 x 小于30的时候,
# 使用物体移动到30,35位置
while hero.pos.x < 30:
hero.move({'x': 30, 'y': 35})
# 当你的 x 小于35的时候
# 移动到宝石[1]的位置
while hero.pos.x < 35:
gem1 = gems[1]
hero.move(gem1.pos)
# 拿到最后一对宝石!
while hero.pos.x < 40:
hero.move({'x': 40, 'y':35})
while hero.pos.x < 45:
gem2 = gems[2]
hero.move(gem2.pos)
while hero.pos.x < 50:
hero.move({'x': 50, 'y':35})
while hero.pos.x < 60:
gem3 = gems[3]
hero.move(gem3.pos)
食人魔山谷挖宝
# 一大群食人魔到来之前,你只有20秒时间!
# 尽可能多捡金子,然后撤退到你的基地,筑好围栏!
while hero.time < 20:
# 收集金币
hero.say("我应该捡起硬币")
coins = hero.findItems()
coin = hero.findNearest(coins)
for coin in coins:
hero.moveXY(coin.pos.x, coin.pos.y)
if hero.gold > 60:
break
while hero.pos.x > 16:
# 撤退到围栏后面
hero.say("我应该撤退")
hero.moveXY(15, 37)
# 建立围栏,挡住食人魔。
hero.buildXY("fence", 21, 38)
黑钻石
while True:
gem = hero.findNearest(hero.findItems())
if gem:
clear = hero.isPathClear(hero.pos, gem.pos)
# isPathClear 方法告诉你是否有障碍物在路上
# 如果是通畅的,move()到 gem.pos (宝石的位置)
if clear:
hero.move(gem.pos)
# 否则的话,回到中心点。
else:
hero.move({"x":40, "y": 35})
宝藏洞穴
# 那个食人魔被秒杀了!最好是避开雪人。
# 5秒后我们会让火焰陷阱爆炸。
# 北面的空地是很好的爆炸引诱地点。
# 雪人不会一直被引开,所以快点偷硬币!
# 之后,跑回营地!
hero.buildXY("fire-trap", 64, 44)
while hero.time < 10:
hero.moveXY(44, 8)
hero.moveXY(20, 33)
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
hero.moveXY(72, 9)
调用复数方法
hero.buildXY("fire-trap", 64, 44)
while hero.time < 10:
hero.moveXY(44, 8)
hero.moveXY(20, 33)
coins = hero.findItems()
coin = hero.findNearest(coins)
if coin:
hero.move(coin.pos)
hero.moveXY(72, 9)
跳舞人生
# 和你的舞伴同步移动让 Pender Spellbane 印象深刻。
friends = hero.findFriends()
friend = hero.findNearest(friends)
disx = hero.pos.x - friend.pos.x
disy = hero.pos.y - friend.pos.y
while True:
x = friend.pos.x + disx
y = friend.pos.y + disy
hero.moveXY(x, y)
安息之云指挥官
# 召唤一些士兵,然后引导他们去你的基地。
# 每个士兵消耗20金币。
while hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
soldiers = hero.findFriends()
soldierIndex = 0
# 添加一个while 循环来命令所有的士兵。
while soldierIndex < len(soldiers):
soldier = soldiers[soldierIndex]
hero.command(soldier, "move", {"x": 50, "y": 40})
soldierIndex += 1
# 去加入你的朋友!
hero.moveXY(50, 40)
高山拉力
需要使用人物:Pender Spellbane(法师),之前的章节我们完成关卡使用的人物都是开始系统给与的默认Anya Weston长官(战士)。
注意了,这里系统给与的提示不好,上节我们好好的跳舞之后,让Pender Spellbane 印象深刻,我们获得了这个法师英雄,所以,这节我们需要使用这关英雄!!否则,你没有可以用通过要关卡要使用的技能。。。
另外,添加了好多的技能,不会用的话就仔细的看说明hero.spells。
# 逃离右边的地图
# 为了逃脱的雪人,你必须让自己跑得更快。
# 使用resetCooldown更频繁地使用咒语或技能
# manaBlast能帮我们清理道路
hero.cast("haste", hero)
hero.resetCooldown("haste")
hero.moveXY(109, 35)
hero.manaBlast()
hero.cast("haste", hero)
hero.resetCooldown("haste")
hero.moveXY(273, 36)
#hero.cast("chain-lightning", hero.findNearestEnemy())
佣兵山
我擦,记得注释掉英雄say的内容,耽误招兵和捡金币的时间,我的天。。
# 收集硬币招募士兵,并指挥他们攻击敌人。
while True:
# 移动到最近的硬币处。
# 使用 move 取代 moveXY,以便于不断发出命令。
coin = hero.findNearest(hero.findItems())
if coin:
hero.move(coin.pos)
#hero.say("我需要金币!")
# 如果钱够了就招募士兵。
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
#hero.say("我应该招募些帮手!")
#hero.summon("soldier")
enemy = hero.findNearest(hero.findEnemies())
if enemy:
soldiers = hero.findFriends()
soldierIndex = 0
# 遍历你所有的士兵,命令他们攻击。
while soldierIndex < len(soldiers):
# 使用'attack'命令,让你的士兵们发起攻击。
soldier = soldiers[soldierIndex]
soldierIndex += 1
hero.command(soldier, "attack", enemy)
木材守卫
while True:
# 收集金子
coin = hero.findNearest(hero.findItems())
hero.move(coin.pos)
# 如果你有足够的金币,召唤一个士兵。
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
# 使用 for 循环来命令每个士兵。
# for 循环有两个部分『for X in Y』
# Y 是被循环的数组结构
# Y 中的每个元素都会执行,X 会被设置称当前循环的个体
for friend in hero.findFriends():
if friend.type == "soldier":
enemy = friend.findNearestEnemy()
# 如果这有一个敌人,命令她攻击。
# 否则的话,移动她到地图的右边。
if enemy:
hero.command(friend, "attack", enemy)
else:
hero.command(friend, "move", {"x":97, "y":47})
零和(对战关卡)
# 在两分钟内击退敌人。
while True:
enemies = hero.findEnemies()
nearestEnemy = hero.findNearest(enemies)
#增加了捡金币的方法
coin = hero.findNearest(hero.findItems())
if coin:
hero.move(coin.pos)
# 你的英雄能收集金币并招募部队。
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
# 在站场上,她也可以命令你的盟友。
friends = hero.findFriends()
for friend in friends:
hero.command(friend, "attack", friend.findNearest(enemies))
# 使用你英雄的能力力挽狂澜。
if nearestEnemy:
hero.manaBlast()