summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorAlexis Hovorka <[email protected]>2022-02-19 23:59:25 -0700
committerAlexis Hovorka <[email protected]>2022-02-19 23:59:25 -0700
commit04b75bea7c6c83bee6b4416ebfd22dc48a380b93 (patch)
tree2795be136eeffefce1540c5bb40000c1dd0da69c /public
parent15605b9918047498c32362eeaf6ba62ccf2dc095 (diff)
[feat] Make keyboard visually track used lettersHEADmain
Diffstat (limited to 'public')
-rw-r--r--public/index.html6
-rw-r--r--public/main.js18
2 files changed, 21 insertions, 3 deletions
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 @@
<table id="keyboard">
<tr>
- <td data-key="q" colspan=2 class="absent">Q</td>
- <td data-key="w" colspan=2 class="present">W</td>
- <td data-key="e" colspan=2 class="found">E</td>
+ <td data-key="q" colspan=2>Q</td>
+ <td data-key="w" colspan=2>W</td>
+ <td data-key="e" colspan=2>E</td>
<td data-key="r" colspan=2>R</td>
<td data-key="t" colspan=2>T</td>
<td data-key="y" colspan=2>Y</td>
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!"));