def join_from_list_of_games(self): self.window_manager("Join Game") try: item = self.game_list.curselection() item = [self.list[int(item)] for item in item] except IndexError: item = None game_id = item[0][0] server_data = dict2pickle("join_game", game_id, None) response = self.send(server_data) data1 = self.client_controller(pickle2dict(response)) self.Rkey = data1 print(" [%s] Game ID : %s" % (self.callback_queue, data1)) server_data = dict2pickle("connect", None, None) response = self.send(server_data) data2 = self.client_controller(pickle2dict(response)) print(" [%s] Number of Players : %s" % (self.callback_queue, data2)) msg = "Game id : %s\nnumber of players : %s" % (data1, data2) messagebox.showinfo("New Game", msg) self.Game_window() self.update_moves() self.menu.entryconfig(3, state="disabled")
def on_request(ch, method, props, body): body_dict = pickle2dict(body) response = game_starter(body_dict, props.reply_to) ch.basic_publish(exchange='', routing_key=props.reply_to, properties=pika.BasicProperties(correlation_id = props.correlation_id), body=response) ch.basic_ack(delivery_tag=method.delivery_tag)
def send_move(self, line): server_data = dict2pickle("move", line, None) response = self.send(server_data) data = self.client_controller(pickle2dict(response)) print(data) self.score += data self.score_lable['text'] = "Score = %s" % self.score
def ask_for_new_game(self): self.window_manager("New Game") server_data = dict2pickle("new_game", None, None) response = self.send(server_data) data1 = self.client_controller(pickle2dict(response)) self.Rkey = data1 print(" [%s] New Game ID : %r" % (self.callback_queue, data1)) server_data = dict2pickle("connect", None, None) response = self.send(server_data) print(pickle2dict(response)) data2 = self.client_controller(pickle2dict(response)) print(" [%s] Number of Players : %s" % (self.callback_queue, data2)) msg = "Game id : %s\nnumber of players : %s" % (data1, data2) messagebox.showinfo("New Game", msg) self.Game_window() self.update_moves()
def on_req(self, ch, method, props, body): body_dict = pickle2dict(body) print(" [%s] Request (%s) from %s" % (self.callback_queue, body_dict["task"], props.reply_to)) response = self.Game_Controller(body_dict, props.reply_to) ch.basic_publish(exchange='', routing_key=props.reply_to, properties=pika.BasicProperties(correlation_id=props.correlation_id), body=response) ch.basic_ack(delivery_tag=method.delivery_tag)
def update_moves(self): global after_id server_data = dict2pickle("update_move", self.callback_queue, None) response = self.send(server_data) data = self.client_controller(pickle2dict(response)) if pickle2dict(response)["arg2"] == str(self.callback_queue): self.move_bt.create_oval(5, 5, 20, 20, fill="green") self.my_turn = True else: self.move_bt.create_oval(5, 5, 20, 20, fill="red") self.my_turn = False self.lines.clear() for item in data: self.lines.append(item[1]) self.create_line(item[1][0], item[1][1], item[1][2]) after_id = self.after(1000, self.update_moves)
def exit_current_game(self, t): self.window_manager("Cancel Game") t.destroy() server_data = dict2pickle("game_exit", None, None) response = self.send(server_data) data = self.client_controller(pickle2dict(response)) print(" [%s] You are out of Game(%s)" % (self.callback_queue, data)) self.Rkey = 'server_queue' self.after_cancel(after_id)
def ask_for_list_of_games(self): self.window_manager("Game List") server_data = dict2pickle("game_list", None, None) response = self.send(server_data) self.list = self.client_controller(pickle2dict(response)) print(" [%s] List of Game ID : %s" % (self.callback_queue, self.list)) self.game_list.delete(0, END) for item in self.list: self.game_list.insert(END, item[0]) self.game_list.select_set(0)