WBStartup
WbToScreen 3
Use Screen 3
LoadFont 2,"topaz.font",8
Use IntuiFont 2
GTButton 0,1,242,252,100,15,"Restart",#PLACETEXT_IN
Window 0,0,14,600,300,$140e,"LifeSimAOS v1.0 Obligement version",-1,-1
DefaultOutput
AttachGTList 0,0
Use Window 0
;Creation du tableau contenant les infos sur les cellules
Dim cellules.b(57,24)
;Creation de la copie du tableau contenant les infos sur les cellules
Dim cellules_copie.b(57,24)
comptvoisins.b=0
Gosub InitSim
comptboucles.l=0
;Boucle principale du programme
While ev.l<>#IDCMP_CLOSEWINDOW
comptboucles.l=comptboucles.l+1
Use Window 0
WLocate 10,8
Print "Generation number ",comptboucles.l
;On recupere les evenements qui se produisent dans la fenetre du logiciel
ev.l=Event
;Si on clique sur le bouton RESTART
If ev=64
comptboucles.l=0
Gosub InitSim
EndIf
;Debut du code de la simulation
For compteur2.w=1 To 57 Step 1
For compteur3.w=1 To 24 Step 1
comptvoisins.b=0
If compteur2.w>1
If compteur3.w>1
;HAUT-GAUCHE
If cellules.b(compteur2.w-1,compteur3.w-1)=1
comptvoisins.b=comptvoisins.b+1
EndIf
EndIf
;GAUCHE
If cellules.b(compteur2.w-1,compteur3.w)=1
comptvoisins.b=comptvoisins.b+1
EndIf
;BAS-GAUCHE
If compteur3.w<24
If cellules.b(compteur2.w-1,compteur3.w+1)=1
comptvoisins.b=comptvoisins.b+1
EndIf
EndIf
EndIf
If compteur2.w<57
If compteur3.w>1
;HAUT-DROITE
If cellules.b(compteur2.w+1,compteur3.w-1)=1
comptvoisins.b=comptvoisins.b+1
EndIf
EndIf
;DROITE
If cellules.b(compteur2.w+1,compteur3.w)=1
comptvoisins.b=comptvoisins.b+1
EndIf
;BAS-DROITE
If compteur3.w<24
If cellules.b(compteur2.w+1,compteur3.w+1)=1
comptvoisins.b=comptvoisins.b+1
EndIf
EndIf
EndIf
;HAUT
If compteur3.w>1
If cellules.b(compteur2.w,compteur3.w-1)=1
comptvoisins.b=comptvoisins.b+1
EndIf
EndIf
;BAS
If compteur3.w<24
If cellules.b(compteur2.w,compteur3.w+1)=1
comptvoisins.b=comptvoisins.b+1
EndIf
EndIf
If (comptvoisins.b<2 OR comptvoisins.b>3)
cellules_copie.b(compteur2.w,compteur3.w)=0
Else
If comptvoisins.b=3
cellules_copie.b(compteur2.w,compteur3.w)=1
EndIf
EndIf
Next
Next
For compteur2.w=1 To 57 Step 1
For compteur3.w=1 To 24 Step 1
cellules.b(compteur2.w,compteur3.w)=cellules_copie.b(compteur2.w,compteur3.w)
Next
Next
Gosub RefreshCells
;Fin du code de la simulation
Wend
DetachGTList 0
Free Window 0
End
..InitSim
;Remplissage aleatoire du tableau des cellules
For compteur2.w=1 To 57 Step 1
For compteur3.w=1 To 24 Step 1
cellules.b(compteur2.w,compteur3.w)=Rnd(2)
Next
Next
For compteur2.w=1 To 57 Step 1
For compteur3.w=1 To 24 Step 1
cellules_copie.b(compteur2.w,compteur3.w)=cellules.b(compteur2.w,compteur3.w)
Next
Next
;Tracage du tableau
;Lignes horizontales
For compteur.w=20 To 260 Step 10
Wline 10,compteur.w,580,compteur.w,1
Next
;Lignes verticales
For compteur.w=10 To 580 Step 10
Wline compteur.w,20,compteur.w,260,1
Next
Gosub RefreshCells
Return
..RefreshCells
;Remplissage des cellules
For compteur2.w=11 To 571 Step 10
For compteur3.w=21 To 251 Step 10
WBox compteur2.w,compteur3.w,compteur2.w+8,compteur3.w+8,
cellules.b(Int(compteur2.w/10),Int((compteur3.w/10)-1))
Next
Next
Return
|