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

Can any one help on this Code?

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). Finish the function so that if the player is being run into a wall, their hp is reduced by 5. Don't let them go past the wall. Consider the grid to be 0-9 in both directions. Don't worry about keeping their hp above 0 either.
# 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
    xd,yd = direction

    if xd==-1 and x>0:
        x -=1 
    if xd==1 and x<9
        x +=1
    elif (x==0 or yd==1 or yd==-1 or x==9):
    return x, y, hp

1 Answer

Steven Parker
Steven Parker
203,207 Points

Here's a few hints to help get you back on track:

  • you don't need to test if the original position is already out of bounds
  • you should probably not assume the direction is in only one dimension, or only one unit
  • be sure to check if the new location would be out of bounds in either dimension
  • you won't need to "print" anything

Thank you very much for the hints. I have done this one. Thank you!