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 Adari
Daniel Adari
3,577 Points

Help in Hit Points challenge!

I have tried solving it in this way with no success... I know there is an easier way but I want to complete it this way... Please help :(

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):
    x, y, hp = player
    x_move, y_move = direction
    nx = x + x_move
    ny = y + y_move

    if (nx) in range(0, 9):
        x = nx
    elif nx > 9:
        hp -= 5
        x = 9
    else:
        x = 0

    if (ny) in range(0, 9):
        y = ny
    elif ny > 9
        hp -= 5
        y = 9
    else:
        y = 0

    return x, y, hp

3 Answers

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

Hi Daniel Adari. Actually, you are closer than you may think :smile: , your approach it's good and it works just fine, double check the second elif statement, something it's missing from the end. Happy coding.

Good spot, too!! :smile: :+1:

Hi Daniel,

I had another look at this one to remind myself how this challenge worked.

I did the same as you and created two more variables to represent the x and y change. I then tested whether x plus the change in x position was either less than zero or greater than 9. If so, do nothing to x but take 5 off hp otherwise, allow the change in the else part of the conditional test. Then do the same with y.

I hope that makes sense.

Steve.

Hi Daniel,

You need to test for scenarios where x or y may become less than zero; not just greater than 9.

I hope that helps a little! Else, get back to me and I'll explain further ... post any new code, though.

Steve.