Chameleons(伪装者)
# Ogres are disguised as coins or gems!
while True:
enemy = hero.findNearestEnemy()
# If you see an enemy - attack it:
if enemy:
hero.attack(enemy)
item = hero.findNearestItem()
# If you see a coin or a gem - move to it's X and Y position:
if item:
hero.moveXY(item.pos.x, item.pos.y)
Arrowproof Wolf(无箭狼)
# Collect mushrooms.
# First, come to the wolf pet and wake up it (say).
hero.moveXY(12, 34)
hero.say("Weak Up wolf!!")
# Next collect mushrooms just usual items.
while True:
item = hero.findNearestItem()
if item:
hero.moveXY(item.pos.x, item.pos.y)
攻擊和凍住你的敵人
# 你掉进陷阱里了!别动!你会受伤的!
# 这个函数检查敌人是否再攻击范围。
def inAttackRange(enemy):
distance = hero.distanceTo(enemy)
# Almost all swords have attack range of 3.
if distance <= 3:
return True
else:
return False
# Attack ogres only when they're within reach.
while True:
# 找到最近的敌人,并将其储存在一个变量中。
enemy = hero.findNearestEnemy()
# 调用 inAttackRange(enemy),将 enemy 作为参数
# 把结果保存于 “canAttack” 变量中
canAttack = inAttackRange(enemy)
# If the result stored in canAttack is True, 然后下手!
if canAttack is True:
hero.attack(enemy)
pass
多人宝藏森林(挑战关卡)
我使用了和平共处的五项原则,没有对电脑下手,挑战关卡,大家可以进行自己的代码编写。这里我就简单编写了。
关于旗子的使用,后面会有很多的练习关卡,让我们多加练习如何使用旗子。
# 当第一个收集100个金币的人!
# 如果你死了,重生的时候只有原来67%的金币
while True:
# 找到金币并攻击敌人
# 使用旗子和特殊的移动策略来赢得比赛!
coin = hero.findNearestItem()
enemy = hero.findNearestItem()
#flag = hero.findFlag()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)
围攻Stonehold(挑战开放关卡)
之后此类关卡先不编写内容,大家自行编写,后续我们会统一用开放式的思想进行此类关卡的内容编写。
并且此类关卡涉及到自身血量的问题,后续的关卡我们也会练习到。如果你不会定义血量等内容,那先使用你的砖石购买些好的装备,来称下血量。
为援兵坚持住
旗子练习关卡!!注意,旗子关卡你需要提交后才可以使用旗子控制英雄!!
# 食人魔正在爬悬崖
# 为集结民兵组织保护足够长时间的农民。
while True:
flag = hero.findFlag()
enemy = hero.findNearestEnemy()
if flag:
# 捡旗子
hero.pickUpFlag(flag)
elif enemy:
# 否则,攻击!
# 使用旗子移动到指定位置,如果 “cleave” 技能冷却完毕,就使用 “cleave” 技能。
if hero.isReady("cleave"):
hero.cleave(enemy)
else:
hero.attack(enemy)
赚钱行家
# To make the training more interesting Senick poisoned you.
# While you aren't moving the poison is harmless.
# This function should check if a coin is closer than 20m.
def isCoinClose(coin):
# Find the distance to the coin.
distanceToCoin = hero.distanceTo(coin)
# If the distance is less than 20:
if distanceToCoin < 20:
# Return True
return True
# Else:
else:
# Return False
return False
pass
while True:
item = hero.findNearestItem()
if item:
# If isCoinClose(item) returns true:
if isCoinClose(item):
hero.moveXY(item.pos.x, item.pos.y)
盐碱地
# Ogres are attacking a nearby settlement!
# 小心,兽人在地上放了毒药。
# Gather coins and defeat the ogres, but avoid the burls and poison!
while True:
enemy = hero.findNearestEnemy()
if enemy.type == "munchkin" or enemy.type == "thrower":
hero.attack(enemy)
item = hero.findNearestItem()
# 检查物品类型,确保英雄不会捡起毒药!
# Look for types: 'gem' or 'coin'
if item.type == "gem" or item.type == 'coin':
hero.moveXY(item.pos.x, item.pos.y)