Code pour creer le jeu de la vie avec excel

Disponible uniquement sur Etudier
  • Pages : 4 (844 mots )
  • Téléchargement(s) : 0
  • Publié le : 19 avril 2011
Lire le document complet
Aperçu du document
GAME OF LIFE EXCEL VBA CODE:

Code with the worksheet where the code will be run
Private Sub CmdClearGrid_Click()
Call ClearGrid
End Sub

Private Sub CmdFillGrid_Click()
CallFillGridLine
End Sub

Private Sub CmdStart_Click()
Me.TxtNumberOfGenerations.Enabled = False
If Me.TxtNumberOfGenerations.Text = "" Then Me.TxtNumberOfGenerations.Text = "0"
Call GridLineGameOfLife
EndSub

Private Sub CommandButton1_Click()
StopGame = True
End Sub

Private Sub TxtNumberOfGenerations_Change()

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
IfStopSelectionChange = 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 ThenTarget.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 = TrueDim 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 = TrueStopSelectionChange = 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
GlobalStopSelectionChange 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...
tracking img