示例#1
0
    def work(self):
        def sr(x):
            return str(round(x))
        running = True
        while  running:
            if not self.manag_que.empty():
                if self.manag_que.get() == 'stop':
                    running = False
            start_time = time.time()
            while not self.mess_queue.empty():
                r_msg = self.mess_queue.get() 
                self.proceed_mess(r_msg)

            players_frags = []
            for player_name , player in self.logged_players.items():
                players_frags +=[player_name, str(player.frags)]

            for player_name, player in self.logged_players.items():
                [x,y] = player.coord
                [m1, m2, m3] = player.magic
                invent = []
                for item in player.inventory:
                    if item.obj_type == 'armor':
                        invent += ['armor'] + [sr(x) for x in item.action]
                    else:
                        invent += [item.obj_type] + [sr(x) for x in item.magic]
                player_info = [sr(item) for item in (x,y,m1,m2,m3)] + invent
                net.send_message_to(self.messenger, player_name, player_info +['lim'] + self.gameitems + ['lim'] + players_frags)
            passed_time = time.time() - start_time
            if passed_time < REFRESH_TIME:
                time.sleep(REFRESH_TIME - passed_time)

        self.messenger.runn = False
示例#2
0
 def proceed_mess(self, message):
     # message = ['comand', 'name', 'arguments']
     if message[0] == 'join_game':
         name, password = message[1], message[2]       
         if name in self.all_players:
             if password == self.all_players[name][0]:
                 self.logged_players[name] = self.all_players[name][1]
                 self.game.spawner.spawn(self.logged_players[name])
                 game_info = [str(self.game.field_size[0]), str(self.game.field_size[1])]
                 net.send_message_to(self.messenger, name, game_info)
         else:
             self.all_players[name] = [password, main_objects.Player()]
             self.logged_players[name] = self.all_players[name][1]
             self.game.spawner.spawn(self.logged_players[name])
             game_info = [str(self.game.field_size[0]), str(self.game.field_size[1])]
             net.send_message_to(self.messenger, name, game_info)
     else:
         if message[0] in self.logged_players:
             self.exec_mess(self.logged_players[message[0]], message)
         else:
             net.send_message_to(self.messenger, message[0], ['not_logged'])