feat: show current game mode

This commit is contained in:
2025-03-14 18:15:19 +01:00
parent 3bdb9759d3
commit e7e4749ecb
5 changed files with 28 additions and 31 deletions

View File

@ -12,6 +12,7 @@
let selectedJ: number | undefined = undefined; let selectedJ: number | undefined = undefined;
let status: 'incomplete' | 'error' | 'won' = 'incomplete'; let status: 'incomplete' | 'error' | 'won' = 'incomplete';
let valueMode: 'Write' | 'Annotation' = 'Write'; let valueMode: 'Write' | 'Annotation' = 'Write';
let lastMode: Difficulty;
const onSelect = (i: number, j: number) => () => { const onSelect = (i: number, j: number) => () => {
if (i === selectedI && j === selectedJ) { if (i === selectedI && j === selectedJ) {
@ -47,7 +48,7 @@
} }
}; };
const onGameCommand = (mode: string) => { const onGameCommand = (mode: 'reset' | Difficulty) => {
if (mode === 'reset') { if (mode === 'reset') {
board.reset(); board.reset();
board.grid = board.grid; // to trigger reload board.grid = board.grid; // to trigger reload
@ -56,20 +57,21 @@
if (mode === 'easy') board.prepare(Difficulty.Easy); if (mode === 'easy') board.prepare(Difficulty.Easy);
else if (mode === 'medium') board.prepare(Difficulty.Medium); else if (mode === 'medium') board.prepare(Difficulty.Medium);
else if (mode === 'hard') board.prepare(Difficulty.Hard); else if (mode === 'hard') board.prepare(Difficulty.Hard);
lastMode = mode;
} }
}; };
let board: Board; let board: Board;
let jsConfetti: JSConfetti; let jsConfetti: JSConfetti;
onGameCommand('easy'); onGameCommand(Difficulty.Medium);
onMount(() => { onMount(() => {
jsConfetti = new JSConfetti(); jsConfetti = new JSConfetti();
}); });
</script> </script>
<GameCommands onClick={onGameCommand} /> <GameCommands {lastMode} onClick={onGameCommand} />
<p class="py-4 text-center">STATUS: {status}</p> <p class="py-4 text-center">STATUS: {status}</p>
<div class="mx-auto grid max-w-xl grid-cols-[1fr_1fr_1fr_auto] gap-4"> <div class="mx-auto grid max-w-xl grid-cols-[1fr_1fr_1fr_auto] gap-4">

View File

@ -1,22 +1,13 @@
<script lang="ts"> <script lang="ts">
const { onClick } = $props(); const { lastMode, onClick }: { lastMode: string; onClick: (arg0: string) => void } = $props();
</script> </script>
<div class="flex justify-center space-x-2"> <div class="flex justify-center space-x-2">
{#each ['reset', 'easy', 'medium', 'hard'] as mode (mode)}
<button <button
class="cursor-pointer rounded-full bg-cyan-500 px-4 py-2 text-sm text-white" class="cursor-pointer rounded-full bg-cyan-500 px-4 py-2 text-sm text-white capitalize"
onclick={() => onClick('reset')}>Reset</button class:bg-cyan-800={lastMode === mode}
> onclick={() => onClick(mode)}>{mode}</button
<button
class="cursor-pointer rounded-full bg-cyan-500 px-4 py-2 text-sm text-white"
onclick={() => onClick('easy')}>Easy</button
>
<button
class="cursor-pointer rounded-full bg-cyan-500 px-4 py-2 text-sm text-white"
onclick={() => onClick('medium')}>Medium</button
>
<button
class="cursor-pointer rounded-full bg-cyan-500 px-4 py-2 text-sm text-white"
onclick={() => onClick('hard')}>Hard</button
> >
{/each}
</div> </div>

View File

@ -75,7 +75,7 @@
@reference "tailwindcss"; @reference "tailwindcss";
:root { :root {
--accent-color: theme(colors.emerald.400); --accent-color: theme(colors.emerald.300);
--gray: #ccc; --gray: #ccc;
} }
/* Inner Design Option */ /* Inner Design Option */

View File

@ -1,9 +1,9 @@
export enum Difficulty { export enum Difficulty {
Easy, Easy = 'easy',
Medium, Medium = 'medium',
Hard, Hard = 'hard',
Last, Last = 'last',
Done Done = 'done'
} }
export type Case = number | undefined; export type Case = number | undefined;
@ -17,11 +17,11 @@ function shuffleArray<T>(array: Array<T>): void {
function getNumberToKeepFromDifficulty(difficulty: Difficulty) { function getNumberToKeepFromDifficulty(difficulty: Difficulty) {
const rules = { const rules = {
0: 3, easy: 3,
1: 2, medium: 2,
2: 1, hard: 1,
3: 8, last: 8,
4: 9 done: 9
}; };
return rules[difficulty]; return rules[difficulty];
} }

View File

@ -2,6 +2,10 @@
import Board from '$lib/Board.svelte'; import Board from '$lib/Board.svelte';
</script> </script>
<svelte:head>
<title>FUBIKI</title>
</svelte:head>
<h1 class="mb-5 text-center text-6xl font-medium">Fubuki</h1> <h1 class="mb-5 text-center text-6xl font-medium">Fubuki</h1>
<div class="mx-2"> <div class="mx-2">