kopia lustrzana https://github.com/lynn/hello-wordl
Fix word length after a weird challenge game
rodzic
6818431b50
commit
32be1606cf
11
src/Game.tsx
11
src/Game.tsx
|
@ -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 &&
|
||||||
|
|
Ładowanie…
Reference in New Issue