def __init__(self, trainer, zone, row, column, doneCallback=None): """ Initialize the Zone Controller """ self.zone = zone self.doneCallback = doneCallback self.zone.setCallbacks(self.handleZoneEvents) self.playerPerson = TrainerPerson(self.zone.tiles[row][column], "trainer", trainer, causeEnterEvents=True) screen = ZoneScreen(self.playerPerson, self.zone) cmds = {commands.UP:self.playerPerson.up, (commands.UP, RELEASED):self.playerPerson.stopMovingUp, commands.DOWN:self.playerPerson.down, (commands.DOWN, RELEASED):self.playerPerson.stopMovingDown, commands.LEFT:self.playerPerson.left, (commands.LEFT, RELEASED):self.playerPerson.stopMovingLeft, commands.RIGHT:self.playerPerson.right, (commands.RIGHT, RELEASED):self.playerPerson.stopMovingRight, commands.SELECT:self.select, commands.EXIT:self.runZoneMenu} PygameController.__init__(self, screen, commands=cmds)
def LoadPerson(element, tiles): """ Load a Person from a Person XML Element """ row, column = LoadPosition(element) tile = tiles[row][column] message = element.findtext(Tags.messageTag) imageFilename = element.findtext(Tags.imageTag) if element.find(Tags.trainerTag) is not None: trainer = LoadTrainer(element) return TrainerPerson(tile, imageFilename, trainer, PersonInteractionDelegate(message)) else: return Person(tile, imageFilename, PersonInteractionDelegate(message))
class ZoneController(PygameController): """ Controller for a Zone """ def __init__(self, trainer, zone, row, column, doneCallback=None): """ Initialize the Zone Controller """ self.zone = zone self.doneCallback = doneCallback self.zone.setCallbacks(self.handleZoneEvents) self.playerPerson = TrainerPerson(self.zone.tiles[row][column], "trainer", trainer, causeEnterEvents=True) screen = ZoneScreen(self.playerPerson, self.zone) cmds = {commands.UP:self.playerPerson.up, (commands.UP, RELEASED):self.playerPerson.stopMovingUp, commands.DOWN:self.playerPerson.down, (commands.DOWN, RELEASED):self.playerPerson.stopMovingDown, commands.LEFT:self.playerPerson.left, (commands.LEFT, RELEASED):self.playerPerson.stopMovingLeft, commands.RIGHT:self.playerPerson.right, (commands.RIGHT, RELEASED):self.playerPerson.stopMovingRight, commands.SELECT:self.select, commands.EXIT:self.runZoneMenu} PygameController.__init__(self, screen, commands=cmds) def select(self): """ Performs a Select """ self.playerPerson.interactWithAdjacentTile() def runZoneMenu(self): """ Run the Zone Menu """ self.runController(ZoneMenuController(self)) def handleZoneEvents(self, events): """ Handle Zone Events """ PerformEvents(deque(events), self) if self.doneCallback is not None and self.doneCallback(): self.stopRunning() def performGameCycle(self): """ Move the Trainer if needed in this tick """ self.playerPerson.performGameTick() def setupZone(self, zone, row, column): """ Setup the current zone """ self.zone = zone self.zone.setCallbacks(self.handleZoneEvents) self.playerPerson.setTile(self.zone.tiles[row][column]) self.screen.playerPerson = self.playerPerson self.screen.zone = self.zone self.commands[commands.UP] = self.playerPerson.up self.commands[(commands.UP, RELEASED)] = self.playerPerson.stopMovingUp self.commands[commands.DOWN] = self.playerPerson.down self.commands[(commands.DOWN, RELEASED)] = self.playerPerson.stopMovingDown self.commands[commands.LEFT] = self.playerPerson.left self.commands[(commands.LEFT, RELEASED)] = self.playerPerson.stopMovingLeft self.commands[commands.RIGHT] = self.playerPerson.right self.commands[(commands.RIGHT, RELEASED)] = self.playerPerson.stopMovingRight