Skip to content

Commit 62b2a18

Browse files
committed
easy mode prompt
1 parent 7e4bad0 commit 62b2a18

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

src/app/PuzzleClient.tsx

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,20 @@ export default function PuzzleClient() {
194194
const [isWon, setIsWon] = useState(false);
195195
const tileSize = containerSize / gridSize;
196196

197+
// Add these new state variables near the other useState declarations
198+
const [moveCount, setMoveCount] = useState(0);
199+
const [easyMode, setEasyMode] = useState(false);
200+
const [showEasyModePrompt, setShowEasyModePrompt] = useState(false);
201+
197202
useEffect(() => {
198203
const arr = randomLegalScramble(gridSize);
199204
setTiles(arr);
200205
setTileOffsets(arr.map(() => ({ x: 0, y: 0 })));
201206
setIsDraggingTile(arr.map(() => false));
202207
setIsWon(false);
208+
setMoveCount(0);
209+
setEasyMode(false);
210+
setShowEasyModePrompt(false);
203211
}, [puzzleImages, gridSize]);
204212

205213
// Whenever tiles change, check if puzzle is solved
@@ -243,6 +251,15 @@ export default function PuzzleClient() {
243251
copy[j] = false;
244252
return copy;
245253
});
254+
255+
// Increment move count and check if we should show easy mode prompt
256+
setMoveCount((prev) => {
257+
const newCount = prev + 1;
258+
if (newCount === 40) {
259+
setShowEasyModePrompt(true);
260+
}
261+
return newCount;
262+
});
246263
}
247264

248265
// ------------------------------------------------------
@@ -467,6 +484,35 @@ export default function PuzzleClient() {
467484
</>
468485
)}
469486

487+
{showEasyModePrompt && !isWon && (
488+
<div className="absolute top-0 left-0 w-full h-full bg-black bg-opacity-50 z-50 flex flex-col items-center justify-center text-center">
489+
<div className="bg-white dark:bg-gray-800 p-6 rounded-lg max-w-sm mx-4">
490+
<h2 className="text-2xl mb-4">Need a hint?</h2>
491+
<p className="mb-4">
492+
Would you like to enable easy mode? This will show the tile
493+
numbers.
494+
</p>
495+
<div className="flex gap-4 justify-center">
496+
<button
497+
className="px-4 py-2 bg-primary text-white rounded hover:opacity-90"
498+
onClick={() => {
499+
setEasyMode(true);
500+
setShowEasyModePrompt(false);
501+
}}
502+
>
503+
Yes, please
504+
</button>
505+
<button
506+
className="px-4 py-2 border border-gray-300 rounded hover:bg-gray-100 dark:hover:bg-gray-700"
507+
onClick={() => setShowEasyModePrompt(false)}
508+
>
509+
No, thanks
510+
</button>
511+
</div>
512+
</div>
513+
</div>
514+
)}
515+
470516
<div
471517
className="border"
472518
style={{
@@ -551,7 +597,13 @@ export default function PuzzleClient() {
551597
fill
552598
className="object-cover pointer-events-none"
553599
/>
554-
<div className="text-center text-md absolute">{tile}</div>
600+
{easyMode && (
601+
<div className="absolute inset-0 flex items-center justify-center">
602+
<span className="bg-white bg-opacity-75 dark:bg-black dark:bg-opacity-75 px-2 py-1 rounded text-lg font-bold">
603+
{tile + 1}
604+
</span>
605+
</div>
606+
)}
555607
</div>
556608
);
557609
})}

0 commit comments

Comments
 (0)