Пример #1
0
    def __init__(self):
        import __builtin__
        __builtin__.LOG = LogConsole()

        print("Starting PSG Client ...")

        # Initialize event dispatcher
        self._dispatcher = Event.Dispatcher()
        self._dispatcher.register(self, 'E_StartGame', self.startGame)
        self._dispatcher.register(self, 'E_ExitGame', self.exitGame)
        self._dispatcher.register(self, 'E_ExitProgram', self.exitProgram)

        # Create server connection object
        self.clientconnection = ClientConnection()

        # Load settings
        self.gst = GameSettings()
        self.gst.loadSettings()

        self._mapStore = MapStore()

        # If AUTOSERVER is set automatically connect and start a game with the
        # local server
        #if (AUTOSERVER):
        #	def connResp(status):
        #		if status:
        #			# Authenticate
        #			self.clientconnection.authenticate('autoserver','password1', authResp)
        #		else:
        #			LOG.error("[GameClient] Could not autoconnect <%s>"%status)
        #	def authResp(status):
        #		if (status == 3):
        #			self.clientconnection.newGame("debug game", mapDict['id'], "3", newResp)
        #		else:
        #			LOG.error("[GameClient] Could not autoauthenticate <%s>"%status)
        #	def newResp(status):
        #		if status > 0:
        #			self.clientconnection.joinGame(status, joinResp)
        #		else:
        #			LOG.error("[GameClient] Could not automatically create a game <%s>"%status)
        #	def joinResp(status, mapMD5):
        #		if status == 2:
        #			Event.Dispatcher().broadcast(Event.Event('E_StartGame', src=self, data=mapMD5))
        #		else:
        #			LOG.error("[GameClient] Could not autojoin <%s>"%status)
        #	# Use the debug map
        #	mapDict = self._mapStore.getMap(name="Debugger Map")
        #	# Connect
        #	self.clientconnection.connect('localhost', 9091, 3000, connResp)
        if NOSERVER:
            mapDict = self._mapStore.getMap(name="Debugger Map")
            print(mapDict)
            Event.Dispatcher().broadcast(
                Event.Event('E_StartGame', src=self, data=mapDict['id']))
        # Otherwise start menu GUI normally
        else:
            self.gui = Gui(Keys(), theme=RTheme())
            self.menu = MainScreen(self)
Пример #2
0
 def exitGame(self, event):
     ''' Clean up open/running game. Show mainmenu.'''
     LOG.debug("[GameClient] Exiting game")
     self.gui = Gui(Keys(), theme=RTheme())
     self.menu = MainScreen(self)