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()
def judge(client, clients, topic, user, message): if DrawHandler.judge_draw_result(topic, message): # self.next_begin() Packet(header='rooms.willnext', data=10, msg=None).write_message_to(clients=clients) gm_say(u'%s 猜对啦, 时间调整为10秒' % user['rolename'], clients) else: say(client, message, clients, 'rooms.message')
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)
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)
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)
def enter_room(self, data): room_id, p_id = data.get('room_id', None), data.get('p_id', None) # 1 get room room = RoomTool.enter_room(self.client, room_id, p_id) room_id = room["r_id"] Packet(header='rooms.info', data=room, msg=None).write_message_to(clients=self.clients) Packet(header='rooms.enter', data=room_id, msg=None).write_message_to(self.client) if room['game_type'] == 'draw': gm_say('欢迎来到聚会玩, 该房间将开启的游戏是 - 你画我猜', client=self.client) elif room['game_type'] == 'chess': gm_say('欢迎来到聚会玩, 该房间将开启的游戏是 - 五子棋', client=self.client) gm_say('游戏规则 - 上方为白色方 下方为黑色方, 黑色方先出棋, 黑色方选手下完轮到白色方, 如此交替进行', client=self.client) else: gm_say('欢迎来到聚会玩, 该房间将开启的游戏是 - UNO棋牌', client=self.client) gm_say('游戏规则 - ')
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)
def send_tips(current_user, other_clients): tips = current_user['topic']['tips'] for tip in tips: gm_say('偷偷给你个提示: %s' % tip, other_clients)