Hit and Freeze (python) [Solved]

# You are trapped. Don't move, it'll be painful.

# This function checks if the enemy is in your attack range.
def inAttackRange(enemy):
    distance = hero.distanceTo(enemy)
    # Almost all swords have attack range of 3.
    if distance <= 3:
        return True
    else:
        return False

# Attack ogres only when they're within reach.
while True:
    # Find the nearest enemy and store it in a variable.
    enemy = hero.findNearestEnemy()
    # Call inAttackRange(enemy), with the enemy as the argument
    # and save the result in the variable canAttack.
    if hero == inAttackRange(enemy):
        return true
    # If the result stored in canAttack is True, then attack!
    if inAttackRange == true:
        hero.attack(enemy)
    pass

that’s my code and I just don’t understand the level that much
could someone help me understand it beter

Did you even start rlly -_0

1 Like

capitalize true everywhere, remove pass, use <= 2 so its a guaranteed hit, as munchkins can move. If you have the longsword, you can increase the distance

also you have not made the variable canAttack so change your code to

canAttack = inAttackRange(enemy)
if canAttack:
    hero.attack(enemy)
2 Likes

try listening to the blue comments. if you are still stuck, use hints, they are there for free and unlimited. finally ask the forums

1 Like

read the link too please as you are a new user

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.