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 90 91 92 93 94 95 96 97 98 99 100
| Option Explicit
'tes variables
Const nblig = 10
Const nbcol = 10
Dim nb As Single
Dim col As Integer
Dim lig As Integer
Dim nb1 As Integer
Dim nb_max As Integer
Dim tab_vide() As Boolean
Dim tab_celule() As String
Dim idx As Integer
'ajouté par moi
Dim ChiffreAleatoire As String
Dim ChiffrAge As String
Dim T As Integer, U As Integer, V As Integer
Private Sub Form_Load()
'placement, initialisation des differents controles
Label5.Move 60, 90: Label5.Caption = "Nbr. Ligne"
Text1.Move 1050, 30, 495, 285: Text1.Text = nblig
Label6.Move 1650, 90: Label6.Caption = "Nbr. Colonne"
Text2.Move 2640, 30, 495, 285: Text2.Text = nbcol
Label4.Move 3270, 90: Label4.Caption = "Pourcentage"
Text3.Move 4260, 30, 495, 285: Text3.Text = "15"
Command1.Move 60, 420, 1215, 255: Command1.Caption = "Go"
Label1.Move 90, 720: Label1.AutoSize = True: Label1.Caption = ""
Label2.Move 90, 960: Label2.AutoSize = True: Label2.Caption = ""
Label3.Move 90, 1200: Label3.AutoSize = True: Label3.Caption = ""
Shape1(0).Move 60, 1440, 315, 315: Shape1(0).FillStyle = 0
Shape1(0).Shape = 3 'circle:
Shape1(0).BorderWidth = 2
End Sub
Private Sub Command1_Click()
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)
'*****************************************************************
'*** ATTENTION IMPERATIF ne pas monter au dela de 90%, ****
'*** peut être moins suivant nb_max(nombre total des cellules)****
'*****************************************************************
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'
Label1 = nb1 'pour debug, a remer/supprimer
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 & "|"
Label2 = ChiffreAleatoire 'pour debug, a remer/supprimer
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 = vbYellow
V = V + 1 'pour debug, a remer/supprimer
End If
Next U
Next T
Label3 = V - 1 'pour debug, a remer/supprimer
End Sub |
Partager