Пример #1
0
    def destroy_game(self, game_id):
        """
        Destroy the current game
        """
        url = "{base_url}/games/game_id".format(base_url=self.base_url,
                                                game_id=game_id)
        response = requests.delete(url=url)

        if response.status_code != httplib.OK:
            raise errors.GameClientException(response.text)
Пример #2
0
    def choose_suspect(self, username, suspect):
        """
        Register a new player for upcoming game
        """
        url = "{base_url}/players/{username}".format(base_url=self.base_url,
                                                     username=username)
        headers = {'Content-Type': "application/json"}
        payload = json.dumps({"suspect": suspect})

        response = requests.put(url=url, data=payload, headers=headers)

        if response.status_code != httplib.OK:
            raise errors.GameClientException(response.text)
Пример #3
0
    def register_player(self, username):
        """
        Register a new player for upcoming game
        """
        url = "{base_url}/players".format(base_url=self.base_url)

        headers = {'Content-Type': "application/json"}
        payload = json.dumps({"username": username})

        response = requests.post(url=url, data=payload, headers=headers)

        if response.status_code != httplib.CREATED:
            raise errors.GameClientException(response.text)
Пример #4
0
    def get_players(self):
        """
        Get a list of all registered players
        """
        url = "{base_url}/players".format(base_url=self.base_url)
        response = requests.get(url=url)

        if response.status_code != httplib.OK:
            raise errors.GameClientException(response.text)

        body = response.json()
        return [
            game_state.Player(**player_dict) for player_dict in body["players"]
        ]
Пример #5
0
    def get_player(self, username):
        """
        Get a specified player
        """
        url = "{base_url}/players/{username}".format(base_url=self.base_url,
                                                     username=username)

        response = requests.get(url=url)

        if response.status_code != httplib.OK:
            raise errors.GameClientException(response.text)

        body = response.json()

        return game_state.Player(**body["player"])
Пример #6
0
    def start_new_game(self):
        """
        Creates a new game and returns a GameState object
        """
        url = "{base_url}/games".format(base_url=self.base_url)
        response = requests.post(url=url)

        if response.status_code != httplib.CREATED:
            raise errors.GameClientException(response.text)

        body = response.json()

        game_dict = body["game_state"]
        builder = game_state.GameStateBuilder()
        game = builder.build_gamestate_from_dict(game_dict)
        return game
Пример #7
0
    def get_game_state(self, game_id):
        """
        Gets the current GameState object. Ideal for polling state
        """
        url = "{base_url}/games/game_id".format(base_url=self.base_url,
                                                game_id=game_id)
        response = requests.get(url=url)

        if response.status_code != httplib.OK:
            raise errors.GameClientException(response.text)

        body = response.json()
        game_dict = body["game_state"]

        builder = game_state.GameStateBuilder()
        game = builder.build_gamestate_from_dict(game_dict)
        return game
Пример #8
0
    def end_turn(self, username):
        """
        end a players turn
        """
        url = "{base_url}/endturn".format(base_url=self.base_url)
        headers = {'Content-Type': "application/json"}
        payload = json.dumps({"username": username})

        response = requests.post(url=url, data=payload, headers=headers)

        if response.status_code != httplib.OK:
            raise errors.GameClientException(response.text)

        body = response.json()
        game_dict = body["game_state"]

        builder = game_state.GameStateBuilder()
        game = builder.build_gamestate_from_dict(game_dict)
        return game
Пример #9
0
    def make_suggestion_response(self, username, gamecard_item):
        """
        Make a suggestion response
        """
        url = "{base_url}/suggestionresponse".format(base_url=self.base_url)
        headers = {'Content-Type': "application/json"}
        payload = json.dumps({
            "username": username,
            "gamecard_item": gamecard_item,
        })

        response = requests.post(url=url, data=payload, headers=headers)

        if response.status_code != httplib.OK:
            raise errors.GameClientException(response.text)

        body = response.json()
        game_dict = body["game_state"]

        builder = game_state.GameStateBuilder()
        game = builder.build_gamestate_from_dict(game_dict)
        return game
Пример #10
0
    def move_player(self, username, suspect, space_name):
        """
        Register a new player for upcoming game
        """
        url = "{base_url}/moveplayer".format(base_url=self.base_url)
        headers = {'Content-Type': "application/json"}
        payload = json.dumps({
            "username": username,
            "suspect": suspect,
            "space_name": space_name
        })

        response = requests.post(url=url, data=payload, headers=headers)

        if response.status_code != httplib.OK:
            raise errors.GameClientException(response.text)

        body = response.json()
        game_dict = body["game_state"]

        builder = game_state.GameStateBuilder()
        game = builder.build_gamestate_from_dict(game_dict)
        return game
Пример #11
0
    def make_accusation(self, username, suspect, weapon, room):
        """
        Make a suggestion
        """
        url = "{base_url}/accusation".format(base_url=self.base_url)
        headers = {'Content-Type': "application/json"}
        payload = json.dumps({
            "username": username,
            "suspect": suspect,
            "weapon": weapon,
            "room": room
        })

        response = requests.post(url=url, data=payload, headers=headers)

        if response.status_code != httplib.OK:
            raise errors.GameClientException(response.text)

        body = response.json()
        game_dict = body["game_state"]

        builder = game_state.GameStateBuilder()
        game = builder.build_gamestate_from_dict(game_dict)
        return game