
wayne ross
3,222 Pointsmove challenge question for task 1
Our game's player only has two attributes, x and y coordinates. Let's practice with a slightly different one, though. This one has x, y, and "hp", which stands for hit points.
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.
Any ideas on what I am doing wrong here?
# 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 wall_perimeter(player):
def move(player, direction):
x, y, hp = player
if ((direction[0]+x)>=0 or (direction[1]+y)>=0 or (direction[0]+x)<=9 or (direction[1]+y)<=9) is True:
move_x,move_y=direction
x=x+move_x
y=y+move_y
else:
print('You hit a wall')
hp=hp-5
return x, y, hp
1 Answer

wayne ross
3,222 Pointsdef move(player, direction):
x, y, hp = player
if ((direction[0]+x)>=0 and (direction[1]+y)>=0 and (direction[0]+x)<=9 and (direction[1]+y)<=9) is True:
move_x,move_y=direction
x=x+move_x
y=y+move_y
else:
print('You hit a wall')
hp=hp-5
return x, y, hp
Grigorij Schleifer
10,352 PointsGrigorij Schleifer
10,352 PointsNice!!!!!
rmsmxxlwyt
Python Web Development Techdegree Student 7,597 Pointsrmsmxxlwyt
Python Web Development Techdegree Student 7,597 PointsThat worked, and another way of writing it: