-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Small web app wrapper around the Game
- Loading branch information
1 parent
ae0db55
commit 72db6a6
Showing
6 changed files
with
306 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ python = "^3.8" | |
pytest = "^8.3.3" | ||
pylint = "*" | ||
requests = "^2.32.3" | ||
flask = "^3.0.3" | ||
|
||
|
||
[build-system] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* static/style.css */ | ||
body { | ||
font-family: sans-serif; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: column; | ||
} | ||
.letter { | ||
border: 1px solid #999; | ||
padding: 8px 6px; | ||
width: 24px; | ||
display: inline-block; | ||
text-align: center; | ||
background-color: #333; | ||
color: #eee; | ||
} | ||
#form, #results { | ||
margin: 1em 0; | ||
} | ||
.valid { | ||
color: green; | ||
} | ||
.invalid { | ||
color: red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!-- templates/check.html --> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf8" /> | ||
<title>Longest Word</title> | ||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"> | ||
</head> | ||
<body> | ||
<h1>Longest Word</h1> | ||
<h2>Result</h2> | ||
<div> | ||
{% for letter in grid %} | ||
<span class="letter">{{ letter }}</span> | ||
{% endfor %} | ||
</div> | ||
<div id="results"> | ||
Your word: <strong>{{ word }}</strong>. | ||
{% if is_valid %} | ||
<span class="valid">Congrats, it's valid!</span> | ||
{% else %} | ||
<span class="invalid">Sorry, it's invalid...</span> | ||
{% endif %} | ||
</div> | ||
<div> | ||
<a href="/">New game</a> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!-- templates/home.html --> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf8" /> | ||
<title>Longest Word</title> | ||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"> | ||
</head> | ||
<body> | ||
<h1>Longest Word</h1> | ||
<div> | ||
{% for letter in grid %} | ||
<span class="letter">{{ letter }}</span> | ||
{% endfor %} | ||
</div> | ||
<!-- Let's build an input "form" so user can type letters --> | ||
<form action="/check" id="form" method="post"> | ||
<!--hidden input form that contains the game.grid to be sent alongside the word letters--> | ||
<input type="hidden" name="grid" value="{{ ''.join(grid) }}"> | ||
<!--explicit input form which forces content to uppercase since our `Game` logic only take care of uppercase letters--> | ||
<input type="text" name="word" onkeyup="this.value = this.value.toUpperCase();"> | ||
<button>Check!</button> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# pylint: disable=missing-docstring | ||
|
||
from flask import Flask, render_template, request | ||
from longest_word.game import Game | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/') | ||
def home(): | ||
game = Game() | ||
return render_template('home.html', grid=game.grid) | ||
|
||
|
||
@app.route('/check', methods=["POST"]) | ||
def check(): | ||
game = Game() | ||
game.grid = list(request.form['grid']) | ||
word = request.form['word'] | ||
is_valid = game.is_valid(word) | ||
return render_template('check.html', is_valid=is_valid, grid=game.grid, word=word) |