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 trial
sidni ahmed
3,329 Pointspart i dont understand in game.py
this is the player_turn function:
def player_turn(self):
player_choice = input("[A]ttack, [R]est or [Q]uit? ").lower()
if player_choice == 'a':
print("You are attacking {}!".format(self.monster))
if self.player.attack:
if self.monster.dodge():
print('{} dodged your attack!'.format(self.monster))
else:
if self.player.leveled_up():
self.monster.hit_points -= 2
else:
self.monster.hit_points -= 1
print('You hit {} with your {}'.format(
self.monster, self.player.weapon))
else:
print("you missed!")
elif player_choice == 'r':
self.player.rest()
elif player_choice == 'q':
sys.exit()
else:
self.player_turn()
what i do not get is the part when if the monster does not dodge, we call player.leveled_up(), why is this? Then the monster loses two hit points. Then after that, there's an option where the monster can lose one hit point. why can the monster lose two hit points and have another option to lose one hit point? what have i misunderstood here?
[MOD: added ```python markdown formatting -cf]
2 Answers
Chris Freeman
Treehouse Moderator 68,468 PointsThe logic goes: If the monster does not dodge (it gets hit) then decide it's damage. The monsters damage is determined by the "experience" of the player. If the player has more than 5 experience points (checked by player.leveled_up()) then monster takes 2 damage, otherwise only 1 damage. If the monster does dodge, then no damage is assessed and "You missed!" is printed. So there are there mutually exclusive out comes: "dodged", "not dodged, hit by experienced player, loses 2 point", "not dodged, hit by inexperienced player, loses 1 point"
Gina Scalpone
21,330 PointsIt's not really a Python question, that's just the way they decided to design the game.
sidni ahmed
3,329 Pointssidni ahmed
3,329 Pointsahhh! i get it! thanks for the responses guys. : )