Esempio n. 1
0
    def add_player(self, username):
        if self.players.has_key(username):
            raise LogicException(
                "There is already someone in this game named {}".format(
                    username))

        if len(self.players.values()) >= self.max_players:
            raise LogicException("Maximum number of players reached!")
        player = Player(username)
        self.players[username] = player
        self.trigger_field_change()
Esempio n. 2
0
 def get_all_games(self):
     msg, type = self.__call_proxy("get_all_games")
     if type == T.RESP_OK:
         return msg
     else:
         C.LOG.warning(msg)
         raise LogicException(
             "Game requesting failed with error: {}".format(msg))
Esempio n. 3
0
 def leave_game(self, game_id, username):
     msg, type = self.__call_proxy("leave_game",
                                   "{}:{}".format(game_id, username))
     if type == T.RESP_OK:
         C.LOG.info("Left game with id: {}".format(game_id))
     else:
         C.LOG.warning(msg)
         raise LogicException("Leaving game failed with: {}".format(msg))
Esempio n. 4
0
 def request_players(self, game_id):
     msg, type = self.__call_proxy("player_list", game_id)
     if type == T.RESP_OK:
         return ObjectFactory.players_from_json(msg)
     else:
         C.LOG.warning(msg)
         raise LogicException(
             "Could not retreive players list from server: {}".format(msg))
Esempio n. 5
0
 def join_game(self, game_id, username):
     msg, type = self.__call_proxy("join_game",
                                   "{}:{}".format(game_id, username))
     if type == T.RESP_OK:
         C.LOG.info("Joined game with id: {}".format(game_id))
     else:
         C.LOG.warning(msg)
         raise LogicException(
             "New game creation failed with message: {}".format(msg))
Esempio n. 6
0
 def new_game_request(self, game_name, max_players):
     msg, type = self.__call_proxy("new_game",
                                   "{}:{}".format(game_name, max_players))
     if type == T.RESP_OK:
         C.LOG.info("New game created with id: {}".format(msg))
         return msg
     else:
         C.LOG.warning(msg)
         raise LogicException(
             "New game creation failed with message: {}".format(msg))
Esempio n. 7
0
 def check_nr(self, nr, address, username, game_id):
     msg, type = self.__call_proxy(
         "check_nr", "{}:{}:{}:{}".format(nr, address, game_id, username))
     if type == T.RESP_OK:
         return msg
     if type == T.RESP_NOK:
         return msg
     else:
         C.LOG.warning(msg)
         raise LogicException(
             "Game requesting failed with error: {}".format(msg))