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

Bookkeeper #121

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

# This function allows to fight until the certain time
# and report about defeated enemies.
def fightAndReport(untilTime):
    defeated = 0
    while True:
        enemy = hero.findNearestEnemy()
        if enemy:
            hero.attack(enemy)
            if enemy.health <= 0:
                defeated += 1
        if hero.time > untilTime:
            break
    hero.moveXY(59, 33)
    hero.say(defeated)

def CollectCoins():
    while True:
        coin=hero.findNearestItem()
        if coin.type=="coin":
            hero.moveXY(coin.pos.x,coin.pos.y)
            if hero.time>30:
                break

# Fight 15 seconds and tell Naria how many enemies you defeated.
fightAndReport(15)

# Collect coins until the clock reaches 30 seconds.
CollectCoins()

# Tell Naria how much gold you collected.
hero.say(hero.gold)

# Fight enemies until the clock reaches 45 seconds.
fightAndReport(45)