def __init__(self): self.width = 3 self.height = 3 Deferrer.__init__(self) Dispatcher.__init__(self) self.data = util.make2dArray(self.width, self.height, None) self.curPlayer = 1
def __init__(self, state, canvas): self.canvas = canvas self.gui = Gui(canvas) self.setState(state, True) #per-slot background panels. These can change color. Good for decoration. self.backgroundPanels = util.make2dArray(state.width, state.height, None) for x in range(state.width): for y in range(state.height): sprite = makeRect(Point(*self.getCornerPos(x,y)), Point(*self.getCornerPos(x+1, y+1))) self.gui.add(sprite) self.backgroundPanels[x][y] = sprite
def setState(self, state, useFancyAnimations=True): #if we ever implement State::unregisterListener, unregister from the previous state if one exists self.state = state self.state.registerListener(self) self.gui.reset() #grid drawing is instantaneous if we don't use fancy animations animationTime = 0.0 if useFancyAnimations: animationTime = 1.0 self.gui.add(drawGridEvent(self.canvas, self.state.width-1, self.state.height-1, animationTime)) self.sprites = util.make2dArray(self.state.width,self.state.height, None) for x in range(self.state.width): for y in range(self.state.height): if state.get(x,y) != None: sprite = self.makePiece(state.get(x,y), x, y) self.sprites[x][y] = sprite self.gui.add(sprite)