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 trialCatherine Grace de Leon
3,153 PointsCan't get past the dungeon game hit points challenge. Not sure what I'm getting wrong.
def move(player, direction): x, y, hp = player xd, yd = direction if x == 0 and xd -= 1: hp -= 5 xd = 0 if x == 9 and xd += 1: hp -= 5 xd = 9 if y == 0 and yd -= 1: hp -= 5 yd = 0 if y == 9 and yd += 1: hp -=5 yd = 9 return x, y, hp
# 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
xd, yd = direction
if x == 0 and xd -= 1:
hp -= 5
xd = 0
if x == 9 and xd += 1:
hp -= 5
xd = 9
if y == 0 and yd -= 1:
hp -= 5
yd = 0
if y == 9 and yd += 1:
hp -=5
yd = 9
return x, y, hp
1 Answer
Krishna Pratap Chouhan
15,203 Pointsif variable_name -= 1:
is not a valid conditional statement.
may be you meant.
if variable_name == -1:
If there is still a problem then...you probably are not considering all possible scenarios.
For example, in your first condition
if x == 0 and xd == -1:
Considers when the focus in on left border and xd(x_displacement) is towards left side(-1). Cant move, hit the wall and hitpoints reduce by 5. but what when the player in in center of the board and trying to move left.(when x>0)
Answer is: .
.
.
# 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
xd, yd = direction
if xd == -1:
if x == 0:
hp -= 5
xd = 0
else:
x = x-1
if xd == 1:
if x == 9:
hp -= 5
xd = 9
else:
x = x+1
if yd == -1:
if y == 0:
hp -= 5
yd = 0
else:
y = y-1
if yd == 1:
if y == 9:
hp -=5
yd = 9
else:
y = y+1
return x, y, hp
Catherine Grace de Leon
3,153 PointsCatherine Grace de Leon
3,153 PointsAh, that does make a lot more sense! Thank you so much! :)
Krishna Pratap Chouhan
15,203 PointsKrishna Pratap Chouhan
15,203 PointsGlad i could be of some help. Enjoy.