From 04b75bea7c6c83bee6b4416ebfd22dc48a380b93 Mon Sep 17 00:00:00 2001 From: Alexis Hovorka Date: Sat, 19 Feb 2022 23:59:25 -0700 Subject: [feat] Make keyboard visually track used letters --- public/index.html | 6 +++--- public/main.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'public') diff --git a/public/index.html b/public/index.html index 0010c06..12bfdd9 100644 --- a/public/index.html +++ b/public/index.html @@ -66,9 +66,9 @@ - - - + + + diff --git a/public/main.js b/public/main.js index 13d83e7..01848b3 100644 --- a/public/main.js +++ b/public/main.js @@ -31,6 +31,15 @@ function setRowState(r, s) { }, r); } +function updateKeyboard(keys) { + $$("td[data-key]", e => { + if (keys.hasOwnProperty(e.dataset.key)) { + e.classList.remove("found","present","absent"); + e.classList.add(["absent","present","found"][keys[e.dataset.key]]); + } + }); +} + let done = false; let currentRow = 0; let currentStr = ""; @@ -51,12 +60,21 @@ function processKey(key) { setRow(board[currentRow], currentStr); } +const guessedLetters = {}; async function tryWord() { if (currentStr.length !== 6) return alert("Guesses must use all six letters!"); const r = await fetch("/guess/"+currentStr).then(r => r.json()); if (r.result === false) return alert("Not in word list!"); + for (let i=0;i<6;i++) { + const j = currentStr.charAt(i); + guessedLetters[j] = Math.max(guessedLetters[j]||0, + " -=".indexOf(r.result.charAt(i))); + } + + updateKeyboard(guessedLetters); + setRowState(board[currentRow], r.result); if (r.result === "======") { setTimeout(() => alert("Congratulations!")); -- cgit v1.2.3-70-g09d2
QWEQWE R T Y