Beispiel #1
0
def play(game_id):
    with DatabaseServices() as dbase:
        figname = request.args.get('figure')
        figure = json.loads(dbase.get_figure_by_name(figname))[0]
        figures = json.loads(dbase.get_figures_by_game_id(game_id))
    return render_template('game/game.html', figures=figures,
                            figure=figure, game_id=game_id)
Beispiel #2
0
def join(game_id, user_id):
    print(f'g ${game_id}, u ${user_id}')
    with DatabaseServices() as dbase:
        my_figures = json.loads(dbase.get_figures_by_user(user_id))
        user = json.loads(dbase.get_username_from_id(user_id))[0]['username']
        current_game = json.loads(dbase.get_game_by_id(game_id))[0]
    return render_template('game/table.html', figures=my_figures,
        game=current_game, user=user)
Beispiel #3
0
def index():
    with DatabaseServices() as dbase:
        figures = json.loads(dbase.get_figures())
        games = json.loads(dbase.get_games())
        users = json.loads(dbase.get_users())
    this_user = {'username': g.user['username'], 'id': g.user['id']}
    return render_template('game/index.html',
                           figures=figures,
                           games=games,
                           users=users,
                           thisUser=this_user,
                           room='lobby')
Beispiel #4
0
def update(id):
    if request.method == 'POST':
        figure_name = request.form['figure_name']
        strength = int(request.form['strength'])
        dexterity = int(request.form['dexterity'])
        error = None

        # TODO: Form requires field, but check for duplicate figname?
        if (strength + dexterity) != 24:
            error = 'You must divide exactly 8 points between your stats. not %s and %s' % (
                strength, dexterity)
        if error:
            flash(error)
        else:
            with DatabaseServices() as dbase:
                rows = dbase.update_figure(figure_name, strength, dexterity,
                                           id)
            return redirect(url_for('lobby.index'))

    with DatabaseServices() as dbase:
        figure_str = dbase.get_figure_by_id(id)
        figure = json.loads(figure_str)[0]
    return render_template('figure/update.html', figure=figure)
Beispiel #5
0
def punch(attack_name, defend_name):
    with DatabaseServices() as dbase:
        attacker = json.loads(dbase.get_figure_by_name(attack_name))[0]
        defender = json.loads(dbase.get_figure_by_name(defend_name))[0]
    rolls = [random.randrange(1, 7) for i in range(0,3)]
    roll_total = sum(rolls)
    if roll_total > attacker["dexterity"]:
        damage = 0
        message = "%s attacks %s but misses with a roll of %s %s" %\
            (attacker["figure_name"], defender["figure_name"], roll_total, rolls)
    else:
        damage = random.randrange(1, 7)
        message = "%s attacks %s and hits with a roll of %s %s. Doing %s damage." %\
            (attacker["figure_name"], defender["figure_name"], roll_total, rolls, damage)

    return { "message": message, "damage": damage }
Beispiel #6
0
def create():
    if request.method == 'POST':
        figure_name = request.form['figure_name']
        strength = int(request.form['strength'])
        dexterity = int(request.form['dexterity'])

        # TODO: validate name using db services
        error = None
        if (strength + dexterity) != 24:
            error = 'You must divide exactly 8 points between your stats. not %s and %s' % (
                strength, dexterity)
        if error:
            flash(error)
        else:
            with DatabaseServices() as dbase:
                rows = dbase.add_figure(figure_name, strength, dexterity,
                                        g.user['id'])
                print(rows)
            return redirect(url_for('lobby.index'))

    return render_template('figure/create.html')
Beispiel #7
0
def delete(id):
    with DatabaseServices() as dbase:
        rows = dbase.delete_figure(id)
    return redirect(url_for('lobby.index'))