From 84880b2551f3120a3616a640a93fc0b91707d883 Mon Sep 17 00:00:00 2001 From: Lynn Date: Fri, 7 Jan 2022 17:13:39 +0100 Subject: [PATCH] Add ?seed= support --- src/Game.tsx | 12 +++++++++--- src/common.json | 1 - src/util.ts | 21 +++++++++++++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Game.tsx b/src/Game.tsx index 1687c83..b7b319e 100644 --- a/src/Game.tsx +++ b/src/Game.tsx @@ -4,7 +4,7 @@ import dictionary from "./dictionary.json"; import { Clue, clue } from "./clue"; import { Keyboard } from "./Keyboard"; import common from "./common.json"; -import { dictionarySet, pick } from "./util"; +import { dictionarySet, pick, resetRng } from "./util"; import { names } from "./names"; enum GameState { @@ -33,7 +33,7 @@ function Game(props: GameProps) { const [currentGuess, setCurrentGuess] = useState(""); const [wordLength, setWordLength] = useState(5); const [hint, setHint] = useState(`Make your first guess!`); - const [target, setTarget] = useState(randomTarget(wordLength)); + const [target, setTarget] = useState(() => randomTarget(wordLength)); const reset = () => { setTarget(randomTarget(wordLength)); @@ -129,13 +129,19 @@ function Game(props: GameProps) { min="4" max="11" id="wordLength" - disabled={guesses.length > 0 || currentGuess !== ""} + disabled={ + gameState === GameState.Playing && + (guesses.length > 0 || currentGuess !== "") + } value={wordLength} onChange={(e) => { const length = Number(e.target.value); + resetRng(); + setGuesses([]); setTarget(randomTarget(length)); setWordLength(length); setHint(`${length} letters`); + (document.activeElement as HTMLElement)?.blur(); }} >