From 2a7300f126bc5f8937f1e92c4ef72f3e80466a8c Mon Sep 17 00:00:00 2001 From: Michiel Scholten Date: Mon, 4 Nov 2024 22:06:09 +0100 Subject: [PATCH] Making the game interactive, getting results from backend --- src/alfagok/static/game.js | 28 ++++++- src/alfagok/templates/index.html | 121 ++++++++++++++++++------------- 2 files changed, 94 insertions(+), 55 deletions(-) diff --git a/src/alfagok/static/game.js b/src/alfagok/static/game.js index a109503..707ed9d 100644 --- a/src/alfagok/static/game.js +++ b/src/alfagok/static/game.js @@ -8,18 +8,38 @@ async function getGameID() { } } -async function doGuess(guessWord, guessError) { +async function doGuess(guessWord) { + if (guessWord === '') { + console.log('Nothing filled in'); + Alpine.store('alfagok').guessError = 'Vul een woord in'; + return; + } + + if (Alpine.store('alfagok').startTime === '') { + console.log('Setting startTime to now'); + } + let response = await fetch('/api/guess/' + guessWord); let result = await response.json(); console.log(result); if (result.error) { console.log('Error occurred during guess'); if (result.error === 'Word not in dictionary') { - guessError = 'Woord komt niet in de woordenlijst voor'; + Alpine.store('alfagok').guessError = 'Woord komt niet in de woordenlijst voor'; } - console.log(guessError); } - return result; + if (result.hint && result.hint === 'after') { + console.log('na'); + Alpine.store('alfagok').guessesBefore.push(guessWord); + } + if (result.hint && result.hint === 'before') { + console.log('voor'); + Alpine.store('alfagok').guessesAfter.push(guessWord); + } + if (result.hint && result.hint === 'it') { + console.log('gevonden'); + } + } /* Time formatting **/ diff --git a/src/alfagok/templates/index.html b/src/alfagok/templates/index.html index 9dbf125..36eeebb 100644 --- a/src/alfagok/templates/index.html +++ b/src/alfagok/templates/index.html @@ -9,36 +9,53 @@ + +
- alfagok puzzle # -

+ alfagok puzzle # + +

Raad het woord van de dag. Elke gok geeft een hint over waar het woord zich in het alfabet bevindt.

@@ -47,57 +64,59 @@
-
    -