From 390ea9e702005942eceaa5ebd8765c470bdeee72 Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Tue, 18 Jan 2022 22:33:49 +0100 Subject: [PATCH] fix upper/lowercase --- app.py | 21 +++++++++++---------- templates/game.html | 3 ++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app.py b/app.py index c0ce2ce..50b297a 100644 --- a/app.py +++ b/app.py @@ -14,6 +14,7 @@ GUESS_SPLITTER = '|' STATE_PLAYING = 'PLAYING' STATE_WIN = 'WIN' STATE_LOSE = 'LOSE' +RANDOM_GAME_ID = -1 @app.route('/') @@ -22,7 +23,8 @@ def home(): return render_template('home.html', num_games=num_games) -def init_game(word): +def init_game(game_id, word): + session['game_id'] = game_id session['word'] = word session['guesses'] = '' session['state'] = STATE_PLAYING @@ -31,25 +33,23 @@ def init_game(word): @app.route('/init/random') def init_random_game(): word = random.choice([w for w in cat_words()]) - session['game_id'] = -1 - init_game(word) + init_game(RANDOM_GAME_ID, word) return redirect(url_for('random_game')) @app.route('/init/deterministic', methods=['post']) def init_deterministic_game(): game_id = request.form.get('game_id') - if not game_id.isdigit() or not 0 <= int(game_id) <= NUM_GAMES: - flash("game_id must be between 0 and {}".format(NUM_GAMES)) - return redirect(url_for('home')) return redirect(url_for('init_deterministic_game_id', game_id=game_id)) @app.route('/init/deterministic/') def init_deterministic_game_id(game_id): + if not 0 <= int(game_id) <= NUM_GAMES: + flash("game_id must be between 0 and {}".format(NUM_GAMES)) + return redirect(url_for('home')) word = [w for w in cat_words()][int(game_id)] - session['game_id'] = game_id - init_game(word) + init_game(game_id, word) return redirect(url_for('deterministic_game_id', game_id=game_id)) @@ -92,7 +92,7 @@ def random_game(): @app.route('/deterministic/') def deterministic_game_id(game_id): - if 'word' not in session or 'state' not in session: + if 'word' not in session or 'state' not in session or ('game_id' in session and session['game_id'] != game_id): return redirect(url_for('init_deterministic_game_id', game_id=game_id)) return build_game_state() @@ -106,8 +106,9 @@ def make_guess(): if len(guess) != 5 and not all([x in ascii_lowercase for x in guess]): flash("Make a 5 letter guess.") return build_game_state() + guess = guess.lower() if guess not in cat_words(): - flash('Not in word list') + flash('Not in word list: {}'.format(guess)) return build_game_state() word = session['word'] round = len(session['guesses'].split(GUESS_SPLITTER)) diff --git a/templates/game.html b/templates/game.html index 3cd2910..cd2a8cf 100644 --- a/templates/game.html +++ b/templates/game.html @@ -13,7 +13,8 @@ {% if state_playing %}
- +
{% else %}