-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
50 lines (35 loc) · 1.09 KB
/
player.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
import pprint
import creator
from Node import Node
def print_description(current):
print(f'<<<{current.title}>>>\n')
print(current.text + '\n')
for i, nextNode in enumerate(current.get_possible_outgoing()):
print(f'[{i}] {nextNode[1]}')
def cli_player(game):
current: Node = game.beginning()
while True:
current.update_state()
print_description(current)
if game.is_ending(current):
return # Maybe ask: restart/exit/...
choice = input('>> ')
if not choice:
choice = 0
if choice == 'exit':
return
if choice == 'vars':
pprint.pprint(current.store.variables)
continue
try:
current = current.take_outgoing(
current.get_possible_outgoing()[int(choice)][0])
except Exception:
print('ERROR: unknown command')
continue
def load_story(path: str = 'story.sgf'): # StoryGraphFile
return creator.create_test_story()
def main():
cli_player(load_story())
if __name__ == '__main__':
main()