Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import functools
- from time import sleep
- character = "Sir Bob"
- health = 14
- xp = 0
- def character_action(func):
- @functools.wraps(func)
- def wrapper(*args, **kwargs):
- if health <= 0:
- print(f"{character} is too weak.")
- return
- result = func(*args, **kwargs)
- print(f" Health: {health} | XP: {xp}")
- return result
- return wrapper
- @character_action
- def eat_food(food):
- global health
- print(f"{character} ate {food}.")
- health += 1
- @character_action
- def fight_monster(monster, strength):
- global health, xp
- if random.randint(1, 20) >= strength:
- print(f"{character} defeated {monster}.")
- xp += 10
- else:
- print(f"{character} flees from {monster}.")
- health -= 10
- xp += 5
- def pause(how_long):
- for i in range(3):
- print(".", end="", flush=True)
- sleep(how_long)
- print()
- print("Eating...")
- pause(1)
- eat_food("bread")
- print("Fight with Imp")
- pause(1)
- fight_monster("Imp", 15)
- print("Fight with Direwolf")
- pause(1)
- fight_monster("Direwolf",15)
- print("Fight with Minotaur")
- pause(1)
- fight_monster("Minotaur",19)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement