极客战记前三章一些较难关卡攻略
的有关信息介绍如下:极客战记有些关卡比较扰人,需要一些技巧。
地牢KITHGARD之门
# 建造三个围栏来阻挡食人魔!
hero.moveDown()hero.buildXY("fence", 36, 34)hero.buildXY("fence", 36, 28)hero.moveRight()hero.moveRight()hero.moveRight()
森林 野马
while True: # 你怎么寻找最近的友好单位? # 马=? horse = hero.findNearest(hero.findFriends()) if horse: x1 = horse.pos.x - 4 x2 = horse.pos.x + 3 if x1 >= 1: # 移动到马的y坐标,但使用x1作为x坐标。 hero.moveXY(x1, horse.pos.y) elif x2 <= 79: # 移动到马的y坐标,但使用x2作为x坐标。 hero.moveXY(x2, horse.pos.y) distance = hero.distanceTo (horse) if distance <= 10: hero.say("Whoa") # 移到到红色的x来使马返回农场。 hero.moveXY(27, 54) # 移回牧场开始寻找下一匹马。
森林 嘲弄
# Attack munchkins, call brawlers and ignore burls.
# This function defines the hero's behaviour about enemies.def dealEnemy(enemy): # If enemy.type is "munchkin": if enemy.type is "munchkin": hero.attack(enemy) # Then attack it: pass # If the enemy's type is "brawler": if enemy.type is "brawler" : # Then say something to call the brawler: hero.say("help") pass
while True: enemy = hero.findNearestEnemy() if enemy: dealEnemy(enemy) else: hero.moveXY(30, 34)
沙漠 哨兵
while True: flagGreen = hero.findFlag("green") flagBlack = hero.findFlag("black") if flagGreen: hero.buildXY("fence", flagGreen.pos.x, flagGreen.pos.y) hero.pickUpFlag(flagGreen)# 如果是绿色旗子,就建立一个栅栏。# Build a "fence" at flagGreen's position.
# 记住要捡起旗子,在你都完成之后! if flagBlack: # 如果是黑色旗子,就建立一个火焰陷阱 hero.buildXY("fire-trap", flagBlack.pos.x, flagBlack.pos.y) hero.pickUpFlag(flagBlack)# Build a "fire-trap" at flagBlack's position.# 记住要捡起旗子,在你都完成之后 ! else: # 回到中间。 hero.moveXY(43, 31)
沙漠 诱饵转
# 我们在测试一个新的战斗单位:诱饵(decoy)。# 创建4个诱饵,然后汇报给 Naria
decoysBuilt = 0while True: coin = hero.findNearestItem() if coin: # 掠夺金币! hero.moveXY(coin.pos.x, coin.pos.y) pass # 每个诱饵消费25个金币。 # 让它知道当你有超过25个金币的时候 if hero.gold >= 25: # buildXY a "decoy" hero.buildXY("decoy", hero.pos.x, hero.pos.y) # 当你一直走的时候,保持统计你创建的诱饵的数量。 decoysBuilt += 1 if decoysBuilt == 4: # 当你创建了4个诱饵时跳出循环 break pass hero.say("完成创建诱饵!")hero.moveXY(14, 36)# 去找 Naria 并告诉她你创建了多少个诱饵。hero.say("I duilded "+decoysBuilt+" decoys !")
沙漠 团队合作
# 宝石很快就会消失。 你需要帮助!
# findItems()返回一个项目数组。items = hero.findItems()
# Get the first gem from the array.# Don't forget that the first index is 0.gem0 = items
# # 告诉 Bruno 拿到 gem0hero.say("Bruno " + gem0)
# You can reference the gem without a variable.hero.say("Matilda " + items)
# Create a variable for the last gem, items:gem2 =items# Move to that gem's position using moveXY()hero.moveXY(gem2.pos.x, gem2.pos.y)
沙漠 疯狂的MAX
while True: farthest = None maxDistance = 0 enemyIndex = 0 enemies = hero.findEnemies()
# 查看全部敌人,找出最远的那个。 while enemyIndex < len(enemies): target = enemies[enemyIndex] enemyIndex += 1
# 是不是存在远得看不到的敌人? distance = hero.distanceTo(target) if distance > maxDistance: maxDistance = distance farthest = target
if farthest: # 干掉最远的敌人! # 如果敌人血量大于0就保持攻击。 while farthest.health > 0: if hero.isReady("cleave"): hero.cleave(farthest) elif hero.isReady("bash"): hero.bash(farthest) else: hero.attack(farthest) pass
沙漠 一打宝石
# 打败前来劫掠的食人魔,让他们把金币交出来!
def findMostHealth(enemies): target = None targetHealth = 0 enemyIndex = 0 while enemyIndex < len(enemies): enemy = enemies[enemyIndex] if enemy.health > targetHealth: target = enemy targetHealth = enemy.health enemyIndex += 1 return target
def valueOverDistance(item): return item.value / hero.distanceTo(item)
# 返回有最高 valueOverDistance(item) 的物品。def findBestItem(items): bestItem = None bestValue = 0 itemsIndex = 0 while itemsIndex < len(items): item = items[itemsIndex] if valueOverDistance(item) > bestValue: bestItem = item bestValue = valueOverDistance(item) itemsIndex += 1 return bestItem
while True: enemies = hero.findEnemies() enemy = findMostHealth(enemies) if enemy and enemy.health > 15: while enemy.health > 0: hero.attack(enemy) else: coins = hero.findItems() coin = None coin = findBestItem(coins) if coin: hero.moveXY(coin.pos.x, coin.pos.y)