forked from CodeMouse92/DeadSimplePython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_adventure_v1.py
More file actions
43 lines (32 loc) · 930 Bytes
/
text_adventure_v1.py
File metadata and controls
43 lines (32 loc) · 930 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
import random
health = 10
xp = 10
def attempt(action, min_roll, outcome):
global health, xp
roll = random.randint(1, 20)
if roll >= min_roll:
print(f"{action} SUCCEEDED.")
result = True
else:
print(f"{action} FAILED.")
result = False
scores = outcome(result)
health = health + scores[0]
print(f"Health is now {health}")
xp = xp + scores[1]
print(f"Experience is now {xp}")
return result
# def eat_bread(success):
# if success:
# return (1, 0)
# return (-1, 0)
# def fight_ice_weasel(success):
# if success:
# return (0, 10)
# return (-10, 10)
# attempt("Eating bread", 5, eat_bread)
# attempt("Fighting ice weasel", 15, fight_ice_weasel)
attempt("Eating bread", 5,
lambda success: (1, 0) if success else (-1, 0))
attempt("Fighting ice weasel", 15,
lambda success: (0, 10) if success else (-10, 10))