地牢关卡过完,接下来是边缘的森林!
1,森林保卫战
hero.moveUp()hero.buildXY("fence", 40, 52)hero.moveDown()hero.moveDown()hero.buildXY("fence", 40, 20)
2,羊肠小道
# It's the first point of the path.hero.moveXY(36, 59)# Move at the next points of the path.hero.moveXY(37, 13)# Build a fence to stop the ogre.hero.moveXY(79,18)hero.moveXY(73,61)hero.moveXY(79,18)
3,丛林里的隔间
hero.moveXY(19, 33)enemy = hero.findNearestEnemy()# 条件判断式将会检查该变数是否参考到一个ogreif enemy: hero.attack(enemy) hero.attack(enemy)hero.moveXY(49, 51)enemy = hero.findNearestEnemy()if enemy: # 在这里撰写攻击敌人指令 hero.attack(enemy) hero.attack(enemy) # pass没有特别的意思,只是用来协助结束条件判断式,写不写都可以 passhero.moveXY(58, 14)enemy = hero.findNearestEnemy()# 使用条件判断式来确认敌人是否存在if enemy: # 如果敌人存在就攻击他 hero.attack(enemy) hero.attack(enemy)
4,if-stravaganza
while True: enemy = hero.findNearestEnemy() # 使用一个 “if” 语句去检查是否有敌人存在: if enemy: # 攻击敌人如果它存在的话 hero.attack(enemy) hero.attack(enemy)
5,背靠背
while True: enemy = hero.findNearestEnemy() if enemy: # 亦或主动出击... hero.attack(enemy) hero.attack(enemy) else: # 亦或回到你的阵地防守。 hero.say(" 我看不到敌人") hero.moveXY(40, 34) pass
6,森林劈裂者
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,边远地区的对峙
while True: # 使用 ‘isReady’ 中的一个 “if-statement” 的语句来检查 “cleave” if hero.isReady("cleave"): # 劈斩! enemy = hero.findNearestEnemy() hero.cleave(enemy) # 或者,如果 cleave 还没准备好的话: else: # 说一点什么来吓走曼切堪食人魔 hero.say(" 快滚吧!刀剑无眼 ! ") pass
8,测距仪
enemy1 = "Gort"distance1 = hero.distanceTo(enemy1)hero.say(distance1)enemy2 = "Smasher"distance2 = hero.distanceTo(enemy2)# 将distance2变数作为参数,传入say()方法hero.say(distance2)# 测量并说出剩余敌人与英雄间的距离# 不要向你的友军进行射击!enemy3 = "Charles"enemy4 = "Gorgnub"distance4 = hero.distanceTo(enemy4)hero.say(distance4)
9,保护农民
while True: enemy = hero.findNearestEnemy() distance = hero.distanceTo(enemy) if distance < 10: # 如果他们与农民太近,就攻击他们 hero.attack(enemy) pass # 否则的话,呆在农民旁边! hero.moveXY(40, 37)
10,疯狂的食人魔
# 地上另一个让英雄打开的宝箱!# 攻击宝箱以打开它# 有些食人魔可不会呆呆地站着挨打!# 当食人魔离你太近时,你得学着保护你自己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
11,跃火林中
# 在这关,别碰恶魔石!往其他方向移动避开它们!while True: evilstone = hero.findNearestItem() if evilstone: pos = evilstone.pos if pos.x == 34: # 如果恶魔石在左边,走到右边。 hero.moveXY(46, 22) pass else: # 如果恶魔石在右边,走到左边。 hero.moveXY(34, 22) pass else: # If there's no evilstone, go to the middle. hero.moveXY(40, 22) pass
12,Village Rover
# This defines a function called findAndAttackEnemydef 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) # Use findAndAttackEnemy findAndAttackEnemy()
13,Backwoods Fork
# This function has a parameter.# 参数是一种给函数传递信息的方式。def checkAndAttack(target): # The 'target' parameter is just a variable! # 它包含了函数调用时的参数。 if target: hero.attack(target) hero.moveXY(43, 34)while True: hero.moveXY(58, 52) topEnemy = hero.findNearestEnemy() checkAndAttack(topEnemy) # 移动到底部的X标记处。 hero.moveXY(58, 16) # 创建名为 bottomEnemy 的变量,寻找最近敌人。 bottomEnemy = hero.findNearestEnemy() # 使用 checkAndAttack 函数,并包括 bottomEnemy 变量。 checkAndAttack(bottomEnemy)
14,Leave it to Cleaver
# This shows how to define a function called cleaveWhenClose# The function defines a parameter called targetdef cleaveWhenClose(target): if hero.distanceTo(target) < 5: pass # Put your attack code here # If cleave is ready, then cleave target hero.cleave(enemy) # else, just attack target! hero.attack(enemy)# This code is not part of the function.while True: enemy = hero.findNearestEnemy() if enemy: # Note that inside cleaveWhenClose, we refer to the enemy as target. cleaveWhenClose(enemy)
15,友人和敌人
# 农民和士兵聚集在森林。# 命令农民战斗,苦工远离!while True: friend = hero.findNearestFriend() if friend: hero.say("To battle, " + friend.id + "!") # 寻找最近的敌人,然后让他们滚蛋 enemy = hero.findNearestEnemy() if enemy: hero.say("Scram," + enemy.id + "!")
16,巫师之门
# Move to Laszlo and get his secret number.hero.moveXY(30, 13)las = hero.findNearestFriend().getSecret()# 向 Laszlo 的数字中加7就能得到 Erzsebet的号码# Move to Erzsebet and say her magic number.erz = las + 7hero.moveXY(17, 26)hero.say(erz)# 将 Erzsebet 的数字除以 4 得到 Simoyi 的数字。# Go to Simonyi and tell him his number.sim = erz / 4hero.moveXY(30, 39)hero.say(sim)# 将 Simonyi 的数字乘以 Laszlo 的数字得到 Agata 的数字。# Go to Agata and tell her her number.Aga = sim * lashero.moveXY(43, 26)hero.say(Aga)
17,金币屑
# 跟随硬币的轨迹来到红色 X 标记的出口while True: # 这能找到最近的敌人。 item = hero.findNearestItem() if item: # 这将物品的 pos,就是坐标,存储在变量中。 itemPosition = item.pos # 将物品的 X 和 Y 坐标放进变量。 itemX = itemPosition.x itemY = itemPosition.y # Now, use moveXY to move to itemX and itemY: hero.moveXY(itemX, itemY)
18,Blind Distance
# 你的任务是告诉他兽人的距离。# 这个函数寻找最近的敌人,并返回距离。# If there is no enemy, the function returns 0.def nearestEnemyDistance(): enemy = hero.findNearestEnemy() result = 0 if enemy: result = hero.distanceTo(enemy) return resultwhile True: # Call nearestEnemyDistance() and # save the result in the variable enemyDistance. enemyDistance = nearestEnemyDistance() # If the enemyDistance is greater than 0: if enemyDistance: # Say the value of enemyDistance variable. hero.say(enemyDistance)
可选关卡1:竞技场
# 在决斗中击败敌人的英雄!while True: # 在一个循环中找到并攻击敌人 # 当你完成的时候,提交到多人天梯系统中! enemy = hero.findNearestEnemy() hero.attack(enemy) if len(hero.findNearestEnemy()) > 5: hero.shield() else: hero.attack(enemy)