Add Win and Lose Conditions
00:00 So far, we only introduced one way to end the game, and that is the player decides to run away. This is working. But we have two other end conditions for the game.
00:09
One is that the health of the player reaches 0
, or the health of the monster reaches 0
. So, where would we introduce this? I would say where we’re attacking, right? So after an attack of the player, we can go and check. if monster_health <= 0:
the game ends.
00:31
So we’re going to break out of the loop and probably also keep being a bit descriptive. "You defeated the monster!"
Yay, congratulations! That means the person won the game. The player won the game.
00:46
And then the second condition will be if, after the attack of the monster, the player’s health is going to be below or at 0
. So, we’ll have to add the same condition again. I’m going to say if player_health <= 0:
then I’m going to print another message that reads something like "You were defeated by the monster!"
01:13
Exclamation mark because it’s a tragic event, of course. Oh yeah, and we’ve got to break. So, now we have three ways to end this loop. It’s an endless loop, but then we have three break
statements in here.
01:26
One is if the monster_health
goes below 0
, one is if you run away, and one is if your health goes below 0
. And each of those checks happen after the respective attacks of yourself and the monster. Looking good. Let’s try it out.
01:46
I want to attack. Attack. My health is 66
, the monster’s health is 124
. Okay, got to heal a little. Heal once more, and then let’s keep attacking.
02:00 Can I defeat this monster just with attacking? Oh, it’s getting close. Got to heal a bit. It’s a tough, it’s a tough monster, but I’m not going to run. I’m going to stick it out. Oh, health six. Whew.
02:17
Wow. We can, this is really a tough fight. Once the health—Can I do it? Attack. Attack the monster for 10
. You defeated the monster!
02:28 So, this essentially was the first real play-through of this little role-playing game. And you see that all the functionality is there. You actually did it and completed the challenge well, but there’s more, right?
02:43 Let’s stretch a bit and then go over to the stretch goals.
Become a Member to join the conversation.