动物园管理员
# 保护笼子。
# 放一个士兵在每一个 X 的位置
points = []
points[0] = {"x": 33, "y": 42}
points[1] = {"x": 47, "y": 42}
points[2] = {"x": 33, "y": 26}
points[3] = {"x": 47, "y": 26}
# 1.收集80金币。
while hero.gold < 80:
coins = hero.findItems()
coin = hero.findNearest(coins)
if coin:
hero.move(coin.pos)
# 2.建造4个士兵。
for i in range(4):
hero.summon("soldier")
# 3.派你的士兵到特定的位置上。
while True:
friends = hero.findFriends()
for j in range(len(friends)):
point = points[j]
friend = friends[j]
enemy = friend.findNearestEnemy()
if enemy and enemy.team == "ogres" and friend.distanceTo(enemy) < 5:
# 命令友方攻击。
hero.command(friend, "attack", enemy)
else:
# 命令的朋友移动到特定点上。
hero.command(friend, "move", point)
木材的叛徒
我使用了法师的角色,购买了个可以召唤树榴巨人的法杖,通过召唤牛逼的生物过的关。。
while True:
# 收集金子
coin = hero.findNearest(hero.findItems())
hero.move(coin.pos)
# 如果你有足够的金币,那就招募一个士兵。
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
#判断召唤树怪技能是否准备OK,如果准备好,就召唤。
if hero.canCast("summon-burl"):
hero.cast("summon-burl")
# 使用 for 循环来命令每个士兵。
#friends = hero.findFriends()
for friend in hero.findFriends():
if friend.type == "soldier" or friend.type == "summon-burl":
hero.command(friend, "move", {"x": 73, "y": 46})
enemy = friend.findNearestEnemy()
# 如果这里有一个敌人,那就命令她攻击。
# 小心!如果你的战士被打败了,术士就会出现!
# 否则的话,将她移动到地图的右边。
if enemy:
hero.command(friend, "attack", enemy)
if friend.health < friend.maxHealth / 2:
hero.command(friend, "move", hero.pos)
高贵的牺牲
# 收集80金。
while hero.gold <= 80:
coin = hero.findNearest(hero.findItems())
hero.move(coin.pos)
# 建造4个士兵来做诱饵
while hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
# 派你的士兵到指定位置。
points = []
points[0] = { "x": 13, "y": 73 }
points[1] = { "x": 51, "y": 73 }
points[2] = { "x": 51, "y": 53 }
points[3] = { "x": 90, "y": 52 }
friends = hero.findFriends()
for j in range(len(friends)):
# 使用range来得到可供遍历的数组。
# 让各盟友士兵和各地点位置匹配,以命令他们移动
point = points[j]
friend = friends[j]
hero.command(friend, "move", point)
狩猎派对
注意下提示,有可能是不对的,如果不看提示,可以按照你自己的思路做编写代码。
# You can use findNearestEnemy() on your soldiers to get their nearest enemy instead of yours.
while True:
friends = hero.findFriends()
# Use for-loop and for each friend:
for friend in friends:
# Command to move east by small steps.
hero.command(friend, "move", {"x":friend.pos.x + 0.1,"y": friend.pos.y})
# If they see an enemy then command to attack.
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
保护和服务
# 保护工人和动物!
# 捍卫这两个职业:
defend = []
defend[0] = { "x": 98, "y": 28 }
defend[1] = { "x": 84, "y": 7 }
soldiers = []
friends = hero.findFriends()
for index in range(len(friends)):
friend = friends[index]
if friend.type == "soldier":
soldiers.append(friend)
else:
# 保卫工人:
defend.append(friend)
while True:
# 使用for循环将每个士兵分配给对应的防守[]目标
# 使用命令(士兵,"defend",胜)或命令(士兵,"defend",位置)
for j in range(len(soldiers)):
friend = friends[j]
soldier = soldiers[j]
#defend = defend[j]
hero.command(soldier, "defend", defend[j])
pass