share all results
This commit is contained in:
parent
6b49d59066
commit
9b927bd398
3 changed files with 37 additions and 19 deletions
|
@ -9,7 +9,7 @@ import { COMMON_WORDS, UNCOMMON_WORDS } from './dictionary';
|
|||
import { Row, RowState } from './Row';
|
||||
import { Keyboard } from './Keyboard';
|
||||
import { useLocalStorage } from './localstorage';
|
||||
import { PuzzleType, PuzzleTypeDisplay } from './PuzzleType';
|
||||
import { PuzzleType, PuzzleTypeDisplay, PUZZLE_TYPES } from './PuzzleType';
|
||||
|
||||
const MAX_GUESSES = 2;
|
||||
const WORD_LENGTH = 5;
|
||||
|
@ -53,6 +53,10 @@ type DailyStats = {
|
|||
[key in PuzzleType]: PuzzleStats
|
||||
};
|
||||
|
||||
function tries(t: number) {
|
||||
return t === 1 ? "my first try" : `try #${t}`;
|
||||
}
|
||||
|
||||
export function Game(props: GameProps) {
|
||||
const { puzzleType, puzzle, day } = props;
|
||||
|
||||
|
@ -97,6 +101,7 @@ export function Game(props: GameProps) {
|
|||
);
|
||||
if (selectedPuzzle.won) {
|
||||
setGameState(GameState.Won);
|
||||
|
||||
if (selectedPuzzle.tries === 1) {
|
||||
setHint(<>
|
||||
You won today's <PuzzleTypeDisplay type={puzzleType} />{' '}
|
||||
|
@ -112,20 +117,31 @@ export function Game(props: GameProps) {
|
|||
const emoji = props.colorBlind
|
||||
? ["⬛", "🟦", "🟧"]
|
||||
: ["⬛", "🟨", "🟩"];
|
||||
const score = (todayStats[puzzleType].tries === 1
|
||||
? "my first try!"
|
||||
: `try #${todayStats[puzzleType].tries}!`
|
||||
);
|
||||
setShareMsg(
|
||||
`I solved ${gameName} #${puzzle.seed} (${puzzleType}🟩) on ${score}\n` +
|
||||
(selectedPuzzle.guesses || [])
|
||||
.map((result) =>
|
||||
clue(result)
|
||||
.map((c) => emoji[c.clue ?? 0])
|
||||
.join("")
|
||||
)
|
||||
.join("\n")
|
||||
);
|
||||
if (PUZZLE_TYPES.every((type) => todayStats[type]?.won)) {
|
||||
setShareMsg(
|
||||
`I solved all 3 puzzles in ${gameName} #${puzzle.seed}!\n` +
|
||||
PUZZLE_TYPES.slice().reverse().map((type) =>
|
||||
(todayStats[type].guesses || [])
|
||||
.map((result) =>
|
||||
clue(result)
|
||||
.map((c) => emoji[c.clue ?? 0])
|
||||
.join("")
|
||||
)
|
||||
.join("\n") + ` (${type}🟩, ${tries(todayStats[type].tries)})`
|
||||
).join("\n")
|
||||
);
|
||||
} else {
|
||||
setShareMsg(
|
||||
`I solved ${gameName} #${puzzle.seed} (${puzzleType}🟩) on ${tries(selectedPuzzle.tries)}!\n` +
|
||||
(selectedPuzzle.guesses || [])
|
||||
.map((result) =>
|
||||
clue(result)
|
||||
.map((c) => emoji[c.clue ?? 0])
|
||||
.join("")
|
||||
)
|
||||
.join("\n")
|
||||
);
|
||||
}
|
||||
} else if ((selectedPuzzle.guesses?.length || 0) >= 2) {
|
||||
setGameState(GameState.Lost);
|
||||
setHint(<p>Not quite! The answer could've been <strong>{game.possible_word().toUpperCase()}</strong>. (Enter to try again)</p>);
|
||||
|
@ -335,7 +351,7 @@ export function Game(props: GameProps) {
|
|||
<button
|
||||
onClick={() => share("Result copied to clipboard!", shareMsg)}
|
||||
>
|
||||
Share results
|
||||
Share {PUZZLE_TYPES.every((type) => todayStats[type]?.won) ? 'all ' : ''}results
|
||||
</button>
|
||||
<button onClick={() => setGameTree(game.explore_game_tree())}>
|
||||
Explore game tree
|
||||
|
@ -365,7 +381,7 @@ export function Game(props: GameProps) {
|
|||
</div>
|
||||
)}
|
||||
<p>
|
||||
Today's puzzle (#{puzzle.seed}) has {puzzle.solutions} path{puzzle.solutions === 1 ? '' : 's'} to a win.
|
||||
Today's <PuzzleTypeDisplay type={puzzleType} /> puzzle (#{puzzle.seed}) has {puzzle.solutions} path{puzzle.solutions === 1 ? '' : 's'} to a win.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -2,6 +2,8 @@ import { h } from 'preact';
|
|||
|
||||
export type PuzzleType = 2 | 3 | 4;
|
||||
|
||||
export const PUZZLE_TYPES: PuzzleType[] = [2, 3, 4];
|
||||
|
||||
export function PuzzleTypeDisplay(props: { type: PuzzleType, active?: boolean }) {
|
||||
const { type, active } = props;
|
||||
const isActive = active === undefined ? true : active;
|
||||
|
|
|
@ -5,7 +5,7 @@ import { gameName, urlParam } from "./util";
|
|||
import "./App.css";
|
||||
import { About } from './About';
|
||||
import { useLocalStorage } from './localstorage';
|
||||
import { PuzzleType, PuzzleTypeDisplay } from './PuzzleType';
|
||||
import { PuzzleType, PuzzleTypeDisplay, PUZZLE_TYPES } from './PuzzleType';
|
||||
|
||||
import * as PUZZLES from './puzzles.json';
|
||||
|
||||
|
@ -18,7 +18,7 @@ type PickPuzzleTypeProps = {
|
|||
|
||||
function PickPuzzleType(props: PickPuzzleTypeProps) {
|
||||
const { puzzleType, setPuzzleType } = props;
|
||||
const PUZZLE_TYPES: PuzzleType[] = [2, 3, 4];
|
||||
|
||||
return (
|
||||
<div class="pick-puzzle-type">
|
||||
{PUZZLE_TYPES.map((type) => (
|
||||
|
|
Loading…
Reference in a new issue