[SOLVED] Computer Science 5: Level 23 Power Points

My hero doesn’t survive and is also not able to defeat all of the skeletons. The code runs fine but I am not able to pass this level and I am not sure what I am doing wrong.

# You need to find and destroy 3 skeletons.
# Skeletons and items are summoned at points of power.
# Move to a point and say the spell: "VENI".
# To find the required points, use the wizard's map.
# 0s are bad points. Positive numbers are good.

spell = "VENI"
# The map of points is a 2D array of numbers.
wizard = hero.findNearest(hero.findFriends())
powerMap = wizard.powerMap

# This function converts grid into x-y coordinates.
def convert(row, col):
    return {'x': 16 + col * 12, 'y': 16 + row * 12}

# Loop through the powerMap to find positive numbers.
# First, loop through indexes of rows.
for i in range(len(powerMap)):
    # Each row is an array. Iterate through it.
    for j in range(len(powerMap[i])):
        # Get the value of the i row and j column.
        pointValue = powerMap[i][j]
        # If it's a positive number:
        if pointValue > 0 :
            # Use convert to get XY coordinates.
            pon = convert(i, j)
            # Move there, say "VENI" and be prepared!
            hero.moveXY(pon.x, pon.y)
            hero.say("VENI")
            enemy = hero.findNearest(hero.findEnemies())
            item = hero.findNearest(hero.findItems())
            if enemy :
                hero.attack(enemy)
            else :
                hero.moveXY(item.pos.x, item.pos.y)

Everything looks good, except, you should add a while loop that checks the state of health of the enemy. As your code is now, you attack it one time, then move on…instead, keep on attacking until it is dead :wink:

2 Likes

Oh, and welcome to the forum! :grin:

3 Likes

thank you for helping me!

3 Likes

hello. can you edit the title by typing [SOLVED] before it please?

1 Like

Done. :slightly_smiling_face:

1 Like

yay!!! (20 characters)

1 Like