-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlocal.py
executable file
·60 lines (51 loc) · 1.2 KB
/
local.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
import time
from targetIo import *
from string import lower
from games import Game, GameManager
from jsonTargets import *
from server import *
class LocalGame:
'''
Handles the local interaction with a user
'''
def isQuitCommand(self, command):
x = {"q": True,
"quit": True}
if (x.has_key(command)):
return x[command]
return False
def notify(self, targets):
message = ConvertTargetsToJson(targets)
print message
def start(self, path):
'''
Runs a local game
'''
totalTime = 2 * 60
# read in the tests
gameManager = GameManager()
games = gameManager.readGames(path, totalTime)
# then run
isQuit = False
proc = TargetIo()
while(not isQuit):
print "-"*60
print gameManager
print "-"*60
command = raw_input("Command: [type game name to start] ")
command = lower(command)
isQuit = self.isQuitCommand(command)
if (not isQuit):
if (gameManager.hasGame(command)):
print
print " >> Starting game."
print
proc.run(games[command], self.notify)
time.sleep(5)
else:
print
print ">> That game does not exist."
print
if (__name__ == "__main__"):
game = LocalGame()
game.start("./games")