From 39c7572d3792801531a6da3fe7e65bf5ddb61a66 Mon Sep 17 00:00:00 2001 From: prodzpod Date: Sat, 23 Mar 2024 21:52:06 +0900 Subject: [PATCH] feat: difficulty stars in emoji share --- src/App.tsx | 3 +++ src/Game.tsx | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/App.tsx b/src/App.tsx index cd7fe05b6..e840bfdba 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -46,6 +46,7 @@ function App() { "qwertyuiop-asdfghjkl-BzxcvbnmE" ); const [enterLeft, setEnterLeft] = useSetting("enter-left", false); + const [ongoing, setOngoing] = useState(false); useEffect(() => { document.body.className = dark ? "dark" : ""; @@ -133,6 +134,7 @@ function App() { max="2" value={difficulty} onChange={(e) => setDifficulty(+e.target.value)} + disabled={ongoing === true} />
@@ -189,6 +191,7 @@ function App() { /[BE]/g, (x) => (enterLeft ? "EB" : "BE")["BE".indexOf(x)] )} + setOngoing={setOngoing} />
); diff --git a/src/Game.tsx b/src/Game.tsx index 3ce5ebd14..d5f9d07f5 100644 --- a/src/Game.tsx +++ b/src/Game.tsx @@ -29,6 +29,7 @@ interface GameProps { difficulty: Difficulty; colorBlind: boolean; keyboardLayout: string; + setOngoing: Function; } const targets = targetList.slice(0, targetList.indexOf("murky") + 1); // Words no rarer than this one @@ -47,6 +48,12 @@ function randomTarget(wordLength: number): string { return candidate; } +function getDifficultyStars(difficulty: Difficulty): string { + if (difficulty === Difficulty.UltraHard) return '**'; + else if (difficulty === Difficulty.Hard) return '*'; + else return ''; +} + function getChallengeUrl(target: string): string { return ( window.location.origin + @@ -87,6 +94,7 @@ function Game(props: GameProps) { const [guesses, setGuesses] = useState([]); const [currentGuess, setCurrentGuess] = useState(""); const [challenge, setChallenge] = useState(initChallenge); + const [currentDifficulty, setCurrentDifficulty] = useState(props.difficulty); const [wordLength, setWordLength] = useState( challenge ? challenge.length : parseUrlLength() ); @@ -128,6 +136,7 @@ function Game(props: GameProps) { setCurrentGuess(""); setGameState(GameState.Playing); setGameNumber((x) => x + 1); + props.setOngoing(false); }; async function share(copiedHint: string, text?: string) { @@ -190,7 +199,9 @@ function Game(props: GameProps) { return; } } + if (guesses.length === 0) setCurrentDifficulty(props.difficulty); setGuesses((guesses) => guesses.concat([currentGuess])); + props.setOngoing(true); setCurrentGuess((guess) => ""); const gameOver = (verbed: string) => @@ -201,9 +212,11 @@ function Game(props: GameProps) { if (currentGuess === target) { setHint(gameOver("won")); setGameState(GameState.Won); + props.setOngoing(false); } else if (guesses.length + 1 === props.maxGuesses) { setHint(gameOver("lost")); setGameState(GameState.Lost); + props.setOngoing(false); } else { setHint(""); speak(describeClue(clue(currentGuess, target))); @@ -282,6 +295,7 @@ function Game(props: GameProps) { setTarget(randomTarget(length)); setWordLength(length); setHint(`${length} letters`); + props.setOngoing(false); }} >