def test_create_game_state_from_dict(self):
     self.maxDiff = None
     self.game_state = game_state.GameState(game_id="12345",
                                            players=self.players)
     game_state_dict = self.game_state.format()
     builder = game_state.GameStateBuilder()
     game_state_built = builder.build_gamestate_from_dict(game_state_dict)
     self.assertEqual(game_state_dict, game_state_built.format())
示例#2
0
    def load_game(self, game_id):
        """
        Loads the specified GameState from the datastore
        """
        self.game_id = game_id
        game_dict = self.db_handler.get_document(
            object_name='game', query_filter={"game_id": self.game_id})

        game_builder = game_state.GameStateBuilder()
        self.game = game_builder.build_gamestate_from_dict(game_dict)
示例#3
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
示例#4
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
示例#5
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
示例#6
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
示例#7
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
示例#8
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