Fix word length after a weird challenge game

pull/54/head^2
Lynn 2022-01-23 22:22:00 +01:00
rodzic 6818431b50
commit 32be1606cf
1 zmienionych plików z 8 dodań i 3 usunięć

Wyświetl plik

@ -28,6 +28,8 @@ interface GameProps {
} }
const targets = targetList.slice(0, targetList.indexOf("murky") + 1); // Words no rarer than this one const targets = targetList.slice(0, targetList.indexOf("murky") + 1); // Words no rarer than this one
const minWordLength = 4;
const maxWordLength = 11;
function randomTarget(wordLength: number): string { function randomTarget(wordLength: number): string {
const eligible = targets.filter((word) => word.length === wordLength); const eligible = targets.filter((word) => word.length === wordLength);
@ -85,7 +87,10 @@ function Game(props: GameProps) {
window.history.replaceState({}, document.title, window.location.pathname); window.history.replaceState({}, document.title, window.location.pathname);
} }
setChallenge(""); setChallenge("");
setTarget(randomTarget(wordLength)); const newWordLength =
wordLength < minWordLength || wordLength > maxWordLength ? 5 : wordLength;
setWordLength(newWordLength);
setTarget(randomTarget(newWordLength));
setGuesses([]); setGuesses([]);
setCurrentGuess(""); setCurrentGuess("");
setHint(""); setHint("");
@ -201,8 +206,8 @@ function Game(props: GameProps) {
<label htmlFor="wordLength">Letters:</label> <label htmlFor="wordLength">Letters:</label>
<input <input
type="range" type="range"
min="4" min={minWordLength}
max="11" max={maxWordLength}
id="wordLength" id="wordLength"
disabled={ disabled={
gameState === GameState.Playing && gameState === GameState.Playing &&