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

jmac pd
jmac pd
11,490 Points

HP: hmm can't find a the problem. Function passes when I pass various values through it.

I passed this through my function and got the values I expected:

move((9, 5, 15), "RIGHT") (9, 5, 10) move((0, 8, 10), "LEFT") (0, 8, 5) move((1, 0, 10), "UP") (1, 0, 5) move((5, 9, 10), "DOWN") (5, 9, 5)


move((5, 8, 10), "DOWN") (5, 9, 10) move((1, 1, 10), "UP") (1, 0, 10) move((1, 8, 10), "LEFT") (0, 8, 10) move((8, 5, 15), "RIGHT")

thinking maybe I am using "direction" wrong, but now I'm thinking in a box I can't get out of.

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
    if direction == "LEFT":
        x -= 1
        if x <= -1:
            hp = hp - 5
            x = 0
    if direction == "RIGHT":
        x += 1
        if x >= 10:
            hp = hp-5
            x = 9
    if direction == "UP":
        y -= 1
        if y <= -1:
            hp = hp - 5
            y = 0
    if direction == "DOWN":
        y += 1
        if y >= 10:
            hp = hp-5
            y = 9

    return x, y, hp

1 Answer

Steven Parker
Steven Parker
231,269 Points

You seem to be expecting "direction" to be a string with an upper-case word.

But the instructions say the function should take "a direction tuple that's two parts, the x to move and the y (like (-1, 0) would move to the left but not up or down)."

So instead of :point_right: move((1, 1, 10), "LEFT")
you might get :point_right: move((1, 1, 10), (-1, 0))

Also see the examples provided in the comments.

jmac pd
jmac pd
11,490 Points

haha i assumed that would be taken from another function that took the player's input.

fine I will check the comments later then...I don't like going straight to an answer.

Steven Parker
Steven Parker
231,269 Points

I'm not sure what you mean by "straight to an answer". The "EXAMPLES" section in the comments (shown in the code above) only illustrate how the method might be called.