AlexeySapsay / Python_solution_CodeCombat_2018

In that repository I will post my sollution for codecombat.com games for study Python
1 stars 0 forks source link

Pet Engineer #180

Open AlexeySapsay opened 6 years ago

AlexeySapsay commented 6 years ago
# Follow me on youtube  channel Phy Tu
# Help with programming on Python, school math, physics
# https://www.youtube.com/channel/UCP5ycahCEZ24qmRRgNnko5Q

# Move your pet to the left or right button as needed.

def onHear(event):
    # Find the guards to listen to.
    archer = pet.findNearestByType("archer")
    soldier = pet.findNearestByType("soldier")
    # If event.speaker is the `archer`:
    if event.speaker==archer:
        # Move to the left button.
        pet.moveXY(32,30)
    # If event.speaker is the `soldier`:
    if event.speaker==soldier:
        # Move to the right button.
        pet.moveXY(48,30)

pet.on("hear", onHear)

# You don't have to change the code below.
# Your hero should protect the bottom right passage.
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)