forked from CodeMouse92/DeadSimplePython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_adventure_v2.py
More file actions
45 lines (34 loc) · 890 Bytes
/
text_adventure_v2.py
File metadata and controls
45 lines (34 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import functools
import random
character = "Sir Bob"
health = 15
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
eat_food("bread")
fight_monster("Imp", 15)
fight_monster("Direwolf", 15)
fight_monster("Minotaur", 19)