From 52a09f5f5e6a4a1864fb0aa528c43752c6055e9a Mon Sep 17 00:00:00 2001 From: Neeldhara Misra Date: Tue, 22 Jul 2025 09:57:14 +0530 Subject: [PATCH] Improve Chessboard Repaint Puzzle UI - click squares directly for cleaner interface --- src/components/ChessboardRepaintPuzzle.tsx | 117 ++++++++------------- 1 file changed, 45 insertions(+), 72 deletions(-) diff --git a/src/components/ChessboardRepaintPuzzle.tsx b/src/components/ChessboardRepaintPuzzle.tsx index 7598f55..b96345c 100644 --- a/src/components/ChessboardRepaintPuzzle.tsx +++ b/src/components/ChessboardRepaintPuzzle.tsx @@ -93,32 +93,48 @@ const ChessboardRepaintPuzzle: React.FC = ({ showS } }; + const handleSquareClick = (row: number, col: number) => { + if (isComplete) return; + + // If clicking on the bottom row, repaint the entire row + if (row === 7) { + repaintRow(row); + return; + } + + // If clicking on the rightmost column, repaint the entire column + if (col === 7) { + repaintColumn(col); + return; + } + + // Otherwise, repaint the 2x2 square with this square as top-left + repaint2x2Square(row, col); + }; + const renderSquare = (row: number, col: number) => { const isBlack = board[row][col]; + const isBottomRow = row === 7; + const isRightmostCol = col === 7; + return (
handleSquareClick(row, col)} className={` w-12 h-12 border border-gray-300 flex items-center justify-center cursor-pointer transition-all duration-200 hover:scale-105 ${isBlack ? 'bg-gray-800' : 'bg-gray-100'} + ${isBottomRow || isRightmostCol ? 'hover:bg-blue-100' : ''} `} - /> - ); - }; - - const render2x2Button = (startRow: number, startCol: number) => { - return ( - + {isBottomRow && ( + Row + )} + {isRightmostCol && !isBottomRow && ( + Col + )} +
); }; @@ -176,57 +192,6 @@ const ChessboardRepaintPuzzle: React.FC = ({ showS {/* Chessboard */}
- {/* Row buttons */} -
- {Array.from({ length: 8 }, (_, i) => ( - - ))} -
- - {/* Column buttons */} -
- {Array.from({ length: 8 }, (_, i) => ( - - ))} -
- - {/* 2x2 square buttons */} -
- {Array.from({ length: 7 }, (_, row) => - Array.from({ length: 7 }, (_, col) => ( -
- {render2x2Button(row, col)} -
- )) - )} -
- {/* Chessboard grid */}
{board.map((row, rowIndex) => @@ -243,7 +208,7 @@ const ChessboardRepaintPuzzle: React.FC = ({ showS {isComplete ? ( "🎉 Congratulations! You achieved exactly one black square!" ) : ( - "Click row/column buttons or 2×2 square buttons to repaint. Goal: exactly one black square!" + "Click any square to repaint the 2×2 region with that square as top-left. Click bottom row or rightmost column to repaint entire row/column. Goal: exactly one black square!" )}

@@ -262,8 +227,16 @@ const ChessboardRepaintPuzzle: React.FC = ({ showS Black square
- - Repaint 2×2 square +
+ Row +
+ Click to repaint entire row +
+
+
+ Col +
+ Click to repaint entire column
@@ -293,9 +266,9 @@ const ChessboardRepaintPuzzle: React.FC = ({ showS

How to Play

    -
  1. Repaint a row: Click any "Row X" button to flip all squares in that row (black becomes white, white becomes black).
  2. -
  3. Repaint a column: Click any "Col X" button to flip all squares in that column.
  4. -
  5. Repaint a 2×2 square: Click any "2×2" button to flip all four squares in that 2×2 region.
  6. +
  7. Repaint a 2×2 square: Click any square to flip all four squares in the 2×2 region with that square as the top-left corner.
  8. +
  9. Repaint a row: Click any square in the bottom row (marked "Row") to flip all squares in that entire row.
  10. +
  11. Repaint a column: Click any square in the rightmost column (marked "Col") to flip all squares in that entire column.
  12. Goal: Achieve exactly one black square on the entire board.