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

Daniel Escobar
Daniel Escobar
2,580 Points

I need help with this Challenge Task

I am not sure what am I doing wrong. I tried so many ways. Can someone help me please.

movement.py
def move(player, direction):

    x, y, hp = player
    x1, y1 = direction


    if x + x1 <= 0:
        x += 1
        hp=- 5
    elif x + x1 >= 9:
        x -=1
        hp=- 5
    elif y + y1 <= 0:
        y += 1
        hp=- 5
    elif y + y1 >= 9:
        y -= 1
        hp=- 5
    else:
        x = x + x1
        y = y + y1

    return x, y, hp

1 Answer

Steven Parker
Steven Parker
231,269 Points

You've got the right idea, but there are a few implementation issues. Here are a few hints:

  • 0 and 9 are part of the grid, so the tests should allow them (just not anything beyond)
  • when a wall would be hit, the x or y should not be changed
  • when reducing hp, the subtracting assignment operator is "-=" (not "=-")