예제 #1
0
 def draw_clear(client, clients):
     other_clients = filter(
         lambda u: id(u) != id(client),
         RoomTool.room_clients(clients,
                               UserTool.current_user(client)['r_id']))
     Packet(header='draw.clear', data=None,
            msg=None).write_message_to(clients=other_clients)
예제 #2
0
    def chess_win(client, clients, i, j, army_type):
        room_id = UserTool.current_user(client)['r_id']
        room_clients = RoomTool.room_clients(clients, room_id)
        other_client = filter(lambda u: id(u) != id(client), room_clients)
        Packet(header='chess.down',
               data={
                   'i': i,
                   'j': j,
                   'army_type': army_type
               },
               msg=None).write_message_to(clients=other_client)
        Packet(header='chess.over', data=None,
               msg=None).write_message_to(clients=room_clients)

        army = u'白色方' if army_type == 'white' else u'黑色方'
        gm_say(u'%s获胜啦 5s后游戏结束' % army, room_clients)

        def game_over():
            room = RoomTool.game_over(room_clients, room_id)
            time.sleep(5)
            Packet(header='rooms.info', data=room,
                   msg=None).write_message_to(clients=clients)

        p = threading.Thread(target=game_over)
        p.start()
예제 #3
0
    def draw_start(data, client, clients):
        color, weight = data.get('color', None), data.get('weight', None)

        other_clients = filter(
            lambda u: id(u) != id(client),
            RoomTool.room_clients(clients,
                                  UserTool.current_user(client)['r_id']))

        Packet(header='draw.begin', data={'color': color, 'weight': weight}, msg=None). \
            write_message_to(clients=other_clients)
예제 #4
0
    def begin(room, clients):
        r_id = int(room['r_id'])
        room_clients = RoomTool.room_clients(clients, r_id)
        room_user = DrawHandler.begin_game(room_clients, r_id, True)
        room, current_user, other_clients = room_user['room'], room_user[
            'user'], room_user['other_clients']

        Packet(header='rooms.begin', data=room,
               msg=None).write_message_to(clients=clients)
        gm_say(u'游戏开始啦, 由 %s 先开始' % current_user['rolename'], room_clients)
        DrawHandler.send_tips(current_user, other_clients)
예제 #5
0
    def say_room(self, data):
        message, r_id = data.get('message', None), data.get('room_id', None)
        clients = RoomTool.room_clients(self.clients, r_id)

        topic = self.draw_handler.current_topic(r_id)

        user = UserTool.current_user(self.client)

        if topic is not None:
            self.draw_handler.judge(self.client, self.clients, topic, user, message)
        else:
            say(self.client, message, clients, 'rooms.message')
예제 #6
0
 def draw_move(data, client, clients):
     x, y, width, height, r_id = (data.get('x', None), data.get('y', None),
                                  data.get('width',
                                           None), data.get('height', None),
                                  data.get('room_id', None))
     other_clients = filter(lambda u: id(u) != id(client),
                            RoomTool.room_clients(clients, r_id))
     x_r, y_r = float(x) / width, float(y) / height
     Packet(header='draw.move', data={
         'x': x_r,
         'y': y_r
     }, msg=None).write_message_to(clients=other_clients)
예제 #7
0
    def begin(room, clients):
        r_id = int(room['r_id'])
        room_clients = RoomTool.room_clients(clients, r_id)
        games = ChessHandler.begin_game(room_clients, r_id, True)
        room, current_user, begin_client = games['room'], games['user'], games[
            'begin_client']

        Packet(header='rooms.begin', data=room,
               msg=None).write_message_to(clients=clients)
        gm_say(u'游戏开始啦, 由黑色方 %s 先出手' % current_user['rolename'], room_clients)
        if begin_client:
            Packet(header='rooms.turned', data=room,
                   msg=None).write_message_to(begin_client)
예제 #8
0
    def chess_down(client, clients, i, j, army_type):
        other_client = filter(
            lambda u: id(u) != id(client),
            RoomTool.room_clients(clients,
                                  UserTool.current_user(client)['r_id']))
        Packet(header='chess.down',
               data={
                   'i': i,
                   'j': j,
                   'army_type': army_type
               },
               msg=None).write_message_to(clients=other_client)

        ChessHandler.next_begin(client, clients)
예제 #9
0
    def next_begin(client, clients):
        r_id = UserTool.current_user(client)['r_id']
        room_clients = RoomTool.room_clients(clients, r_id)
        games = ChessHandler.begin_game(room_clients, r_id)
        room, current_user, army, begin_client = games['room'], games[
            'user'], games['army'], games['begin_client']

        # RoomTool.update_room(r_id, cantip=False)

        Packet(header='rooms.next', data=room,
               msg=None).write_message_to(clients=clients)
        gm_say(u'接下去由%s %s 出手' % (army, current_user['rolename']),
               room_clients)
        if begin_client is not None:
            Packet(header='rooms.turned', data=None,
                   msg=None).write_message_to(begin_client)
예제 #10
0
    def next_begin(client, clients):
        r_id = UserTool.current_user(client)['r_id']
        room_clients = RoomTool.room_clients(clients, r_id)
        games = DrawHandler.begin_game(room_clients, r_id)
        room, current_user, over, other_clients = games['room'], games[
            'user'], games['over'], games['other_clients']

        RoomTool.update_room(r_id, cantip=False)

        if over:
            Packet(header='rooms.info', data=room,
                   msg=None).write_message_to(clients=clients)
            gm_say('本局游戏结束啦', room_clients)
        else:
            Packet(header='rooms.next', data=room,
                   msg=None).write_message_to(clients=clients)
            gm_say(u'接下去由 %s 作画' % current_user['rolename'], room_clients)

            DrawHandler.send_tips(current_user, other_clients)