Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
231,236 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
231,236 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 '&'