Hallo Leute,
bin letztens auf diese Internetseite gestoßen: http://www.mathematische-basteleien.de/gameoflife.htm
und dachte mir ich würde das gerne in AutoIt nachprogrammieren.
Nun das hier ist das Ergebnis:
[autoit]
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Array.au3>
Global $iGUIw = 500, $iGUIh = 600, $iWidth = 10, $iHeight = 10, $iBlack = 0x000000, $iWhite = 0xffffff, $iZeit = 1,$iAlleTod
Global $iYSize = 50, $iXSize = 50, $aControlID[$iYSize][$iXSize], $aKolonie[$iYSize][$iXSize]
$hGUI = GUICreate("SpielDesLebens", $iGUIw, $iGUIh)
$hBtnStop = GUICtrlCreateButton("Stop",310,550,50,50)
$hBtnStart = GUICtrlCreateButton("Start", 200, 550, 100, 50)
$hLabel = GUICtrlCreateLabel("Zyklen:", 10, 550, 50, 50)
$hZeit = GUICtrlCreateLabel($iZeit, 60, 550, 100, 50)
For $y = 0 To UBound($aControlID) - 1
For $x = 0 To UBound($aControlID) - 1
$aKolonie[$y][$x] = 0
$aControlID[$y][$x] = GUICtrlCreateGraphic($x * $iWidth, $y * $iHeight, $iWidth, $iHeight)
GUICtrlSetBkColor(-1, $iWhite)
Next
Next
GUISetState(@SW_SHOW)
_Start()
[/autoit][autoit][/autoit][autoit]Func _Start()
While 1
Sleep(10)
Global $hMsg = GUIGetMsg()
If $hMsg = $GUI_EVENT_CLOSE Then Exit
For $y = 0 To UBound($aControlID) - 1
For $x = 0 To UBound($aControlID) - 1
If $hMsg = $aControlID[$y][$x] Then
If $aKolonie[$y][$x] = 1 Then
GUICtrlSetBkColor($aControlID[$y][$x], $iWhite)
$aKolonie[$y][$x] = 0
Else
GUICtrlSetBkColor($aControlID[$y][$x], $iBlack)
$aKolonie[$y][$x] = 1
EndIf
EndIf
Next
Next
If $hMsg = $hBtnStart Then
$iStop = 1
Do
_Leben()
$iZeit += 1
GUICtrlSetData($hZeit, $iZeit)
_Zeichen()
$hMsg = GUIGetMsg()
Until $iAlleTod = 0 Or $hMsg = $hBtnStop
EndIf
WEnd
EndFunc
Func _Zeichen()
GUISetState(@SW_LOCK)
For $y = 0 To UBound($aKolonie) - 1
For $x = 0 To UBound($aKolonie) - 1
If $aKolonie[$y][$x] = 1 Then
GUICtrlSetBkColor($aControlID[$y][$x], $iBlack)
EndIf
If $aKolonie[$y][$x] = 2 Then
GUICtrlSetBkColor($aControlID[$y][$x], $iWhite)
EndIf
Next
Next
GUISetState(@SW_UNLOCK)
EndFunc
Func _Leben()
Local $aNeueKolonie[$iYSize][$iXSize]
$iAlleTod = 0
For $y = 0 To $iYSize - 1
For $x = 0 To $iXSize - 1
Local $iNachbarn = 0
If $x - 1 <> -1 Then
If $aKolonie[$y][$x - 1] = 1 Then $iNachbarn += 1
EndIf;Links
If $x + 1 <> UBound($aKolonie) Then
If $aKolonie[$y][$x + 1] = 1 Then $iNachbarn += 1
EndIf;Rechts
If $y - 1 <> -1 Then
If $aKolonie[$y - 1][$x] = 1 Then $iNachbarn += 1
EndIf;Oben
If $y + 1 <> UBound($aKolonie) Then
If $aKolonie[$y + 1][$x] = 1 Then $iNachbarn += 1
EndIf;Unten
If $y - 1 <> -1 And $x - 1 <> -1 Then
If $aKolonie[$y - 1][$x - 1] = 1 Then $iNachbarn += 1
EndIf;Links Oben
If $y + 1 <> UBound($aKolonie) And $x - 1 <> -1 Then
If $aKolonie[$y + 1][$x - 1] = 1 Then $iNachbarn += 1
EndIf;Links Unten
If $y - 1 <> -1 And $x + 1 <> UBound($aKolonie) Then
If $aKolonie[$y - 1][$x + 1] = 1 Then $iNachbarn += 1
EndIf;Rechts Oben
If $y + 1 <> UBound($aKolonie) And $x + 1 <> UBound($aKolonie) Then
If $aKolonie[$y + 1][$x + 1] = 1 Then $iNachbarn += 1
EndIf;Rechts Unten
If $aKolonie[$y][$x] = 2 Or $aKolonie[$y][$x] = 0 Then
If $iNachbarn = 3 Then
$aNeueKolonie[$y][$x] = 1
$iAlleTod = 1
EndIf
EndIf
If $aKolonie[$y][$x] = 1 Then
If $iNachbarn = 2 Or $iNachbarn = 3 Then
$aNeueKolonie[$y][$x] = 1
$iAlleTod = 1
Else
$aNeueKolonie[$y][$x] = 2
EndIf
EndIf
Next
Next
$aKolonie = $aNeueKolonie
EndFunc
Die Geschwindigkeit lässt natürlich zu wünschen übrig, eventuell wäre hier der Einsatz von GDIPlus deutlich besser. Auch die Berechnung der nächsten "Kolonie" ist aus dem Kindergarten aber Hej! was soll's es funktioniert
Ich empfehle euch besonders die verschiedenen Gleiter auszuprobieren. Bis dahin viel Spaß