Exemplo n.º 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)
Exemplo n.º 2
0
        def __init__(self, parent):
            self._parent = parent
            Pane.__init__(self)
            self._clientcon = ClientConnection()
            self.x = MENUPOS[0]
            self.y = MENUPOS[1]
            self.width = MENUSIZE[0]
            self.height = MENUSIZE[1]

            DEBUG_NAME = "Test Game"

            self.add(Label("NEW NETWORK GAME", pos=(160, 1)))
            self.add(Label("Name", pos=(MENUPAD[0], MENUPAD[2])))
            self.i_name = self.add(
                Entry(DEBUG_NAME,
                      pos=(MENUPAD[0] + 140, MENUPAD[2]),
                      size=(220, 10)))
            self.add(
                Label("Number of Players", pos=(MENUPAD[0], MENUPAD[2] + 25)))
            self.i_num = self.add(
                Entry("3",
                      pos=(MENUPAD[0] + 140, MENUPAD[2] + 25),
                      size=(40, 10)))
            self.add(Label("Map", pos=(MENUPAD[0] + 160, MENUPAD[2] + 50)))
            self.s_maps = self.add(
                SelList([],
                        pos=(MENUPAD[0], MENUPAD[2] + 75),
                        size=(MENUSIZE[0] - MENUPAD[2] - 5, 150)))
            self.add(
                Button("Ok",
                       self._ok,
                       pos=(MENUPAD[0], MENUSIZE[1] - MENUPAD[3] - 20),
                       size=(100, 12)))
            self.add(
                Button("Cancel",
                       self._cancel,
                       pos=(MENUSIZE[0] - 120, MENUSIZE[1] - MENUPAD[3] - 20),
                       size=(100, 12)))

            self._mapStore = MapStore()
            self._refreshMaps()
Exemplo n.º 3
0
    def __init__(self, parent, gcli):
        Pane.__init__(self)
        self._widgetClickers = dict()
        self._parent = parent
        self._gcli = gcli
        self.x = MENUPOS[0]
        self.y = MENUPOS[1]
        self.width = MENUSIZE[0]
        self.height = MENUSIZE[1]
        self._clientcon = ClientConnection()
        self._mapStore = MapStore()

        server = self._clientcon.address
        port = self._clientcon.port

        # Connection
        self.add(Label("NETWORK GAME", pos=(160, 1)))
        self.add(Label("Server:", pos=(MENUPAD[0], MENUPAD[2])))
        self.i_server = self.add(
            Entry(server, pos=(MENUPAD[0] + 65, MENUPAD[2]), size=(120, 10)))
        self.add(Label("Port:", pos=(MENUPAD[0] + 200, MENUPAD[2])))
        self.i_port = self.add(
            Entry(port, pos=(MENUPAD[0] + 265, MENUPAD[2]), size=(120, 10)))
        self.add(Label("Username:"******"Password:"******"Connect",
                   self._connect,
                   pos=(MENUSIZE[0] - 90, MENUPAD[2] + 50),
                   size=(70, 12)))

        self.s_games = self.add(
            SelList([],
                    pos=(MENUPAD[0], MENUPAD[2] + 75),
                    size=(MENUSIZE[0] - MENUPAD[2] - 5, 150)))

        self.b_create = self.add(
            Button("Create Game",
                   self._create,
                   pos=(MENUPAD[0], MENUSIZE[1] - MENUPAD[3] - 45),
                   size=(100, 12)))
        self._disable(self.b_create)

        self.add(
            Button("Join Game",
                   self._join,
                   pos=(MENUSIZE[0] - MENUPAD[1] - 95,
                        MENUSIZE[1] - MENUPAD[3] - 45),
                   size=(100, 12)))

        self.add(
            Button("Main Menu",
                   parent.showMain,
                   pos=(MENUPAD[0], MENUSIZE[1] - MENUPAD[3] - 20),
                   size=(100, 12)))

        if self._clientcon.isAuthorized():
            self._setConnected()