hello-wordle/src/App.tsx

53 wiersze
1.3 KiB
TypeScript
Czysty Zwykły widok Historia

2021-12-31 01:43:09 +00:00
import "./App.css";
import common from "./common.json";
2022-01-01 02:04:48 +00:00
import { dictionarySet, pick } from "./util";
2021-12-31 01:43:09 +00:00
import Game from "./Game";
2022-01-01 02:04:48 +00:00
import { names } from "./names";
2022-01-01 18:35:03 +00:00
import { useState } from "react";
2022-01-01 02:04:48 +00:00
const targets = common
.slice(0, 20000) // adjust for max target freakiness
.filter((word) => dictionarySet.has(word) && !names.has(word));
function randomTarget(wordLength: number) {
const eligible = targets.filter((word) => word.length === wordLength);
return pick(eligible);
}
function App() {
2022-01-01 02:04:48 +00:00
const [wordLength, setWordLength] = useState(5);
const [target, setTarget] = useState(randomTarget(wordLength));
if (target.length !== wordLength) {
throw new Error("length mismatch");
}
return (
<>
<h1>hello wordl</h1>
<input
type="range"
2022-01-01 18:14:50 +00:00
min="4"
max="11"
2022-01-01 02:04:48 +00:00
value={wordLength}
onChange={(e) => {
2022-01-01 18:14:50 +00:00
const length = Number(e.target.value);
setTarget(randomTarget(length));
setWordLength(length);
2022-01-01 02:04:48 +00:00
}}
></input>
<div className="App">
<Game
2022-01-01 18:14:50 +00:00
key={target}
2022-01-01 02:04:48 +00:00
wordLength={wordLength}
target={target}
maxGuesses={6}
2022-01-01 18:14:50 +00:00
restart={() => {
setTarget(randomTarget(wordLength));
}}
2022-01-01 02:04:48 +00:00
/>
</div>
</>
);
}
export default App;