诱饵钻探
新的装备,新的开始,按提示购买即可。
# 我们在测试一个新的战斗单位:诱饵(decoy)。
# 建造4个诱饵,然后汇报总数给Naria。
decoysBuilt = 0
while True:
coin = hero.findNearestItem()
if coin:
# 收集硬币!
hero.moveXY(coin.pos.x, coin.pos.y)
# 每个诱饵消费25金。
# 如果hero.gold大于或等于25:
if hero.gold >= 25:
# 用buildXY建造一个"decoy"
hero.buildXY("decoy", hero.pos.x, hero.pos.y)
# 为decoysBuilt计数值加1。
decoysBuilt += 1
if decoysBuilt == 4:
# 建造了4个诱饵后跳出循环。
break
hero.say("完成诱饵建造!")
hero.moveXY(14, 36)
# 说出你建造了多少诱饵。
hero.say("I have builted " + decoysBuilt + " decoy!!")
守书人
为了使用起来方便,我这里定义了一个收集金币并报告金币数量的方法,你可以自行按照你的意愿来编写代码。
# This function allows to fight until the certain time
# and report about defeated enemies.
def fightAndReport(untilTime):
defeated = 0
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
if enemy.health <= 0:
defeated += 1
if hero.time > untilTime:
break
hero.moveXY(59, 33)
hero.say(defeated)
def colCoin(untilTime):
while True:
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
if hero.time > untilTime:
break
hero.moveXY(59, 33)
hero.say(hero.gold)
#fightAndReport(untilTime)
# Fight 15 seconds and tell Naria how many enemies you defeated.
fightAndReport(15)
# Collect coins until the clock reaches 30 seconds.
colCoin(30)
# Fight enemies until the clock reaches 45 seconds.
fightAndReport(45)
Sarven前哨基地
只要装备好,一刀一个小朋友
# 怪物正在攻击附近的前哨基地!
# 指挥英雄保卫定居点。
# 巡逻时带上你的手表,没有食人魔可以通过。
while True:
polarPos = hero.time / 4
# 数在20到60之间。
xPos = 40 + Math.cos(polarPos) * 20
# 数在14到54之间。
yPos = 34 + Math.sin(polarPos) * 20
hero.moveXY(xPos, yPos)
# 寻找食人魔并打败他们!
# 当他们的健康在0以上时,确保进行攻击。
enemy = hero.findNearestEnemy()
if enemy and enemy.health >= 0:
hero.attack(enemy)
吸引牦牛
# 保护 Brandy 免受口渴耗牛的冲击!
# 收集金币来建造干扰耗牛的诱饵。
# 使用flag来决定什么时候在哪里建造诱饵。
while True:
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
flag = hero.findFlag()
if flag:
hero.pickUpFlag(flag)
if hero.gold >= 25:
hero.buildXY("decoy", flag.pos.x, flag.pos.y)
炼金术传承
# 和食人魔矮人抢Omarn Brewstone提取出的水!
# 使用`continue`语句避开毒药。
while True:
enemy = hero.findNearestEnemy()
item = hero.findNearestItem()
# 如果没有敌人,使用continue跳出此轮循环继续运行。
if not enemy:
continue
# 如果没有物品,要一瓶药水,然后continue。
if not item:
hero.say("给我点喝的!")
continue
# 如果item.type是"poison",使用continue跳出此轮循环继续运行。
if item.type == "poison":
continue
# 此时,药水必须是一瓶水
# 使用moveXY移到药水,然后回到开始!
if item:
hero.moveXY(item.pos.x, item.pos.y)
hero.moveXY(34, 47)
复查
# 第一点,打败6位ogres~
# 然后收集硬币,直到你有30金。
# 变量用来对ogres计数
defeatedOgres = 0
# 没打败6位ogres,就继续打
while defeatedOgres < 6:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
defeatedOgres += 1
else:
hero.say("食人魔!")
# 移到地图的右侧。
hero.moveXY(49, 36)
# 钱没攒够30块,就继续捡
while hero.gold < 30:
# 寻找并收集金币
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
# 去掉这行 say()。
hero.say("我应该收集金币!")
# 移动到出口。
hero.moveXY(76, 32)
山谷的风与牛
# 沙漠风暴!收衣服啦!!
# 牛牛检测到风暴迹象
# 把变量做为执行条件
yak = hero.findNearestEnemy()
# 至少还有一只牛牛在场时:
while yak:
item = hero.findNearestItem()
if item:
hero.moveXY(item.pos.x, item.pos.y)
# 更新变量`yak`的值
# 使用findNearestEnemy()
yak = hero.findNearestEnemy()
if yak == 0:
break
pass
# 牛没了!
# 快去撤离点:红X
hero.moveXY(38, 58)
菠菜粉
# 收集7份菠菜药水。
# 然后你会强大到足以击败食人魔。
potionCount = 0
# 在while循环中包装药水集合代码。
# 使用条件检查potionCount
while True:
item = hero.findNearestItem()
if item:
hero.moveXY(item.pos.x, item.pos.y)
potionCount += 1
if potionCount == 7:
break
# 当while循环结束时,
# 去战斗吧!
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
沙漠战役
# while循环重复直到条件为否。
ordersGiven = 0
while ordersGiven < 5:
# 在站场上移动和排列你的盟友。 (如果你是直接在他们面前,他们只能听到你的。)
hero.moveXY(hero.pos.x, hero.pos.y - 10)
# 用hero.say命令你的盟友“进攻”!
# 如果你在X上,他们只能听到你。
hero.say("Attack!")
# 请务必增加命令!
ordersGiven += 1
while True:
enemy = hero.findNearestEnemy()
# 当你下达完命令,立即加入战斗!
if enemy:
if hero.isReady("cleave"):
hero.cleave(enemy)
else:
hero.attack(enemy)