Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Improve the User Experience

00:00 The final stretch goal is to use emojis or string formatting syntax to make the game output more enjoyable. I’ve been thinking about that quite a bit because this waterfall of yellow text is kind of hard to keep track of.

00:15 You can use frameworks to make this look nicer, but in this case, I think I’m going to go down the emoji route and just add a bit of visual signposting of what’s going on.

00:28 Let’s give the critical hit an emoji crash.

00:35 That looks good for a critical hit. Then here we’ve got the health stats. Let’s put a heart there. What else do we have? Do you want to attack? That sounds good here. So, the KeyboardInterrupt, I’m kind of giving the user a message of something’s not working out, so I’m just going to put a red X there and then maybe I’ll set info if you really want to leave, and then here we are. So you attack, let’s put a little smiley face here, representing the player. And then when the monster attacks, we put in a—no, not a clap.

01:18 Let’s put in a dragon. That explains why it has so much health. What else do we have? Another invalid action, I’m going to put a red X, and then running away, a little—that sounds good, a little wave. What else do we have?

01:38 You were defeated, dead. And you healed, all sparkles. And you defeated the monster. Good job, you get a prize.

01:53 What I did is I just added emojis at the beginning of each of those lines to kind of visually help a little bit more in understanding what’s going on. And maybe that’s not enough, but I want to ahead and give it a try.

02:08 Restart. Your health. Okay, so that’s already easier for me to understand. Here’s the health stats. That’s good. I attack. You attacked the monster for 10. Monster attacked for 16. And then we’re back to the health stats.

02:22 How does healing look like? You healed for 30 health! Nice. Attack again. Oh, there you go. The monster’s again just scoring critical hits. This is pretty nice. This is easier for me to read, but what I’m still missing is a space between the different moves, because right now it’s still all mushed together.

02:43 I’m going do this at the beginning, after the health stats, I’m going to use the end keyword of the print() function, where I can change what a line ends after it prints out, and I’m going to do two newline characters.

03:00 The default is a single newline character, and we’re going to do two instead to just give that extra newline. Let’s try that again. Now I get the health stats, then there’s an empty line.

03:12 And now, okay, I can attack again. All right, so this looks better, I think. Let’s try a little more. I’m going to heal. Monster attacked with a critical hit again. Oh, finally!

03:26 This is the first critical hit I think that I scored, but this is much more readable than before. I’m pretty happy with that, actually. Let’s see what happens when I run. Okay, You ran away. That’s understandable. Start another round. Oh, I accidentally pressed an invalid action. That’s also understandable. Heal.

03:47 What if I do Ctrl + C? You can't quit the game. If you really want to leave, you'll need to run. I don’t really love the information symbol here, so I think I’m going to get rid of that.

04:02 Where is it? There.

04:08 What else can we try out? Winning or losing? Okay, let’s lose in this round. I’m just going to keep attacking and probably lose. There you go. You were defeated by the monster! and skull. That looks okay.

04:23 And let’s do one more round,

04:28 where I want to try out Ctrl + C again.

04:32 You can't quit. Okay, the error message. If you really want to leave, you need to run. Okay, that’s helpful. Great.

04:38 And now I’ve got to win a game to see that trophy. So that’ll be the hardest round so far, I guess. Attack, attack, attack. Got to heal. Heal back up. Oh dear, that’s a strong monster.

04:58 17. Whew. That’s quite a battle.

05:10 Okay, I think I got it. Ka-ching! You defeated the monster! and I got my prize. Great. So, I didn’t actually change much. All I did was introduce these little emojis at the beginning of each print line, but it really helps in orienting the user on what’s happening, what type of turn is currently happening. Is it your turn?

05:31 Is this is something that the user did? Is it something that the monster did? Is this just some stats at the end of the round? And then also, what’s an invalid action? What’s a win condition? What’s a lose condition?

05:43 And also, what’s a special action? So, the critical hit also got its own symbol. I guess this is just a little bit of user interface improvements. And you could have done this differently too.

05:54 You could have used some string formatting syntax to maybe move it a bit or add some padding here or there. Yeah, there’s multiple ways to make this look nice.

06:05 If you did polish your game up nicely or implemented some other functionality, then please share your game in the comments in the discussion tab. I’m looking forward to checking it out.

alex opoku on Oct. 4, 2023

I have completed the challenge and bleow is my code

# Rolle Playing Game
print("Hello welcome to  the role playing game", end ="\n\n")

import random

player_health = 100
monster_health  = 150
heal = 30

while True:
    print(f"Health Status: Player= {player_health}, Monster= 
    {monster_health}", end ="\n\n")

    if monster_health > 0 and player_health > 0:
        try:
            player_strategy = input("Enter a to ATTACK, h to HEAL 
            and r to RUN AWAY:")
        except KeyboardInterrupt:
            print("You can't quit by pressing Ctrl+C. Run away  
            intead")
            continue
        monster_attack_value = random.randint(15,20)

        # Player's turn
        if player_strategy.lower() == "a":
            player_attack_value = random.randint(10,15)

            if player_attack_value % 3 == 0:
                monster_health = monster_health - 2 * 
                player_attack_value
                print(f"Yippee !!! You dealt monster critical damage 
                of {2 * player_attack_value}")
            else:
                monster_health = monster_health - 
                player_attack_value
                print(f"Good strike!!! Monster is dealt a damage of 
                {player_attack_value}")

        elif player_strategy.lower() == "h":

            if player_health >= 70:
                player_health = 100
            else:
                player_health = player_health + heal

        elif player_strategy.lower() == "r":
            player_health = 0
        else:
            continue


        # Monster's turn        
        if monster_attack_value % 3 == 0:
            player_health = player_health - 2 * monster_attack_value
            print(f"Oh what a monsterious blow, monster caused a 
            damage of {2 * monster_attack_value}")
        else:
            player_health = player_health - monster_attack_value
            print(f"What a blow from the monster, causing you5 a 
            damage of {monster_attack_value}")




    else:
        if player_health > 0:
            print(f"Yippee!!! You've won with {player_health} 
            points")
        else:
            print("What a defeat from the monster!")
        break

I coudn’t add the emojis. Your comments please

Become a Member to join the conversation.