@@ -194,12 +194,20 @@ export default function PuzzleClient() {
194
194
const [ isWon , setIsWon ] = useState ( false ) ;
195
195
const tileSize = containerSize / gridSize ;
196
196
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
+
197
202
useEffect ( ( ) => {
198
203
const arr = randomLegalScramble ( gridSize ) ;
199
204
setTiles ( arr ) ;
200
205
setTileOffsets ( arr . map ( ( ) => ( { x : 0 , y : 0 } ) ) ) ;
201
206
setIsDraggingTile ( arr . map ( ( ) => false ) ) ;
202
207
setIsWon ( false ) ;
208
+ setMoveCount ( 0 ) ;
209
+ setEasyMode ( false ) ;
210
+ setShowEasyModePrompt ( false ) ;
203
211
} , [ puzzleImages , gridSize ] ) ;
204
212
205
213
// Whenever tiles change, check if puzzle is solved
@@ -243,6 +251,15 @@ export default function PuzzleClient() {
243
251
copy [ j ] = false ;
244
252
return copy ;
245
253
} ) ;
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
+ } ) ;
246
263
}
247
264
248
265
// ------------------------------------------------------
@@ -467,6 +484,35 @@ export default function PuzzleClient() {
467
484
</ >
468
485
) }
469
486
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
+
470
516
< div
471
517
className = "border"
472
518
style = { {
@@ -551,7 +597,13 @@ export default function PuzzleClient() {
551
597
fill
552
598
className = "object-cover pointer-events-none"
553
599
/>
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
+ ) }
555
607
</ div >
556
608
) ;
557
609
} ) }
0 commit comments