-
Notifications
You must be signed in to change notification settings - Fork 236
/
hierarchical.py
85 lines (69 loc) · 2.26 KB
/
hierarchical.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
"""
hierarchical prompt usage example
"""
from PyInquirer import style_from_dict, prompt
from examples import custom_style_2
def ask_direction():
directions_prompt = {
'type': 'list',
'name': 'direction',
'message': 'Which direction would you like to go?',
'choices': ['Forward', 'Right', 'Left', 'Back']
}
answers = prompt.prompt(directions_prompt)
return answers['direction']
# TODO better to use while loop than recursion!
def main():
print('You find yourself in a small room, there is a door in front of you.')
exit_house()
def exit_house():
direction = ask_direction()
if (direction == 'Forward'):
print('You find yourself in a forest')
print('There is a wolf in front of you; a friendly looking dwarf to the right and an impasse to the left.')
encounter1()
else:
print('You cannot go that way. Try again')
exit_house()
def encounter1():
direction = ask_direction()
if (direction == 'Forward'):
print('You attempt to fight the wolf')
print('Theres a stick and some stones lying around you could use as a weapon')
encounter2b()
elif (direction == 'Right'):
print('You befriend the dwarf')
print('He helps you kill the wolf. You can now move forward')
encounter2a()
else:
print('You cannot go that way')
encounter1()
def encounter2a():
direction = ask_direction()
if direction == 'Forward':
output = 'You find a painted wooden sign that says:'
output += ' \n'
output += ' ____ _____ ____ _____ \n'
output += '(_ _)( _ )( _ \\( _ ) \n'
output += ' )( )(_)( )(_) ))(_)( \n'
output += ' (__) (_____)(____/(_____) \n'
print(output)
else:
print('You cannot go that way')
encounter2a()
def encounter2b():
prompt.prompt({
'type': 'list',
'name': 'weapon',
'message': 'Pick one',
'choices': [
'Use the stick',
'Grab a large rock',
'Try and make a run for it',
'Attack the wolf unarmed'
]
}, style=custom_style_2)
print('The wolf mauls you. You die. The end.')
if __name__ == '__main__':
main()