예제 #1
0
def shop(event) -> Dict:
    if ("game_id" not in event or "game_timestamp" not in event
            or "player_id" not in event or "room_id" not in event
            or "x" not in event or "y" not in event
            or "rotation" not in event):
        return {}
    response = game_table.get_item(Key={
        "id": event["game_id"],
        "timestamp": event["game_timestamp"]
    })
    if response["Item"]["game_state"] != "PLAYING":
        return {}
    game_info = Game.from_json_obj(response["Item"])
    game_info = manager.action_shop(
        game_info,
        event["player_id"],
        event["room_id"],
        event["x"],
        event["y"],
        event["rotation"],
    )
    update_game(event["game_id"], event["game_timestamp"], game_info,
                "PLAYING")
    return {
        "player_id": event["player_id"],
        "game_id": event["game_id"],
        "game_timestamp": event["game_timestamp"],
    }
예제 #2
0
def get_game_info(event) -> Dict:
    if "game_id" not in event or "game_timestamp" not in event:
        return {}
    response = game_table.get_item(Key={
        "id": event["game_id"],
        "timestamp": event["game_timestamp"]
    })
    game_info = Game.from_json_obj(response["Item"])
    return {
        "game_id": event["game_id"],
        "game_timestamp": event["game_timestamp"],
        "game_info": game_info.to_public_json_obj(),
    }
예제 #3
0
def discard(event) -> Dict:
    if ("game_id" not in event or "game_timestamp" not in event
            or "player_id" not in event or "discard_list" not in event):
        return {}
    response = game_table.get_item(Key={
        "id": event["game_id"],
        "timestamp": event["game_timestamp"]
    })
    if response["Item"]["game_state"] != "PLAYING":
        return {}
    game_info = Game.from_json_obj(response["Item"])
    game_info = manager.action_discard(game_info, event["player_id"],
                                       event["discard_list"])
    if manager.is_game_ended(game_info):
        update_game(event["game_id"], event["game_timestamp"], game_info,
                    "ENDED")
    else:
        update_game(event["game_id"], event["game_timestamp"], game_info,
                    "PLAYING")
    return {
        "player_id": event["player_id"],
        "game_id": event["game_id"],
        "game_timestamp": event["game_timestamp"],
    }