Ejemplo n.º 1
0
def lose():
    if 'player' in session and 'game_id' in session:
        if 'lose' in session:
            if session['lose'] is True:
                db_connection.query("UPDATE Game SET turns = (?)," +
                                    "is_finished = (?)" +
                                    "WHERE game_id = (?)", (session['attempts'], False, session['game_id']))
                Game.clear_game()
                return render_template('gamestart.html')
    session.clear()
    return render_template('login.html')
 def __init__(self, username: str):
     if 'player' not in session:
         session['player'] = username
         rows = db_connection.select_query(
             'SELECT * FROM User WHERE username = ?', [username])
         if len(rows) == 0:
             db_connection.query('INSERT INTO User VALUES(null, ?)',
                                 [username])
             rows = db_connection.select_query(
                 'SELECT * FROM User WHERE username = ?', [username])
         session['player_id'] = rows[0][0]
Ejemplo n.º 3
0
 def __init__(self, player_id: int, newgame: bool):
     session['answer'] = []
     session['amount'] = 4
     session['color_amount'] = 6
     if newgame:
         db_connection.query("INSERT INTO Game(player_id)" + 'VALUES (?)',
                             [player_id])
         result = db_connection.select_query(
             'SELECT * FROM Game ' + 'WHERE player_id = ?' +
             'ORDER BY created_at DESC ' + 'LIMIT 1', [player_id])
         session['game_id'] = result[0][0]
     else:
         pass
Ejemplo n.º 4
0
def gamestart():
    if request.method == 'GET' and 'player' in session:
        return render_template('gamestart.html')
    if request.method == 'POST' and 'player' in session:
        Game.clear_game()
        Player.begin_game()
        is_checked = request.form.get('doubles')
        cheat_on = request.form.get('cheat')
        session['answer'] = Game.generate_game(int(request.form['amount']), int(request.form['color_amount']), is_checked)
        session['is_cheated'] = False
        if cheat_on:
            session['is_cheated'] = True
            db_connection.query("UPDATE Game SET has_cheated = (?)" +
                                "WHERE game_id = (?)", (True, session['game_id']))
        if 'tries' not in session:
            session['tries'] = []
        return render_template('game.html', Color=Color, cheating=session['is_cheated'])
    return render_template('login.html')