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

Gas Attack #176

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

# Calculate the total health of all the ogres.

def sumHealth(enemies):
    # Create a variable and set it to 0 to start the sum.
    totalHealth = 0
    # Initialize the loop index to 0
    enemyIndex = 0
    enemies=cannon.findEnemies()
    # While enemyIndex is less than the length of enemies array
    while enemyIndex<len(enemies):
        # Add the current enemy's health to totalHealth
        totalHealth+=enemies[enemyIndex].health
        # Increment enemyIndex by 1.
        enemyIndex+=1
    return totalHealth

# Use the cannon to defeat the ogres.
cannon = hero.findNearest(hero.findFriends())
# The cannon can see through the walls.
enemies = cannon.findEnemies()
# Calculate the sum of the ogres' health.
ogreSummaryHealth = sumHealth(enemies)
hero.say("Use " + ogreSummaryHealth + " grams.")