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

Air Bridge #170

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

# Help peasants to escape.

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

def onSpawn(event):
    remainingPeasants = 3
    while remainingPeasants > 0:
        pet.moveXY(40, 55)
        peasant = pet.findNearestByType("peasant")
        if peasant:
            pet.carryUnit(peasant, 40, 34)
            remainingPeasants -= 1
    enemy = pet.findNearestByType('munchkin')
    if enemy:
        pet.carryUnit(enemy, 40, 19)
pet.on("spawn", onSpawn)

while True:
    enemy = None
    enemies = hero.findEnemies()
    for element in enemies:
        if element.pos.x>30 and element.pos.x<50:
            enemy = element
            break
    if enemy:
        hero.attack(enemy)