fix upper/lowercase

This commit is contained in:
Daniel Tsvetkov 2022-01-18 22:33:49 +01:00
parent 00c493e492
commit 390ea9e702
2 changed files with 13 additions and 11 deletions

21
app.py
View File

@ -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/<int:game_id>')
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/<int:game_id>')
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))

View File

@ -13,7 +13,8 @@
</ul>
{% if state_playing %}
<form method="post" action="{{ url_for('make_guess') }}">
<input maxlength="5" minlength="5" size="5" name="guess" autofocus autocomplete="off"/>
<input maxlength="5" minlength="5" size="5" name="guess" autofocus autocomplete="off"
style="text-transform:uppercase"/>
<input type="submit">
</form>
{% else %}