Locked learning resources

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

Unlock This Lesson

Locked learning resources

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.

Avatar image for alex opoku

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

Avatar image for mvc1972parti01

mvc1972parti01 on Sept. 21, 2024

Please, I´ve tried and didn’t succeced in put emojis in my code. What I need to do? I´m working with a PC, with Windows.

Avatar image for mvc1972parti01

mvc1972parti01 on Sept. 21, 2024

Here is my code:

import random

heal_play=100
heal_mons=150
opt_play=""

while heal_play > 0 and heal_mons > 0:

    print("                              ")
    print("Welcome to the jungle, baby!")
    print("                              ")

    try:
       opt_play=input("What do you wanna do? A=attack, H=heal or R=run ? _")
    except KeyboardInterrupt:
       print("                              ")
       print("Se quiser parar, aperte 'R'")
       continue

    if opt_play.lower() == "a":
        point_attack=random.randint(10,15)
        print(f"point attack: {point_attack}")

        if point_attack%3==0:
            heal_mons=heal_mons-(point_attack*2)
            power_ataque = point_attack*2

        else:
            heal_mons = heal_mons - point_attack
            power_ataque = point_attack

        print(F"Força do seu ataque foi de {power_ataque}")
        print(F"Força do Monstro = {heal_mons}")

    elif opt_play.lower() == "h":
        heal_play = heal_play + 30

        if heal_play > 100:
            heal_play = 100
        print(F"Sua saúde está em = {heal_play}")    

    elif opt_play.lower() == "r":
        break

    else:
        continue

    monster_attack = random.randint(15,20)
    heal_play = heal_play - monster_attack
    print(F"Diminui sua energia em {monster_attack}")
    print(F"Sua saúde está em = {heal_play}")

print("GAMER OVER")
Avatar image for Martin Breuss

Martin Breuss RP Team on Sept. 23, 2024

@mvc1972parti01 you should be able to add emojis just like other text characters in between quotes, e.g.:

print("Welcome to the jungle, baby! 🐍")

I haven’t confirmed that on Windows, but there shouldn’t be any difference. Let me know what’s the issue you run into when you try.

Avatar image for roshny

roshny on Oct. 14, 2024

Really enjoyed learning. Code works but let me know if I’ve missed anything or if there’s any feedback.

import random


def player_move(player, monster):

    while True:
        try:
            move = input("🗡 Attack - a, 💚 Heal - h or 🏃 Run Away - r: ").lower()
            if move in ["a", "h", "r"]:
                break
            else:
                raise Exception
        except KeyboardInterrupt:
            print("❌ NO CAN DO...RUN (r) TO QUIT GAME!")
        except Exception:
            print("Invalid move..🤨")

    if move == "a":
        points = random.randint(10, 15)
        if points % 3 == 0:
            monster -= 2 * points
            print(f"Critical Attack😎! {2 * points}")
        else:
            monster -= points
            print(f"Attack! {points}")

    elif move == "h":
        player += 30
        print(f"Heal! +30")
        if player > 100:
            player = 100
            print("At Max health💯!")

    elif move == "r":
        print("Buhbye, Quitter!👋")
        exit()

    return player, monster


def monster_move(player):

    points = random.randint(15, 20)
    if points % 3 == 0:
        player -= points * 2
        print(f"💥Critical Damage!💥 -{2 * points}")
    else:
        player -= points
        print(f"Damage! -{points}")

    return player


def main():
    player = 100
    monster = 150

    print("\nWELCOME TO THE GAME\n")
    while player > 0 and monster > 0:
        print(f"Current Health: 👤 YOU {player}  🐲 MONSTER {monster}", end="\n\n")
        player, monster = player_move(player, monster)
        player = monster_move(player)
        if player <= 0:
            print("You Lose.💀", end=" ")
        elif monster <= 0:
            print("You Won.🏆", end=" ")
    print("GAME OVER!!!")


main()
Avatar image for Jerry Witherite

Jerry Witherite on Dec. 8, 2024

I am having the same trouble with putting emoji in idle. If i right click my only options are cut copy paste and set and clear breakpoints. I am running idle 3.13 on windows 11. is there a setting i do not know about?

Become a Member to join the conversation.