好伙伴的名字B
# 宠物需要向英雄和农民问好。
# 使用这个函数作为"hear"事件的处理函数:
def sayHello(event):
# 宠物在说你好:
pet.say("致敬")
# 使用宠物的pet.on("eventType", functionName)方法.
# 这一关里,宠物需要在听到声音后运行sayHello
pet.on("hear", sayHello)
# 那么,问候宠物,等待回应。
hero.say("你好,朋友!")
宠物小测试
# 编写一个事件处理函数,名为onHear
# 完成onHear函数
def onHear(event):
# 宠物需要在onHear中说点什么。
pet.say("必须的!")
pet.say("必须是!")
pet.say("28")
pet.say("美国!")
pet.say("Bye")
pass
pet.on("hear", onHear)
hero.say("能听懂我的话吗?")
hero.say("你是美洲狮吗?")
hero.say("你多大啦?")
# 再问两个问题。
hero.say("你来自哪里?")
hero.say("Byebye")
看门狗
# 你无法帮助农民过河。
# 不过,你的宠物做得到!
# 将你的狼调教成看门狗。
def onSpawn(event):
while True:
# 宠物一样可以发现敌人。
enemy = pet.findNearestEnemy()
# 如果有敌人:
if enemy:
# 然后让宠物说点什么:
pet.say("鬼子来了,快跑啊!!!")
pet.on("spawn", onSpawn)
漫漫长路
如果你的血较少,记得买件撑血的装备。
# 移动到右边
# 补全这个函数:
def onSpawn(event):
pass
# 在 while-true 循环里:
while True:
# 使用hero.findNearestItem()
item = hero.findNearestItem()
# 如果有物品:
if item:
# 使用pet.fetch(item)来拿取物品。
pet.fetch(item)
# 使用pet.on()来将onSpawn指派给"spawn"事件
pet.on("spawn", onSpawn)
hero.moveXY(78, 35)
森林慢跑
# 你的宠物可以使用 pet.moveXY()
def onSpawn(event):
while True:
# 首先,移动到左侧X标记处:
pet.moveXY(9, 24)
# 接着,移动到上面的X标记。
pet.moveXY(30, 43)
# 将宠物移动至右侧的X标记处:
pet.moveXY(51, 24)
# 将你的宠物移动到下面的X标记处:
pet.moveXY(30, 5)
# 使用pet.on(),通过onSpawn来处理"spawn"事件
pet.on("spawn", onSpawn)
# 激励你的宠物!
# 不要移除下方的命令。
while True:
hero.say("狗狗真棒!")
hero.say("你能做到的!")
hero.say("跑跑跑!")
hero.say("快好了!")
hero.say("再来一圈!")
Airdrop(空投)
# Get all swords and protect the village.
def onSpawn (event):
while True:
item = hero.findNearestItem()
# The pet should fetch the item if it exists:
if item:
pet.fetch(item)
# Assign onSpawn function for the pet's "spawn".
pet.on("spawn", onSpawn)
while True:
# Guard the left passage:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
hero.moveXY(22, 34)
pass
森林加农炮之舞
# 你的宠物应该在X标记上来回跑动
# 英雄需要时刻保持兴奋!
# 为宠物编写事件函数onSpawn
# 这个函数要让狼来回跑动:
# 首先,跑到右侧的标记上,然后左侧的标记:
def onSpawn():
while True:
pet.moveXY(48, 8)
pet.moveXY(12, 8)
pet.on("spawn", onSpawn)
# 鼓舞你的宠物。不要移除这个:
while True:
hero.say("跑!!!")
hero.say("速度!")
Reward and Ruination(罪与罚)
# It seems like the Ogre Chieftain is stealing your gems!
# Use the two artillery cannons for your goals.
while True:
enemy = hero.findNearestEnemy()
if enemy:
enemyPos = enemy.pos.x + " " + enemy.pos.y
hero.say("Enemy at " + enemyPos)
# Now that you have sweet revenge,
# why not have your cake and eat it, too?
# Find the item's position and
# say it for your artillery to target.
item = hero.findNearestItem()
if item:
itemPos = item.pos.x + " " + item.pos.y
hero.say("Item at " + itemPos)