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

Sarven Siege(money grab) #164

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

# Defend your towers in this replayable challenge level!
# Step on an X if you have 20 gold to build a soldier.

while True:
    coins=hero.findItems()
    coinIndex=0
    nearest=None
    nearestDistance=999

    while coinIndex<len(coins):
        coin=coins[coinIndex]
        coinIndex+=1
        distance=hero.distanceTo(coin)

        if distance<nearestDistance:
            nearest=coin
            nearestDistance=distance
        if hero.gold>=25 :
            hero.moveXY(83,78)
        if hero.gold>=26:
            hero.moveXY(84, 51)
        if hero.gold>=27:
            hero.moveXY(84,22) 
    hero.moveXY(nearest.pos.x,nearest.pos.y)