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

Mad Maxer Sells Out #184

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

# Coins here disappear after a few seconds!
# Get all the gold coins before they vanish.

while True:
    closestGold = None
    minGoldDist = 9001
    coinIndex = 0
    coins = hero.findItems()
    # Find the closest coin that is gold.
    # Remember that gold coins have a value of 3.
    for coin in coins:
        distance=hero.distanceTo(coin)
        if distance<minGoldDist and coin.value==3:
            closestGold=coin
            minGoldDist=distance

        coinIndex+=1

    if closestGold:
        #Now go to the closest gold coin and get it!
        hero.moveXY(closestGold.pos.x,closestGold.pos.y)
        pass