-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
52 lines (40 loc) · 1.48 KB
/
game.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
import time, sys
from classes.parser import regex_imperative
from classes.handlers import route_imperative
from classes.context import gen_context
from website_utils.utils import my_print, my_input, server_context
context = gen_context(sys.argv[1])
# Meant for playing on console - really just to easily design & debug
def local_game():
context.map[context.current_loc].print_surroundings()
# Game loop
while True:
# Gather input from player
command = input("> ")
imp = regex_imperative(context, command)
# Route imperative if something was given
if imp:
route_imperative(imp, context)
print('')
else:
my_print("des", "I beg your pardon?")
print('')
# Game for the webserver
def server_game():
context.map[context.current_loc].print_surroundings()
# Game loop
while True:
# Gather input from server
my_print("des", "") # one newline
command = my_input("> ")
imp = regex_imperative(context, command)
# Route imperative if something was given
if imp:
route_imperative(imp, context)
# Update server context metainfo
server_context.current_loc = context.map[context.current_loc].brief
server_context.moves += 1
else:
my_print("des", "I beg your pardon?")
# Break the barrier so the html file can be rendered properly
server_context.html_barrier.wait()