commit f433b174cb53f32b69a443a048d2501df548e8db Author: apio Date: Wed Oct 5 20:41:34 2022 +0200 Ready. Set. Go! diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fc9afdc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv/** \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..548ed3a --- /dev/null +++ b/main.py @@ -0,0 +1,27 @@ +from flask import Flask, jsonify, render_template +from random import choice +import json + +defaults = [] + +app = Flask(__name__) + +@app.route("/") +def index(): + initial_word = choice(defaults) + return render_template("index.html", initial_word=initial_word["word"], initial_image_url=initial_word["image_url"]) + +@app.route("/random") +def random(): + word = choice(defaults) + return jsonify(word=word["word"], image_url=word["image_url"]) + +@app.before_first_request +def load(): + global defaults + file = open("startup.json") + defaults = json.load(file) + file.close() + +if __name__ == "__main__": + app.run("0.0.0.0", 8000) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1b4eda1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +click==8.1.3 +Flask==2.2.2 +Flask-SQLAlchemy==3.0.0 +greenlet==1.1.3 +gunicorn==20.1.0 +itsdangerous==2.1.2 +Jinja2==3.1.2 +MarkupSafe==2.1.1 +SQLAlchemy==1.4.41 +Werkzeug==2.2.2 diff --git a/startup.json b/startup.json new file mode 100644 index 0000000..5d3f06e --- /dev/null +++ b/startup.json @@ -0,0 +1,62 @@ +[ +{ + "word": "batido", + "image_url": "http://www.ahungryblog.com/wp-content/uploads/2015/03/batido-de-frutas-1755x1163.jpg" +}, +{ + "word": "biblioteca", + "image_url": "https://cdn.theculturetrip.com/wp-content/uploads/2016/10/25584966356_8b17bbfb2c_o-min.jpg" +}, +{ + "word": "cacahuete", + "image_url": "https://img-3.journaldesfemmes.fr/tlg1QaE9-aR-EgiE6tAOhVcCFaU=/1500x/smart/2543bf82f3134f499c0f489b5a37e5c4/ccmcms-jdf/24583407.jpg" +}, +{ + "word": "hielo", + "image_url": "https://conceptodefinicion.de/wp-content/uploads/2018/05/Hielo-2.jpg" +}, +{ + "word": "humo", + "image_url": "https://www.pikpng.com/pngl/m/290-2900708_humo-blanco-en-for-free-download-monochrome-clipart.png" +}, +{ + "word": "sushi", + "image_url": "https://images.unsplash.com/photo-1607301405418-780ee5e6dd10?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1583&q=80" +}, +{ + "word": "huevo", + "image_url": "https://images.unsplash.com/photo-1587486913049-53fc88980cfc?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=880&q=80" +}, +{ + "word": "hamburguesa", + "image_url": "https://images.unsplash.com/photo-1568901346375-23c9450c58cd?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=999&q=80" +}, +{ + "word": "rueda", + "image_url": "https://images.unsplash.com/photo-1548741465-8b453e363e48?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1074&q=80" +}, +{ + "word": "huerto", + "image_url": "https://images.unsplash.com/photo-1592419391068-9bd09dd58510?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80" +}, +{ + "word": "paella", + "image_url": "https://images.unsplash.com/photo-1588276552401-30058a0fe57b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1123&q=80" +}, +{ + "word": "helado", + "image_url": "https://images.unsplash.com/photo-1642646682918-442f76c1ec74?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTZ8fGhlbGFkb3xlbnwwfHwwfHw%3D&auto=format&fit=crop&w=500&q=60" +}, +{ + "word": "playa", + "image_url": "https://images.unsplash.com/photo-1593881135366-021cb95fd82d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1074&q=80" +}, +{ + "word": "volante", + "image_url": "https://images.unsplash.com/photo-1613771750144-9f2177c60fb0?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1471&q=80" +}, +{ + "word": "koala", + "image_url": "https://images.unsplash.com/photo-1459262838948-3e2de6c1ec80?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1469&q=80" +} +] \ No newline at end of file diff --git a/static/ortie.js b/static/ortie.js new file mode 100644 index 0000000..eba546b --- /dev/null +++ b/static/ortie.js @@ -0,0 +1,75 @@ +var target = document.getElementById("startup-target").innerText; +var buffer = ""; +var successfulAttempts = 0; +var failedAttempts = 0; +var isGameActive = true; + +document.body.removeChild(document.getElementById("startup-target")); + +const field = document.getElementById("spell-field"); +const scoreGood = document.getElementById("score-good"); +const scoreBad = document.getElementById("score-bad"); +const scorePercent = document.getElementById("score-percent"); + +const image = document.getElementById("word-image"); + +async function updateTarget() { + isGameActive = false; + const response = await fetch("/random"); + const object = await response.json(); + target = object.word; + image.src = object.image_url; + isGameActive = true; + console.log("ready!"); +} + +function isLetter(str) { + return str.length === 1 && str.match(/[a-z]/i); +} + +updateSpellField = (text) => { + field.innerText = text; + field.style.color = ""; +} + +updateScores = () => { + scoreGood.innerText = successfulAttempts; + scoreBad.innerText = failedAttempts; + var total = successfulAttempts + failedAttempts; + var percent = (successfulAttempts / total) * 100; + scorePercent.innerText = Math.round(percent); +} + +submitBuffer = () => { + if(buffer.toLowerCase() !== target.toLowerCase()) + { + updateSpellField(target); + field.style.color = "red"; + failedAttempts += 1; + } else { + updateSpellField(buffer); + field.style.color = "green"; + successfulAttempts += 1; + } + updateScores(); + buffer = ""; + updateTarget(); +} + +document.onkeyup = (ev) => { + const key = ev.key; + if(isGameActive) + { + if(key === "Enter") + { + if(buffer.length != 0) submitBuffer(); + } + if(isLetter(key)) + { + buffer += key; + updateSpellField(buffer); + } + } + ev.preventDefault(); + return false; +} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..60b9c82 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,62 @@ + + + + + + + Ortie: Entrenamiento de OrtografĂ­a + + + + + + + +
+
+ +
+
+

empieza!

+
+
+
 
0
+
 
0
+
 
100%
+
+
+
+ +
{{ initial_word }}
+ + + + \ No newline at end of file