1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
Option Explicit
Const nblig = 10
Const nbcol = 10
Dim tab_cell(0 To nblig, 0 To nbcol) As String
Dim tab_vie(0 To nblig, 0 To nbcol) As Boolean
Dim i As Integer
Dim j As Integer
Dim nb As Double
Dim col As Integer
Dim lig As Integer
Dim nb1 As Integer
Dim nb_max As Integer
'Commande principal: on entre un pourcentage de cellule vivante qui est nb, et en fonction de se pourcentage il me les réparti aléatoirement dans tab_cell avec les couleurs normalement.
Private Sub Command1_Click()
Dim tab_vi() As Boolean
Dim tab_cel() As String
Call InitTvie(tab_vi())
Call MortouVivant(tab_vi(), tab_cel())
For i = 0 To nblig
For j = 0 To nbcol
tab_cell(i, j) = ""
Next j
Next i
nb = Text1.Text
nb_max = nblig * nbcol
nb1 = Int(nb * nb_max)
For i = 1 To nb1
Randomize
col = Int(nblig * Rnd() + 1)
lig = Int(nbcol * Rnd() + 1)
tab_cell(col, lig) = "Vivant"
Next i
End Sub
'Initialisation de tab_vie aléatoirement en booléen, ça devrait être bon!'
Private Sub InitTvie(ByRef tab_vi() As Boolean)
Dim i As Integer
Dim j As Integer
Dim val As Integer
For i = 0 To nblig
For j = 0 To nbcol
Randomize
val = CInt(Int(Rnd() + 1))
If val = 0 Then
tab_vi(i, j) = False
End If
Next j
Next i
End Sub
'Sous programme qui sert a dire que lorsque tab_vi=faux alors tab_cell= "mort" et inversement. Mais les couleurs ne fonctionnent pas. Je me demande s'il ne faux pas les mettre dans la commande'
Private Sub MortouVivant(ByRef tab_vi() As Boolean, ByRef tab_cel() As String)
Dim idx As Integer
Dim i As Integer
Dim j As Integer
ReDim tab_cel(nblig, nbcol)
ReDim tab_vi(nblig, nbcol)
For i = 1 To nblig
For j = 1 To nbcol
If tab_vi(i, j) = False Then
tab_cel(i, j) = "Mort"
Else
tab_cel(i, j) = "Vivant"
End If
Shape1(i).FillStyle = 0
Shape1(i).FillColor = vbWhite
If tab_cel(i, j) = "Mort" Then
Shape1(idx).FillColor = vbRed
Else
Shape1(idx).FillColor = vbYellow
End If
Next j
Next i
End Sub |
Partager