Python Python Collections (2016, retired 2019) Dungeon Game Hit points

tyler borg
tyler borg
1,948 Points

I'M SO LOST. PLZ HELP! (hit points)

I'm stuck on the hit points challenge and have looked through all the community questions but I still don't understand what's going on...All the movements and variables are really confusing me and I can't understand how this works. Can someone outline step by step what's going on here? Would be much appreciated...thx.

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
    xdir, ydir = direction
    if xdir or ydir > 9:
        hp -= 5
    if xdir or ydir < 0:
        hp -= 5
    return x, y, hp

3 Answers

diogorferreira
diogorferreira
19,362 Points

xdir and ydir will always be either -1, 0, -1 - it's the direction in which the player is moving. So it would never be more than 9 and the if statement would never be executed. What you need to compare is the player's x and y positions and check if they're trying to move out of bounds. E.g when the x is 0, xdir cannot be -1 otherwise the character would lose 5HP.
This is the example I am referring to > move((0, 1, 10), (-1, 0)) => (0, 1, 5).

tyler borg
tyler borg
1,948 Points

I'm still confused...I think I'm confused on just how many variables are at play...you're saying that xdir is a separate variable from x?

tyler borg
tyler borg
1,948 Points

i think im starting to understand it a little...this is what i have now even though its still not right.

def move(player, direction):
    x, y, hp = player
    xdir, ydir = direction
    if x + xdir <= 0:
        hp -= 5
    if y + ydir <= 0:
        hp -= 5
    if x + xdir >= 9:
        hp -= 5
    if y + ydir >= 9:
        hp -= 5
    else:
        x + xdir
        y + ydir

    return x, y, hp
tyler borg
tyler borg
1,948 Points

ok...i figured it out. I just had to add an = sign to the +