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

Hussein Amr
Hussein Amr
2,461 Points

Didn't understand

I think this is quite easy, but i didn't understand that part: "Our move function takes this three-part tuple player and 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)."

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

    return x, y, hp

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

The player gives an example of using the three-part tuple to extract the current x, y, and hp from the player tuple.

Similarly, the move is a two-part tuple of the form (x, y). It can be extracted in a similar fashion to get the desired move:

x_move, y_move = direction

Post back if you need more help. Good luck!!

Hussein Amr
Hussein Amr
2,461 Points

Apparently I can't get the program to stop if the player is trying to get past the wall I don't know how i should use the max and min Chris Freeman

def move(player, direction):
    x, y, hp = player
    x_move , y_move = direction 


    if x_move + x > 9 or x_move + x < 0:
        hp -= 5
        max(x) = 9
        min(x)= 0
    else:
        x_move + x

    if y_move + y > 9 or y_move + y < 0:
        hp -= 5
        max(y) = 9
        min(y) = 0
    else:
        y_move + y

    return x, y, hp
Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

I see what you're trying to do. How about:

    x = min(9, x) # reduces x to 9 if greater 9
    X = max(0, x) # increases x to 0 if less than 0

The other way is:

if x > 9:
    x = 9
elif x < 0:
    x = 0
Hussein Amr
Hussein Amr
2,461 Points

Chris Freeman is it possible to use the second method in the same if statement that I have or do I have to create a new one? also the methods don't work tell me what i'm doing wrong

def move(player, direction):
    x, y, hp = player
    x_move , y_move = direction 


    if x_move + x > 9 or x_move + x < 0:
        hp -= 5
        X = min(9 , x)
        x = max(0 , x)
    else:
        x_move + x

    if y_move + y > 9 or y_move + y < 0:
        hp -= 5
        Y = min(9 , y)
        y = max(9 , y)
    else:
        y_move + y

    return x, y, hp
Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Very, very close now. Remember to assign the new value back to x and y in the else blocks so the new values can be returned.