Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Dungeon Game Hit points

Quick Help with Move Function in Hit Points (HINT needed!)

Can someone give me some assistance in figuring out why this wont work. I have updated the position and by unpacking direction into movex and movey it should be accounting for the updating position

movement.py
# EXAMPLES:
# move((1, 1, 10), (-1, 0)) => (0, 1, 10)
# move((0, 1, 10), (-1, 0)) => (0, 1, 5)
# move((0, 9, 5), (0, 1)) => (0, 9, 0)

def move(player, direction):
    movex, movey = direction
    x, y, hp = player
    if x == 0 & movex == -1:
        hp -= 5
        x = 0
    # if player's x == 4 , they can't move right
    elif x == 9 & movex == 1:
        hp -= 5
        x = 9
    # if player's y == 0 , they can't move up
    elif y == 0 & movey == -1:
        hp -= 5
        y = 0
    # if player's y == 4 , they can't move down
    elif y == 9 & movey == 1:
        hp -= 5
        y = 9
    else:
        x += movex
        y += move y         
    return x, y, hp

3 Answers

Steven Parker
Steven Parker
221,295 Points

You're nearly there, I see two issues (on 5 lines):

  • the boolean combination operator is the word "and", not the symbol "&"
  • it looks like you have a stray space in the middle of "movey" on the second-to-last line
Steven Parker
Steven Parker
221,295 Points

I invite the person who down-voted this answer to leave an explanatory comment to help me provide better assistance in the future.

not sure if this block will work if the direction tuple will have negative (-) numbers?

else:
    x += movex
    y += movey  

will you get correct result from this?:

x += -1

Try using 'and' instead of '&'