Code pour creer le jeu de la vie avec excel
Code with the worksheet where the code will be run
Private Sub CmdClearGrid_Click() Call ClearGrid
End Sub
Private Sub CmdFillGrid_Click() Call FillGridLine
End Sub
Private Sub CmdStart_Click() Me.TxtNumberOfGenerations.Enabled = False If Me.TxtNumberOfGenerations.Text = "" Then Me.TxtNumberOfGenerations.Text = "0" Call GridLineGameOfLife
End Sub
Private Sub CommandButton1_Click() StopGame = True
End Sub
Private Sub TxtNumberOfGenerations_Change() End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If StopSelectionChange = True Then Exit Sub If Intersect(ActiveCell, Range("B2", Cells(MaxValue + 1, MaxValue + 1))) Is Nothing Then 'no action Else If Target.Interior.Color = 0 Then Target.Interior.Color = 16777215 Else Target.Interior.Color = 0 End If End If Cells(1, 1).Select
End Sub
Fill_gridline module
Dim i As Integer
Sub FillGridLine() StopSelectionChange = True Dim RandomValue As Byte Application.ScreenUpdating = False For i = 0 To MaxValue2 - MaxValue RandomValue = Int(Rnd * 2) Select Case RandomValue Case Is = 0 Cells(ConvertNbrRow(i), ConvertNbrColumn(i)).Interior.Color = 0 Case Is = 1 Cells(ConvertNbrRow(i), ConvertNbrColumn(i)).Interior.Color = 16777215 End Select Next i Application.ScreenUpdating = True StopSelectionChange = False
End Sub
Sub ClearGrid() StopSelectionChange = True For i = 0 To MaxValue2 Cells(ConvertNbrRow(i), ConvertNbrColumn(i)).Interior.Color = 16777215 Cells(ConvertNbrRow(i), ConvertNbrColumn(i)).Select Next i StopSelectionChange = False ProjectGridOfLife.Sheet2.LblNumberOfGenerations.Caption = ""
End Sub
Gridline
Option Explicit
Option Base 1
Global StopSelectionChange As Boolean
Public Const MaxValue As Integer = 50
Public Const MaxValue2 As Integer = MaxValue ^ 2 - 1
Dim GridRow As Integer, GridCol As Integer, NeighborCell As Integer
Dim ColCell As