-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
79 lines (68 loc) · 2.85 KB
/
app.py
File metadata and controls
79 lines (68 loc) · 2.85 KB
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
import argparse
import logging
import os
# Code block executed if the program is 'run'
if __name__ == "__main__":
# Extract any arguments passed to the app
parser = argparse.ArgumentParser()
parser.add_argument('--gui',
dest='usegui',
default=False,
action='store_true',
help="Use the GUI interface to the game")
parser.add_argument('--debug',
dest='debugon',
default=False,
action='store_true',
help="Enable debugging.")
parser.add_argument('--log-format',
dest='logformat',
type=str,
default="%(asctime)s %(levelname)s: %(message)s",
help="Set the Python logging format")
parser.add_argument('--server',
dest='cowbull_server',
default='localhost',
type=str,
help="The name of the cowbull game server, defaults to localhost"
)
parser.add_argument('--port',
dest='cowbull_port',
default=5000,
type=int,
help="The port used to serve the cowbull game server, defaults to 5000"
)
parser.add_argument('--game-version',
dest='cowbull_version',
default="v1",
type=str,
help="The cowbull game server version, defaults to v1"
)
args = parser.parse_args()
# Set the environment variables to the arg values
# only *IF* they are not already set. If set, env.
# vars. take priority
if not os.getenv("cowbull_server", None):
os.environ["cowbull_server"] = args.cowbull_server
if not os.getenv("cowbull_port", None):
os.environ["cowbull_port"] = str(args.cowbull_port)
if not os.getenv("cowbull_version", None):
os.environ["cowbull_version"] = args.cowbull_version
# Decide if using ANSI or GUI
if args.usegui:
from Views.TkView import TkView as IO
from Controllers.GUIController import GUIController as GameController
else:
from Views.ConsoleView import ConsoleView as IO
from Controllers.ConsoleController import ConsoleController as GameController
# Configure logging.
if args.debugon:
logging.basicConfig(format=args.logformat, level=logging.DEBUG)
else:
logging.basicConfig(format=args.logformat, level=logging.INFO)
# Create an Input/Output object
io = IO()
# Initiate the controller passing the TerminalIO and Helper objects
c = GameController(io_controller=io)
# Play the game
c.play()