Game of life

Pubblicità

Talos

Utente Èlite
Messaggi
4,801
Reazioni
1,233
Punteggio
138
salve a tutti ragazzi , a scuola abbiamo fatto il gioco della vita
Gioco Life di Conway - Wikipedia
ora il professore mi ha chiesto di fare un do while loop che esegua in automatico quello che io invece vado a fare cliccando piu volte sullo stesso bottone , cliccandoci 1 sola volta !
in sostanza il loop dove dovrei metterlo?

( fatto in vba )

Private Sub SECONDAGENERAZIONE_Click()
variabile--->fl = 1
Do While fl = 1

For r = 4 To 11
For c = 4 To 11
cont = 0
If Workbooks(1).Worksheets("Gioco vita").Cells(r - 1, c - 1) = 1 And _
Workbooks(1).Worksheets("Gioco vita").Cells(r - 1, c - 1) <> "" Then
cont = cont + 1
End If

If Workbooks(1).Worksheets("Gioco vita").Cells(r - 1, c) = 1 And _
Workbooks(1).Worksheets("Gioco vita").Cells(r - 1, c) <> "" Then
cont = cont + 1
End If

If Workbooks(1).Worksheets("Gioco vita").Cells(r, c - 1) = 1 And _
Workbooks(1).Worksheets("Gioco vita").Cells(r, c - 1) <> "" Then
cont = cont + 1
End If

If Workbooks(1).Worksheets("Gioco vita").Cells(r + 1, c + 1) = 1 And _
Workbooks(1).Worksheets("Gioco vita").Cells(r + 1, c + 1) <> "" Then
cont = cont + 1
End If

If Workbooks(1).Worksheets("Gioco vita").Cells(r + 1, c - 1) = 1 And _
Workbooks(1).Worksheets("Gioco vita").Cells(r + 1, c - 1) <> "" Then
cont = cont + 1
End If

If Workbooks(1).Worksheets("Gioco vita").Cells(r - 1, c + 1) = 1 And _
Workbooks(1).Worksheets("Gioco vita").Cells(r - 1, c + 1) <> "" Then
cont = cont + 1
End If

If Workbooks(1).Worksheets("Gioco vita").Cells(r + 1, c) = 1 And _
Workbooks(1).Worksheets("Gioco vita").Cells(r + 1, c) <> "" Then
cont = cont + 1
End If

If Workbooks(1).Worksheets("Gioco vita").Cells(r, c + 1) = 1 And _
Workbooks(1).Worksheets("Gioco vita").Cells(r, c + 1) <> "" Then
cont = cont + 1
End If


If Workbooks(1).Worksheets("Gioco vita").Cells(r, c) = 1 Then
If cont = 2 Or cont = 3 Then
Workbooks(1).Worksheets("Gioco vita").Cells(r + 75, c) = 1
Else
Workbooks(1).Worksheets("Gioco vita").Cells(r + 75, c) = 0
End If
Else
If cont = 3 Then
Workbooks(1).Worksheets("Gioco vita").Cells(r + 75, c) = 1
Else
Workbooks(1).Worksheets("Gioco vita").Cells(r + 75, c) = 0
End If
End If

Next c
Next r

For r = 4 To 11
For c = 4 To 11
Workbooks(1).Worksheets("Gioco vita").Cells(r, c) = Workbooks(1).Worksheets("Gioco vita").Cells(r + 75, c)

If Workbooks(1).Worksheets("Gioco vita").Cells(r, c) = 1 Then
Cells(r, c).Interior.Color = RGB(228, 121, 4)
Cells(r, c).Characters.Font.Color = RGB(228, 121, 4)
Else
Cells(r, c).Interior.Color = RGB(0, 0, 0)
Cells(r, c).Characters.Font.Color = RGB(0, 0, 0)
End If

Next
Next

End Sub
 
Pubblicità
Pubblicità
Indietro
Top