Exemplo n.º 1
0
def create_game(game_data):
    name = game_data['Name']
    desc = game_data['Description']
    decks = int(game_data['CardDecks'])
    cards = int(game_data['CardsPerPlayer'])
    age = int(game_data['MinimumAge'])
    min_players = int(game_data['MinimumPlayers'])
    max_players = int(game_data['MaximumPlayers'])
    playerinfoid = 0
    rulesetid = 0

    existing_playerinfoid = DataRepository.read_playerinfo_by_data(
        age, min_players, max_players)

    if existing_playerinfoid is not None:
        playerinfoid = int(existing_playerinfoid["ID"])
    else:
        playerinfoid = DataRepository.create_playerinfo(
            age, min_players, max_players)

    existing_rulesetid = DataRepository.read_ruleset_by_data(
        cards, playerinfoid)

    if existing_rulesetid is not None:
        rulesetid = int(existing_rulesetid["ID"])
    else:
        rulesetid = DataRepository.create_ruleset(playerinfoid, cards, 0)

    gameid = DataRepository.create_game(name, desc, decks, rulesetid)

    socketio.emit('B2F_game_created')
Exemplo n.º 2
0
def games():
    if request.method == 'GET':
        data = DataRepository.read_games()
        if data is not None:
            return jsonify(games=data), 200
        else:
            return jsonify(message='ERROR: there were no games found!'), 404
    elif request.method == 'POST':
        gegevens = DataRepository.json_or_formdata(request)

        data = DataRepository.create_game(
            gegevens['name'], gegevens['description'], gegevens['cardDecks'], gegevens['rulesetID'])
        if data is not None:
            return jsonify(gameid=data), 201
        else:
            return jsonify(message='ERROR: please try again!'), 404