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 trialHussein Amr
2,461 PointsDidn'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)."
# 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
Treehouse Moderator 68,441 PointsThe 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
2,461 PointsChris 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
Treehouse Moderator 68,441 PointsVery, 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.
Hussein Amr
2,461 PointsHussein Amr
2,461 PointsApparently 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
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsI see what you're trying to do. How about:
The other way is: