Minigame: Lights out

  • Hallo,
    heute darf ich euch mein Minigame Lights out präsentieren. Es geht darum, so schnell wie möglich alle Lichter auszuknipsen.
    Das Ergebnis kann man dann mit dem seienr Freunde und Kollegen vergleichen.
    Hier die Source:

    Spoiler anzeigen
    [autoit]

    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_outfile=F:\Fertige Programme\Lights out\Lights out.exe
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include<array.au3>
    #include<listviewconstants.au3>
    #include<guilistview.au3>
    #include<gdiplus.au3>
    #include<staticconstants.au3>
    local $ar[41]
    global $i= random(1, 40)
    global $counter=0
    global $gerundet=0
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Lights out", 500, 600, 192, 124)
    $knopf1 = GUICtrlCreateButton("Start", 23, 25, 57, 33, $WS_GROUP)
    $ar[1]= GUICtrlCreateButton("", 24, 64, 57, 57, $WS_GROUP)
    $ar[2]= GUICtrlCreateButton("", 82, 64, 57, 57, $WS_GROUP)
    $ar[3]= GUICtrlCreateButton("", 142, 64, 57, 57, $WS_GROUP)
    $ar[4]= GUICtrlCreateButton("", 203, 64, 57, 57, $WS_GROUP)
    $ar[5]= GUICtrlCreateButton("", 264, 64, 57, 57, $WS_GROUP)
    $ar[6]= GUICtrlCreateButton("", 24, 125, 57, 57, $WS_GROUP)
    $ar[7]= GUICtrlCreateButton("", 82, 125, 57, 57, $WS_GROUP)
    $ar[8]= GUICtrlCreateButton("", 142, 125, 57, 57, $WS_GROUP)
    $ar[9]= GUICtrlCreateButton("", 203, 125, 57, 57, $WS_GROUP)
    $ar[10]= GUICtrlCreateButton("", 264, 125, 57, 57, $WS_GROUP)
    $ar[11]= GUICtrlCreateButton("", 25, 185, 57, 57, $WS_GROUP)
    $ar[12]= GUICtrlCreateButton("", 83, 185, 57, 57, $WS_GROUP)
    $ar[13]= GUICtrlCreateButton("", 143, 185, 57, 57, $WS_GROUP)
    $ar[14]= GUICtrlCreateButton("", 204, 185, 57, 57, $WS_GROUP)
    $ar[15]= GUICtrlCreateButton("", 265, 185, 57, 57, $WS_GROUP)
    $ar[16]= GUICtrlCreateButton("", 25, 246, 57, 57, $WS_GROUP)
    $ar[17]= GUICtrlCreateButton("", 83, 246, 57, 57, $WS_GROUP)
    $ar[18]= GUICtrlCreateButton("", 143, 246, 57, 57, $WS_GROUP)
    $ar[19]= GUICtrlCreateButton("", 204, 246, 57, 57, $WS_GROUP)
    $ar[20]= GUICtrlCreateButton("", 265, 246, 57, 57, $WS_GROUP)
    $ar[21]= GUICtrlCreateButton("", 27, 306, 57, 57, $WS_GROUP)
    $ar[22]= GUICtrlCreateButton("", 85, 306, 57, 57, $WS_GROUP)
    $ar[23]= GUICtrlCreateButton("", 145, 306, 57, 57, $WS_GROUP)
    $ar[24]= GUICtrlCreateButton("", 206, 306, 57, 57, $WS_GROUP)
    $ar[25]= GUICtrlCreateButton("", 267, 306, 57, 57, $WS_GROUP)
    $ar[26]= GUICtrlCreateButton("", 27, 367, 57, 57, $WS_GROUP)
    $ar[27]= GUICtrlCreateButton("", 85, 367, 57, 57, $WS_GROUP)
    $ar[28]= GUICtrlCreateButton("", 145, 367, 57, 57, $WS_GROUP)
    $ar[29]= GUICtrlCreateButton("", 206, 367, 57, 57, $WS_GROUP)
    $ar[30]= GUICtrlCreateButton("", 267, 367, 57, 57, $WS_GROUP)
    $ar[31]= GUICtrlCreateButton("", 27, 429, 57, 57, $WS_GROUP)
    $ar[32]= GUICtrlCreateButton("", 85, 429, 57, 57, $WS_GROUP)
    $ar[33]= GUICtrlCreateButton("", 145, 429, 57, 57, $WS_GROUP)
    $ar[34]= GUICtrlCreateButton("", 206, 429, 57, 57, $WS_GROUP)
    $ar[35]= GUICtrlCreateButton("", 267, 429, 57, 57, $WS_GROUP)
    $ar[36]= GUICtrlCreateButton("", 27, 490, 57, 57, $WS_GROUP)
    $ar[37]= GUICtrlCreateButton("", 85, 490, 57, 57, $WS_GROUP)
    $ar[38]= GUICtrlCreateButton("", 145, 490, 57, 57, $WS_GROUP)
    $ar[39]= GUICtrlCreateButton("", 206, 490, 57, 57, $WS_GROUP)
    $ar[40]= GUICtrlCreateButton("", 267, 490, 57, 57, $WS_GROUP)

    [/autoit] [autoit][/autoit] [autoit]

    For $p= 1 to 40
    guictrlsetstate($ar[$p], $gui_disable)
    guictrlsetbkcolor($ar[$p], 0x000000)
    next
    $Button1 = GUICtrlCreateButton("In die Highscore eintragen", 323, 25, 133, 32, $WS_GROUP)
    $ListView1 = GUICtrlCreateListView("Name des Spielers|Zeit", 323, 65, 240, 241)
    Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($ListView1)]
    GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 110)
    GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 60)
    guictrlsetbkcolor($listview1, 0x000000)
    guictrlsetcolor($listview1, 0xFFFFFF)
    $iniread= IniReadSectionNames(@Scriptdir&"\score.ini")
    $armax=_ArrayMax($iniread)
    For $a=1 to $armax
    guictrlcreatelistviewitem($iniread[$a]&"|"& Iniread(@scriptdir&"\score.ini", $iniread[$a], "1name", ""), $listview1)
    next
    _GUICtrlListView_SimpleSort($listview1, $B_DESCENDING[1], 1)
    soundplay(@Scriptdir&"\st.mp3",0 )
    $Pic1 = GUICtrlCreatePic(@Scriptdir&"\matrix.jpg", 0, 1, 500, 600, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    case $GUI_EVENT_CLOSE
    Exit
    case $knopf1
    For $p= 1 to 40
    guictrlsetstate($ar[$p], $gui_enable)
    next
    $time= Timerinit()
    guictrlsetstate($knopf1, $gui_disable)
    $i= random(1, 40)
    guictrlsetbkcolor($ar[$i], 0x57FF5C)
    case $ar[$i]
    $counter+=1
    If $counter=50 then
    For $p= 1 to 40
    guictrlsetstate($ar[$p], $gui_disable)
    next
    guictrlsetstate($button1, $gui_enable)
    $ungerundet=Timerdiff($time)* 10^(-3)
    $gerundet= StringFormat("%.2f\n", $ungerundet )
    Msgbox(0, "", "Du hast"& $gerundet & "Sekunden gebraucht, um alle Lichter auszuknipsen" )
    $counter=0
    guictrlsetbkcolor($ar[$i], 0xFFFFFF)
    guictrlsetstate($knopf1, $gui_enable)
    else
    guictrlsetbkcolor($ar[$i], 0xFFFFFF)
    $i= random(1, 40)
    guictrlsetbkcolor($ar[$i], 0x57FF5C)
    endif
    case $button1
    If $gerundet=0 then
    msgbox(0, "Fehler", "Du hast noch nicht gespielt")
    Else
    GUICtrlSetState($button1, $gui_disable)
    $input= Inputbox("Dein Name", "Wie ist dein Name?")
    If $input<> 0 and $input<> 1 and $input<> 2 and $input<> 3 and $input<> 4 and $input<> 5 and $input<>6 and $input<> 7 and $input<> 8 and $input<> 9 Then
    Msgbox(0, "Fehler", "Dein Name darf keine Zahlen beeinhalten")
    else
    $name= Iniwrite(@ScriptDir&"\score.ini", $input, "1name", $gerundet)
    $iniread= IniReadSectionNames(@Scriptdir&"\score.ini")
    $armax=_ArrayMax($iniread)
    _GUICtrlListView_DeleteAllItems($listview1)
    For $j=1 to $armax
    guictrlcreatelistviewitem($iniread[$j]&"|"& Iniread(@scriptdir&"\score.ini", $iniread[$j], "1name", ""), $listview1)
    next
    _GUICtrlListView_SimpleSort($listview1, $B_DESCENDING[1],1)
    endif
    endif
    EndSwitch
    wend

    [/autoit]


    Der Downloadlink: http://www.file-upload.net/download-31436…ts-out.rar.html
    Mit dabei ist ne ini, die eigentlich ohnehin erstellt wird^^
    - der Matrixhintergrund
    - und ein kleiner Soundtrack.
    Viel Spaß beim Ausprobieren :)
    Edit1: Kleiner Fehler bemerkt, wird morgen behoben.

    [align=center]Meine Werke mit der Irrlicht Engine
    AutoIt Picture Viewer Dreidimensionaler Bildbetrachter
    Mr Bubble 3D Neue Interpretation des Flashklassikers Bubble trouble

    Einmal editiert, zuletzt von Twodollarbillie (19. Januar 2011 um 20:53)

  • Nettes Spiel, sauber geschrieben! Du kannst Strg+T in Scite benutzen, um den Quellcode sauber einrücken zu lassen.
    Außerdem ist es schade, dass nicht alle Buttons ausgeklickt werden müssen, sondern manche Buttons mehrfach vorkommen.


  • Außerdem ist es schade, dass nicht alle Buttons ausgeklickt werden müssen, sondern manche Buttons mehrfach vorkommen.

    Ne Idee wie man das anders in Autoit umsetzen könnte? Oder wie man ne Funktion auslösen könnte, wenn man auf den falschen Button klickt?
    kleiner ansatz reicht

    [align=center]Meine Werke mit der Irrlicht Engine
    AutoIt Picture Viewer Dreidimensionaler Bildbetrachter
    Mr Bubble 3D Neue Interpretation des Flashklassikers Bubble trouble

    Einmal editiert, zuletzt von Twodollarbillie (22. Januar 2011 um 12:06)

  • Das geht auch einfacher, hier mal ein Beispiel ;).

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <Array.au3>
    #include <Date.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $aLights[40], $aRemaining[40], $bStart = False, $iCurTarget = Random(0, 39, 1), $Timer, $iH, $iM, $iS
    For $i = 0 To 39
    $aRemaining[$i] = $i
    Next

    [/autoit] [autoit][/autoit] [autoit]

    $hWnd = GUICreate("Test", 355, 450, 0, 0)
    $iX = 5
    $iY = 5
    For $i = 1 To 40
    $aLights[$i - 1] = GUICtrlCreateButton("", $iX, $iY, 50, 50)
    GUICtrlSetBkColor(-1, 0x505050)
    $iX += 55
    If Not Mod($i, 5) Then
    $iY += 55
    $iX = 5
    EndIf
    Next
    $cStart = GUICtrlCreateButton("Start", 290, 5, 60, 25)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $cStart
    If $bStart = False Then
    _Reset()
    $bStart = True
    $iCurTarget = $aRemaining[Random(0, UBound($aRemaining) - 1, 1)]
    GUICtrlSetBkColor($aLights[$iCurTarget], 0xFF0000)
    _ArrayDelete($aRemaining, _ArrayInterpolationSearch($aRemaining, $iCurTarget))
    $Timer = TimerInit()
    EndIf
    Case $aLights[$iCurTarget]
    If $bStart Then
    GUICtrlSetState($aLights[$iCurTarget], $GUI_DISABLE)
    GUICtrlSetBkColor($aLights[$iCurTarget], 0x00FF00)

    [/autoit] [autoit][/autoit] [autoit]

    If UBound($aRemaining) = 1 Then
    $iCurTarget = $aRemaining[Random(0, UBound($aRemaining) - 1, 1)]
    GUICtrlSetBkColor($aLights[$iCurTarget], 0xFF0000)
    $aRemaining = 0
    ElseIf UBound($aRemaining) > 1 Then
    $iCurTarget = $aRemaining[Random(0, UBound($aRemaining) - 1, 1)]
    GUICtrlSetBkColor($aLights[$iCurTarget], 0xFF0000)
    _ArrayDelete($aRemaining, _ArrayInterpolationSearch($aRemaining, $iCurTarget))
    ElseIf Not $aRemaining Then
    _TicksToTime(Floor(TimerDiff($Timer)), $iH, $iM, $iS)
    If Not $iH Then
    MsgBox(64, "Info", "Du hast innerhalb von " & StringFormat("%02d:%02d", $iM, $iS) & " Sekunden alle Lichter ausgemacht.")
    Else
    MsgBox(16, "Error", "Mann, bist du langsam! Du hast ganze " & $iH & " Stunden gebraucht.")
    EndIf
    $bStart = False
    EndIf
    EndIf
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _Reset()
    Dim $aRemaining[40]
    For $i = 0 To 39
    GUICtrlSetState($aLights[$i], $GUI_ENABLE)
    GUICtrlSetBkColor($aLights[$i], 0x505050)
    $aRemaining[$i] = $i
    Next
    EndFunc ;==>_Reset

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _ArrayInterpolationSearch(ByRef $a_Search, $iValue, $iStart = 0, $iEnd = -1)
    ; Author: name22 (http://www.autoit.de)
    If $iEnd = -1 Then $iEnd = UBound($a_Search) - 1
    If $a_Search[$iStart] > $iValue Then Return SetError(2, 0, -1)
    If $a_Search[$iEnd] < $iValue Then Return SetError(3, 0, -1)

    [/autoit] [autoit][/autoit] [autoit]

    While $iValue >= $a_Search[$iStart] And $iValue <= $a_Search[$iEnd]
    $iPotentialPos = Round($iStart + (($iValue - $a_Search[$iStart]) / ($a_Search[$iEnd] - $a_Search[$iStart])) * ($iEnd - $iStart))
    Select
    Case $a_Search[$iPotentialPos] = $iValue
    Return $iPotentialPos
    Case $a_Search[$iPotentialPos] > $iValue
    $iEnd = $iPotentialPos - 1
    Case $a_Search[$iPotentialPos] < $iValue
    $iStart = $iPotentialPos + 1
    EndSelect
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Return SetError(1, 0, -1)
    EndFunc ;==>_ArrayInterpolationSearch

    [/autoit]