From 687f2acc2256c16585a2cd3ccabf1f15a66bfc46 Mon Sep 17 00:00:00 2001 From: Lynn Date: Fri, 14 Jan 2022 00:16:27 +0100 Subject: [PATCH] It's playable --- src/App.css | 7 ++++++- src/Game.tsx | 19 ++++++++++--------- src/Keyboard.tsx | 3 ++- src/Row.tsx | 26 ++++++++++++++------------ src/clue.ts | 16 ++++++++++++++++ src/util.ts | 21 +++++++++++++++++++++ 6 files changed, 69 insertions(+), 23 deletions(-) diff --git a/src/App.css b/src/App.css index 69bc7ba..eae8b23 100644 --- a/src/App.css +++ b/src/App.css @@ -44,6 +44,10 @@ body { user-select: none; } +table.Game-rows { + margin: auto; +} + .Game-keyboard { display: flex; flex-direction: column; @@ -171,7 +175,8 @@ a:active { font-variant-numeric: tabular-nums; } -.Game-sr-feedback { +.Game-sr-feedback, +.sr-only { position: absolute; left: -10000px; top: auto; diff --git a/src/Game.tsx b/src/Game.tsx index 3770520..eabdea2 100644 --- a/src/Game.tsx +++ b/src/Game.tsx @@ -1,10 +1,10 @@ import { useEffect, useState } from "react"; import { Row, RowState } from "./Row"; import dictionary from "./dictionary.json"; -import { Clue, clue } from "./clue"; +import { Clue, clue, describeClue } from "./clue"; import { Keyboard } from "./Keyboard"; import targetList from "./targets.json"; -import { dictionarySet, pick, resetRng, seed } from "./util"; +import { dictionarySet, pick, resetRng, seed, speak } from "./util"; enum GameState { Playing, @@ -57,6 +57,7 @@ function Game(props: GameProps) { if (/^[a-z]$/.test(key)) { setCurrentGuess((guess) => (guess + key).slice(0, wordLength)); setHint(""); + setSrStatus(""); } else if (key === "Backspace") { setCurrentGuess((guess) => guess.slice(0, -1)); setHint(""); @@ -81,7 +82,7 @@ function Game(props: GameProps) { setGameState(GameState.Lost); } else { setHint(""); - setSrStatus("Feedback goes here"); + speak(describeClue(clue(currentGuess, target))); } } }; @@ -99,7 +100,7 @@ function Game(props: GameProps) { }, [currentGuess, gameState]); let letterInfo = new Map(); - const rowDivs = Array(props.maxGuesses) + const tableRows = Array(props.maxGuesses) .fill(undefined) .map((_, i) => { const guess = [...guesses, currentGuess][i] ?? ""; @@ -156,7 +157,7 @@ function Game(props: GameProps) { }} > -
{rowDivs}
-

{hint || `\u00a0`}

-

+ {tableRows}
+

{hint || `\u00a0`}

+ {/*

{srStatus} -

+

*/} {seed ? (
diff --git a/src/Keyboard.tsx b/src/Keyboard.tsx index ceb1c24..3413d53 100644 --- a/src/Keyboard.tsx +++ b/src/Keyboard.tsx @@ -13,7 +13,7 @@ export function Keyboard(props: KeyboardProps) { ]; return ( -
+