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