feat: show current game mode
This commit is contained in:
@ -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">
|
||||||
|
@ -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">
|
||||||
<button
|
{#each ['reset', 'easy', 'medium', 'hard'] as mode (mode)}
|
||||||
class="cursor-pointer rounded-full bg-cyan-500 px-4 py-2 text-sm text-white"
|
<button
|
||||||
onclick={() => onClick('reset')}>Reset</button
|
class="cursor-pointer rounded-full bg-cyan-500 px-4 py-2 text-sm text-white capitalize"
|
||||||
>
|
class:bg-cyan-800={lastMode === mode}
|
||||||
<button
|
onclick={() => onClick(mode)}>{mode}</button
|
||||||
class="cursor-pointer rounded-full bg-cyan-500 px-4 py-2 text-sm text-white"
|
>
|
||||||
onclick={() => onClick('easy')}>Easy</button
|
{/each}
|
||||||
>
|
|
||||||
<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
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -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 */
|
||||||
|
@ -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];
|
||||||
}
|
}
|
||||||
|
@ -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">
|
||||||
|
Reference in New Issue
Block a user