def connect_second_player(self): self.connect_player() message = OnlineMessage(self.MESSAGES_TO_USER['JoinGame']) players = self.get_player_list() self.send(message.encode(), players[1]) self._server_FSM.handle_event(Event.PLAYER_CONNECTED)
def get_min_range(self): message = OnlineMessage(self.MESSAGES_TO_PLAYER['GetMinRange']) self._server.send(message.encode(), self._player_list[0]) message.decode(self._server.get(self._player_list[0])) try: min_range = int(message.get_body()) except ValueError: return None return min_range
def ask_game(self): players = self.get_player_list() message = OnlineMessage() type_game = None while type_game not in self.GAME_LIST: message = OnlineMessage(self.MESSAGES_TO_USER['AskGame']) self.send(message.encode(), players[0]) message.decode(self.get(players[0])) type_game = message.get_header() if type_game not in self.GAME_LIST: message.set_header(self.MESSAGES_TO_USER['WrongGame']) self.send(message.encode(), players[0]) message.set_header(self.MESSAGES_TO_USER['CorrectGame']) message.set_body(type_game) self.send(message.encode(), players[0]) self._server_FSM.handle_event(self.GAME_LIST[type_game])
def get_coord(self, dim, player): message = OnlineMessage(self.MESSAGES_TO_PLAYER['GetCoord']) self._server.send(message.encode(), self.actual_player(player)) message.decode(self._server.get(self.actual_player(player))) try: coord = int(message.get_body()) except ValueError: return False if 1 <= coord <= dim: return coord return False
def get_guess(self, min_range, max_range): min_max = [min_range, max_range] message = OnlineMessage(self.MESSAGES_TO_PLAYER['GetGuess'], min_max) self._server.send(message.encode(), self._player_list[0]) message.decode(self._server.get(self._player_list[0])) try: guess = int(message.get_body()) except ValueError: return None if min_range <= guess <= max_range: return guess return None
def ask_player_guess(self): message = OnlineMessage(self.MESSAGES_TO_PLAYER['AskPlayerGuess']) self._server.send(message.encode(), self._player_list[0])
def wrong_max_range(self, min_range): message = OnlineMessage(self.MESSAGES_TO_PLAYER['WrongMaxRange'], min_range) self._server.send(message.encode(), self._player_list[0])
def ask_max_range(self): message = OnlineMessage(self.MESSAGES_TO_PLAYER['AskMaxRange']) self._server.send(message.encode(), self._player_list[0])
def player_move(self, player): message = OnlineMessage(self.MESSAGES_TO_PLAYER['PlayerMove'], player) self._server.send(message.encode(), self._player_list[0]) self._server.send(message.encode(), self._player_list[1])
def welcome(self): message = OnlineMessage(self.MESSAGES_TO_PLAYER['Welcome']) self._server.send(message.encode(), self._player_list[0])
def congratulate_win(self): message = OnlineMessage(self.MESSAGES_TO_PLAYER['CongratulateWin']) self._server.send(message.encode(), self._player_list[0])
def draw_board(self, board, dim): message = OnlineMessage(self.MESSAGES_TO_PLAYER['DrawBoard'], board) self._server.send(message.encode(), self._player_list[0]) self._server.send(message.encode(), self._player_list[1])
def wrong_guess(self, min_range, max_range): min_max = [min_range, max_range] message = OnlineMessage(self.MESSAGES_TO_PLAYER['WrongGuess'], min_max) self._server.send(message.encode(), self._player_list[0])
def announce_draw(self): message = OnlineMessage(self.MESSAGES_TO_PLAYER['AnnounceDraw']) self._server.send(message.encode(), self._player_list[0]) self._server.send(message.encode(), self._player_list[1])
def wrong_move(self, player): message = OnlineMessage(self.MESSAGES_TO_PLAYER['WrongMove']) self._server.send(message.encode(), self.actual_player(player))
def wrong_coord(self, dim, player): message = OnlineMessage(self.MESSAGES_TO_PLAYER['WrongCoord'], dim) self._server.send(message.encode(), self.actual_player(player))
def ask_coord(self, coord, player): message = OnlineMessage(self.MESSAGES_TO_PLAYER['AskCoord'], coord) self._server.send(message.encode(), self.actual_player(player))
def less(self): message = OnlineMessage(self.MESSAGES_TO_PLAYER['Less']) self._server.send(message.encode(), self._player_list[0])
def first_second(self, player1, player2): message = OnlineMessage(self.MESSAGES_TO_PLAYER['YouFirst'], player1) self._server.send(message.encode(), self.actual_player(player1)) message = OnlineMessage(self.MESSAGES_TO_PLAYER['YouSecond'], player2) self._server.send(message.encode(), self.actual_player(player2))