Exemple #1
0
    def startGame(self, level=None):
        db = mapLayout.LayoutDatabase(pathGetter=self.theme.getPath,
                                      blocks=self.mapBlocks)
        gameType = 'solo'
        self.game = game = LocalGame(
            db,
            self.size[0],
            self.size[1],
            onceOnly=True,
            blockRatio=self.blockRatio,
            duration=self.duration * 60,
            level=level,
            gameType=gameType,
        )
        if self.testMode:
            game.world.setTestMode()

        self.ais[:] = []

        try:
            for i in range(self.aiCount):
                if self.stackTeams:
                    ai = game.addBot(self.aiClass, team=game.world.teams[0])
                else:
                    ai = game.addBot(self.aiClass)
                self.ais.append(ai)
        except ImportError:
            print('AI module not found: %s' % (self.aiClass, ),
                  file=sys.stderr)
            sys.exit(1)
        except AttributeError:
            print(
                ('AI module does not define BotClass: %s' % (self.aiClass, )),
                file=sys.stderr)
            sys.exit(1)

        # Create a client and an interface.
        if self.isolate:
            rgame = RemoteGame(db)
            hub = LocalHub(game)
            self.tweener = UIMsgThrottler()
            if self.delay:
                delayer = DelayNodeHub(self.delay)
                hub.connectNode(delayer)
                delayer.connectNode(self.tweener)
            else:
                hub.connectNode(self.tweener)
            self.tweener.connectNode(rgame)
            self.rgame = rgame
            rgame.connected(game.world.dumpEverything())
            self.uiAgent = agent = PandaUIAgent(self, rgame)
        else:
            self.tweener = LocalGameTweener(game)
            self.uiAgent = agent = PandaUIAgent(self, game)
        agent.onDisconnectRequest.addListener(self.stop)
        agent.onConnectionLost.addListener(self.stop)

        agent.show()
    def connectedToGame(self, trosnothClient, settings, authTag):
        self.trosnothClient = trosnothClient
        trosnothClient.onConnectionLost.addListener(self._connectionLost)

        self.game = game = RemoteGame(self.app.layoutDatabase)
        self.app.tweener = UIMsgThrottler()
        self.trosnothClient.connectNode(self.app.tweener)
        self.app.tweener.connectNode(game)

        game.connected(settings)
        self.onGameOpened(game, authTag)
Exemple #3
0
    def connectionEstablished(self, settings, authTag=0):
        'Called when this client establishes a connection to a server.'
        self.trosnothClient.onConnectionLost.addListener(self.connectionLost)

        game = RemoteGame(self.app.layoutDatabase)
        self.app.tweener = UIMsgThrottler()
        self.trosnothClient.connectNode(self.app.tweener)
        self.app.tweener.connectNode(game)

        game.connected(settings)
        self.setupGame(game, authTag, local=False)

        self.game = game
        self.elements = [self.gi]
Exemple #4
0
    def connectToReplay(self, filename):
        self.trosnothClient = player = replays.ReplayPlayer(filename)

        game = RemoteGame(self.app.layoutDatabase)
        self.app.tweener = UIMsgThrottler()

        player.connectNode(self.app.tweener)
        self.app.tweener.connectNode(game)

        game.connected(player.popSettings())
        self.setupReplay(game)
        player.start()

        self.game = game
        self.elements = [self.gi]
    def openReplay(self, filename):
        if self.game is not None:
            raise RuntimeError('Already displaying a game')

        self.trosnothClient = replayer = replays.ReplayPlayer(filename)

        self.game = game = RemoteGame(self.app.layoutDatabase)
        self.app.tweener = UIMsgThrottler()

        replayer.connectNode(self.app.tweener)
        self.app.tweener.connectNode(game)

        game.connected(replayer.popSettings())
        replayer.start()

        self.onReplayOpened(game)