Beispiel #1
0
    def run(self):
        """
            waits until enough players entered game and all of them are ready
            then starts main game loop
        :return: nothing
        """
        while not self.started:
            if self.killed:
                return

            players_with_ready_input = self.__select_players()
            for player in players_with_ready_input:
                try:
                    message = player.get_input()
                except Exception as msg:
                    print msg
                    controller.pressed_leave(self, player)
                    continue

                self.controller.serve_event(player, message['content'])

            for player in self.players:
                if not player.ready and player.arrival_time + self.TIMEOUT < time.time():
                    self.remove_player(player)
                    print 'Player ' + player.name + ' removed - waited too long.'

            if controller.can_start_game(self):
                self.started = True

        try:
            self.game.game_loop()
        except Exception as msg:
            print msg
        print 'Game ended'
Beispiel #2
0
    def run(self):
        """
            waits until enough players entered game and all of them are ready
            then starts main game loop
        :return: nothing
        """
        while not self.started:
            if self.killed:
                return

            players_with_ready_input = self.__select_players()
            for player in players_with_ready_input:
                try:
                    message = player.get_input()
                except Exception as msg:
                    print msg
                    controller.pressed_leave(self, player)
                    continue

                self.controller.serve_event(player, message['content'])

            for player in self.players:
                if not player.ready and player.arrival_time + self.TIMEOUT < time.time(
                ):
                    self.remove_player(player)
                    print 'Player ' + player.name + ' removed - waited too long.'

            if controller.can_start_game(self):
                self.started = True

        try:
            self.game.game_loop()
        except Exception as msg:
            print msg
        print 'Game ended'
Beispiel #3
0
 def notify_players(self, message=None):
     """
         notify observers
         sends message to all players containing game state
     :return: nothing
     """
     time.sleep(1)
     for player in self.players:
         try:
             if not player.leaving:
                 player.send(self.__dict(player, message))
         except socket.error:
             controller.pressed_leave(self, player)
             print 'Player ' + player.name + ' disconnected'
Beispiel #4
0
 def notify_players(self, message=None):
     """
         notify observers
         sends message to all players containing game state
     :return: nothing
     """
     time.sleep(1)
     for player in self.players:
         try:
             if not player.leaving:
                 player.send(self.__dict(player, message))
         except socket.error:
             controller.pressed_leave(self, player)
             print 'Player ' + player.name + ' disconnected'