Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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])
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
 def ask_player_guess(self):
     message = OnlineMessage(self.MESSAGES_TO_PLAYER['AskPlayerGuess'])
     self._server.send(message.encode(), self._player_list[0])
Ejemplo n.º 7
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])
Ejemplo n.º 8
0
 def ask_max_range(self):
     message = OnlineMessage(self.MESSAGES_TO_PLAYER['AskMaxRange'])
     self._server.send(message.encode(), self._player_list[0])
Ejemplo n.º 9
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])
Ejemplo n.º 10
0
 def welcome(self):
     message = OnlineMessage(self.MESSAGES_TO_PLAYER['Welcome'])
     self._server.send(message.encode(), self._player_list[0])
Ejemplo n.º 11
0
 def congratulate_win(self):
     message = OnlineMessage(self.MESSAGES_TO_PLAYER['CongratulateWin'])
     self._server.send(message.encode(), self._player_list[0])
Ejemplo n.º 12
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])
Ejemplo n.º 13
0
 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])
Ejemplo n.º 14
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])
Ejemplo n.º 15
0
 def wrong_move(self, player):
     message = OnlineMessage(self.MESSAGES_TO_PLAYER['WrongMove'])
     self._server.send(message.encode(), self.actual_player(player))
Ejemplo n.º 16
0
 def wrong_coord(self, dim, player):
     message = OnlineMessage(self.MESSAGES_TO_PLAYER['WrongCoord'], dim)
     self._server.send(message.encode(), self.actual_player(player))
Ejemplo n.º 17
0
 def ask_coord(self, coord, player):
     message = OnlineMessage(self.MESSAGES_TO_PLAYER['AskCoord'], coord)
     self._server.send(message.encode(), self.actual_player(player))
Ejemplo n.º 18
0
 def less(self):
     message = OnlineMessage(self.MESSAGES_TO_PLAYER['Less'])
     self._server.send(message.encode(), self._player_list[0])
Ejemplo n.º 19
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))