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
|
lig = val(Text1.Text) 'obtient le Nbr de ligne
col = val(Text2.Text) 'obtient le Nbr de colonne
'redimensionnes les 2 tableux
ReDim tab_vide(lig - 1, col - 1)
ReDim tab_celule(lig - 1, col - 1)
nb = val(Text3.Text) ' je rentre un pourcentage de cellule vivante
nb_max = lig * col 'je calcule le nombre max de case du tableau
'elimination eventuel des shapes en trop (sauf l'index 0)
'For T = Shape1.Count - 1 To nb_max - 1 Step -1
' Unload Shape1(T)
'Next T'
'là je divise par 100 puisque tu as parlé de %, ligne au dessus
nb1 = Int((nb * nb_max) / 100) 'j'obtiens le nombres de cellules vivantes par rapport aux nombres de cases'
Text4.Text = nb1
Text5.Text = nb_max - nb1
Randomize
V = Int(lig * Rnd)
U = Int(col * Rnd)
ChiffreAleatoire = "|" & CStr(V) & "/" & CStr(U)
T = 0
Do While T < nb1
V = Int(lig * Rnd)
U = Int(col * Rnd)
ChiffrAge = CStr(V) & "/" & CStr(U)
If InStr(ChiffreAleatoire, ChiffrAge) = 0 Then
ChiffreAleatoire = ChiffreAleatoire & "|" & ChiffrAge
T = T + 1
End If
' DoEvents'
Loop
ChiffreAleatoire = ChiffreAleatoire & "|"
V = 0 'pour debug, a remer/supprimer
For T = 0 To lig - 1
For U = 0 To col - 1
idx = (T * col) + U 'la je suis pas sûr, lire la suite apres le code
'Shape1(idx).FillStyle = 0 'a deremer, si pas fait a la construction
'If idx > Shape1.Count - 1 Then
'ajout d'une Shape1 qui manque
' Load Shape1(idx)
' End If'
'placement
'Shape1(idx).Move Shape1(0).Left + (U * Shape1(0).Width), Shape1(0).Top '+ (Shape1(0).Height * T)
'Shape1(idx).Visible = True'
ChiffrAge = "|" & CStr(T) & "/" & CStr(U) & "|"
If InStr(ChiffreAleatoire, ChiffrAge) = 0 Then
tab_vide(T, U) = False
tab_celule(T, U) = "Mort"
'Shape1(idx).FillColor = vbRed'
Else
tab_vide(T, U) = True
tab_celule(T, U) = "Vivant"
'Shape1(idx).FillColor = vbBlack'
End If
Next U
Next T
Text4.Text = nb1
Text5.Text = nb_max - nb1 |
Partager