/
GameController.py
44 lines (35 loc) · 1.43 KB
/
GameController.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
from man import comm
from . import NogginConstants as Constants
from . import GameStates
from .util import FSA
class GameController(FSA.FSA):
def __init__(self, brain):
FSA.FSA.__init__(self,brain)
self.brain = brain
self.gc = brain.comm.gc
#jf- self.setTimeFunction(self.brain.nao.getSimulatedTime)
self.addStates(noggin.GameStates)
self.currentState = 'gameInitial'
self.setName('GameController')
self.setPrintStateChanges(True)
self.setPrintFunction(self.brain.out.printf)
def run(self):
if self.gc.state == comm.STATE_INITIAL:
self.switchTo('gameInitial')
elif self.gc.state == comm.STATE_SET:
self.switchTo('gameSet')
elif self.gc.state == comm.STATE_READY:
self.switchTo('gameReady')
elif self.gc.state == comm.STATE_PLAYING:
if self.gc.penalty != comm.PENALTY_NONE:
self.switchTo("gamePenalized")
else:
self.switchTo("gamePlaying")
elif self.gc.state == comm.STATE_FINISHED:
self.switchTo('gameFinished')
#Set team color
if self.gc.color != self.brain.my.teamColor:
self.brain.my.teamColor = self.gc.color
self.brain.makeFieldObjectsRelative()
print "Switching team color to ",Constants.teamColorDict[self.brain.my.teamColor]
FSA.FSA.run(self)