Lights out game

Arcticwarrio

Active Member
Joined
Dec 6, 2005
Messages
439
Hi Everyone,

just because i wanted to, i want to try and make a lights out game in excel

i cant figure out how to reset the game without calling a loop or something the part in red

also some kind of pattern generator to start off with (not looked at this yet)

if you want to make it resize columns A to E and rows 1 to 5 as 80 pixels wide and grid border A1:E5

cell G2 says RESET and the score is displayed in G4

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count <> 1 Then Exit Sub
[COLOR=Red]If Target = "G2" Then Range("A1:E5").Interior.ColorIndex = xlNone[/COLOR]
If Target.Column > 5 Or Target.Row > 5 Then GoTo ROW5
ActiveSheet.Unprotect
If Target.Interior.ColorIndex = xlNone Then Target.Interior.ColorIndex = 8 Else Target.Interior.ColorIndex = xlNone
If Target.Row = 5 Then GoTo ROW1
If Target.Offset(1, 0).Interior.ColorIndex = 8 Then Target.Offset(1, 0).Interior.ColorIndex = xlNone Else Target.Offset(1, 0).Interior.ColorIndex = 8
ROW1:
If Target.Column = 5 Then GoTo ROW2
If Target.Offset(0, 1).Interior.ColorIndex = 8 Then Target.Offset(0, 1).Interior.ColorIndex = xlNone Else Target.Offset(0, 1).Interior.ColorIndex = 8
ROW2:
If Target.Row = 1 Then GoTo ROW3
If Target.Offset(-1, 0).Interior.ColorIndex = 8 Then Target.Offset(-1, 0).Interior.ColorIndex = xlNone Else Target.Offset(-1, 0).Interior.ColorIndex = 8
ROW3:
If Target.Column = 1 Then GoTo ROW4
If Target.Offset(0, -1).Interior.ColorIndex = 8 Then Target.Offset(0, -1).Interior.ColorIndex = xlNone Else Target.Offset(0, -1).Interior.ColorIndex = 8
ROW4:
Range("G4").Value = Range("G4").Value + 1
ROW5:
'ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Application.EnableEvents = False
Range("G1").Select
Application.EnableEvents = True
End Sub

p.s. the protect sheet is to stop you from cheating
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,224,583
Messages
6,179,673
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top