Code

This is a convenience variable that specifies the pattern many of the below functions take when they are expecting a "GameBoard" argument.

GameBoard = Table[True | False, {5}, {5}];

Create a new clear game board with all lights initially set to false.

ClearBoard[] := Table[False, {5}, {5}];

Adjust the given game board after a move has been made.  Toggle the light that was pressed, as well as the lights immediately above, below, to the left, and to the right of the light that was pressed.

AdjustBoard[board : GameBoard, x_Integer, 
          y_Integer] := 
Module[{b = 
              board}, 
b[[y, 
                x]] = ! b[[y, x]]; 
If[x > 1, 
            b[[y, x - 1]] = ! b[[y, 
                    x - 1]]]; 
If[x < 5, 
            b[[y, x + 1]] = ! b[[y, 
                    x + 1]]]; 
If[y > 1, 
            b[[y - 1, 
                  x]] = ! b[[y - 1, x]]]; 
If[
            y < 5, b[[y + 1, 
                  x]] = ! b[[y + 1, 
                    x]]]; 
b
];

Create a new game board with the given number of moves made in reverse as its initial state.  Ideally, the more moves made, the harder the board would be to solve.  But for this particular game that's not quite the case, since many moves can cancel each other out...

NewBoard[
          iter_Integer] := 
Module[{b = 
              ClearBoard[]}, 
Do[
            b = AdjustBoard[
                b, 
Random[
                  Integer, {1, 5}], 
Random[
                  Integer, {1, 
                    5}]
], {iter}]; 
b
];

Set the current game board in the notebook window to the given game board state.  If a board already exists, find it and overwrite it, otherwise create a new game board.

SetBoard[
          board : GameBoard] := 
Module[{nb = 
              ButtonNotebook[]}, 
If[
              nb =!= $Failed && 
                NotebookFind[nb, "GameBoard", All, 
                    CellTags] =!= $Failed, 
NotebookWrite[
                nb, Cell[BoxData[MakeGrid[board]], 
                  CellTags -> "GameBoard", Editable -> False], 
                All], 
CellPrint[
                Cell[BoxData[MakeGrid[board]], CellTags -> "GameBoard", 
                  Editable -> 
                    False]]
];
];

Take appropriate action when one of the lights is clicked.  First adjust the board as necessary.  Next check to see if the player won (if all the lights are off or False) and do a little animation if they did.

ClickBoard[board : GameBoard, x_Integer, 
          y_Integer] := 
Module[{b = board, xx, 
            yy}, 
b = 
            AdjustBoard[board, x, y]; 
If[
            FreeQ[b, 
              True], 
Do[
b = 
                ClearBoard[]; 
b[[yy, xx]] = 
                True; 
SetBoard[b], {yy, 1, 5}, {xx, 1, 
                5}]; 
b = 
              ClearBoard[]
]; 
SetBoard[
            b];
];

Create a button box to represent a given light on the game board.  It's color will indicate its state, and the button function will do the appropriate action to toggle the light.

\(\(MakeButton[board : GameBoard, x_Integer, 
          y_Integer] := 
ButtonBox[" ", 
Active -> 
            True, 
ButtonEvaluator -> 
            Automatic, 
ButtonFunction :> 
            ClickBoard[board, x, y], 
ButtonMargins -> 
            10, 
Background -> 
            If[board[\([y, x]\)], RGBColor[1, 0, 0], 
              RGBColor[0, 0, 1]]
];\)\)

Create a grid box containing the appropriate buttons to represent a given game board.

MakeGrid[
          board : GameBoard] := 
GridBox[
Table[
            Table[MakeButton[board, x, y], {x, 1, 5}], {y, 1, 
              5}], 
RowSpacings -> 0.1, 
          ColumnSpacings -> 0.1
];

Game

Each of the buttons in the grid below represents a light.  The red buttons indicate a light that is on, while the blue buttons indicate a light that is off.  The purpose of this game is to get all of the lights of.  Each time you press a light the state of that light will change, as will the state of the lights immediately above, below, to the left, and to the right of the light you pressed.

({{Easy Game, Medium Game, Difficult Game}})