Skip to content

Commit

Permalink
added puzzle component
Browse files Browse the repository at this point in the history
  • Loading branch information
gnehs committed Mar 1, 2024
1 parent e8c98a5 commit bee94aa
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
Binary file added public/meme/meme-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/meme/meme-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/meme/meme-3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/app/(game)/puzzle/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import { Menu } from "@/components/Menu";
import { useState } from "react";

import Puzzle from "@/components/Puzzle";
export default function Page() {
const [active, setActive] = useState(0);
return (
Expand All @@ -11,6 +11,8 @@ export default function Page() {
active={active}
setActive={setActive}
/>
<Puzzle src="/meme/meme-1.jpg" done={[2, 4, 5, 7]} size="3x3" />
<Puzzle src="/meme/meme-2.jpg" done={[3, 12, 9, 7]} size="4x4" />
</div>
);
}
40 changes: 40 additions & 0 deletions src/components/Puzzle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { twMerge } from "tailwind-merge";
export default function Puzzle({
src,
done,
size,
}: {
src: string;
done: number[];
size: "3x3" | "4x4";
}) {
return (
<div className="w-full p-2">
<div
className={twMerge(
"grid aspect-square overflow-hidden rounded-md border-4 border-gray-200",
size === "3x3" ? "grid-cols-3" : "grid-cols-4",
)}
style={{
backgroundImage: `url(${src})`,
backgroundSize: "cover",
}}
>
{Array.from({ length: size === "3x3" ? 9 : 16 }).map((_, i) => {
const isDone = done.includes(i + 1);
return (
<div
key={i}
className={twMerge(
"flex select-none items-center justify-center bg-white font-mono text-6xl font-bold text-gray-300",
isDone ? "opacity-0" : "",
)}
>
?
</div>
);
})}
</div>
</div>
);
}

0 comments on commit bee94aa

Please sign in to comment.