4 Gewinnt

  • hi,
    1. ich hab ein kleines 4 Gewinnt gemacht nur habe ich einen fehler i-wie gewinnt immer spieler 2
    2. vllt noch ein paar verbesserungsmöglichkeiten

    [autoit]

    #cs ----------------------------------------------------------------------------

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

    AutoIt Version: 3.3.0.0
    Author: Griss

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

    Script Function: 4 Gewinnt
    Template AutoIt script.

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

    #ce ----------------------------------------------------------------------------

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

    ; Script Start - Add your code below here

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

    #include <GUIConstants.au3>
    #include <EditConstants.au3>
    #include <ButtonConstants.au3>
    #include <StaticConstants.au3>

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

    dim $input[43]
    dim $button[8]
    dim $inp[43]
    dim $spieler = 1, $runde = 0
    dim $spalteh[8][7]
    dim $spaltev[7][8]
    dim $vsplate[7]
    dim $hsplate[8]
    dim $spaltero[13][13]
    dim $spaltelo[13][13]
    dim $lospalte[13]
    dim $rospalte[13]
    dim $mitem[4]

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

    #Region gui
    $Form2 = GUICreate("Spieler Name", 274, 131)
    $GroupBox1 = GUICtrlCreateGroup("", 32, 9, 209, 81)
    $Input1 = GUICtrlCreateInput("Spieler 1", 48, 24, 177, 21)
    $Input2 = GUICtrlCreateInput("Spieler 2", 48, 56, 177, 21)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Button1 = GUICtrlCreateButton("&OK", 96, 96, 73, 25, $BS_DEFPUSHBUTTON)
    GUISetState(@SW_SHOW)
    #EndRegion gui

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

    while 1
    $msg = guigetmsg()

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

    if $msg = $GUI_EVENT_CLOSE then Exit

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

    if $msg = $Button1 Then
    $Namesp1 = guictrlread($Input1)
    $Namesp2 = guictrlread($Input2)
    guictrlsetstate($Form2, @sw_hide)
    ExitLoop
    endif
    wend

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

    #Region ### START Koda GUI section ### Form=e:\dokumente und einstellungen\griss\desktop\koda_1.7.0.1\forms\4gewinnt verbessert2.kxf
    $Form1_1 = GUICreate("Form1", 593, 314, 210, 175)
    $Menu = GuiCtrlCreateMenu("&Menu")
    $mitem[1] = GUICtrlCreateMenuItem("Neues Spiel Starten",$menu)
    $mitem[2] = GUICtrlCreateMenuItem("Beenden",$menu)
    $about = GuiCtrlCreateMenu("&About")
    $Button[1] = GUICtrlCreateButton("Feld 1", 24, 8, 49, 33, 0)
    $Button[2] = GUICtrlCreateButton("Feld 2", 88, 8, 49, 33, 0)
    $Button[3] = GUICtrlCreateButton("Feld 3", 152, 8, 49, 33, 0)
    $Button[4] = GUICtrlCreateButton("Feld 4", 216, 8, 49, 33, 0)
    $Button[5] = GUICtrlCreateButton("Feld 5", 280, 8, 49, 33, 0)
    $Button[6] = GUICtrlCreateButton("Feld 6", 344, 8, 49, 33, 0)
    $Button[7] = GUICtrlCreateButton("Feld 7", 408, 8, 49, 33, 0)
    $Input[1] = GUICtrlCreateInput("", 40, 56, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[2] = GUICtrlCreateInput("", 40, 96, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[3] = GUICtrlCreateInput("", 40, 136, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[4] = GUICtrlCreateInput("", 40, 176, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[5] = GUICtrlCreateInput("", 40, 216, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[6] = GUICtrlCreateInput("", 40, 256, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[7] = GUICtrlCreateInput("", 104, 56, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[8] = GUICtrlCreateInput("", 104, 96, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[9] = GUICtrlCreateInput("", 104, 136, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[10] = GUICtrlCreateInput("", 104, 176, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[11] = GUICtrlCreateInput("", 104, 216, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[12] = GUICtrlCreateInput("", 104, 256, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[13] = GUICtrlCreateInput("", 168, 56, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[14] = GUICtrlCreateInput("", 168, 96, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[15] = GUICtrlCreateInput("", 168, 136, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[16] = GUICtrlCreateInput("", 168, 176, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[17] = GUICtrlCreateInput("", 168, 216, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[18] = GUICtrlCreateInput("", 168, 256, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[19] = GUICtrlCreateInput("", 232, 56, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[20] = GUICtrlCreateInput("", 232, 96, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[21] = GUICtrlCreateInput("", 232, 136, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[22] = GUICtrlCreateInput("", 232, 176, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[23] = GUICtrlCreateInput("", 232, 216, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[24] = GUICtrlCreateInput("", 232, 256, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[25] = GUICtrlCreateInput("", 296, 56, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[26] = GUICtrlCreateInput("", 296, 96, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[27] = GUICtrlCreateInput("", 296, 136, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[28] = GUICtrlCreateInput("", 296, 176, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[29] = GUICtrlCreateInput("", 296, 216, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[30] = GUICtrlCreateInput("", 296, 256, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[31] = GUICtrlCreateInput("", 360, 56, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[32] = GUICtrlCreateInput("", 360, 96, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[33] = GUICtrlCreateInput("", 360, 136, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[34] = GUICtrlCreateInput("", 360, 176, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[35] = GUICtrlCreateInput("", 360, 216, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[36] = GUICtrlCreateInput("", 360, 256, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[37] = GUICtrlCreateInput("", 424, 56, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[38] = GUICtrlCreateInput("", 424, 96, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[39] = GUICtrlCreateInput("", 424, 136, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[40] = GUICtrlCreateInput("", 424, 176, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[41] = GUICtrlCreateInput("", 424, 216, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Input[42] = GUICtrlCreateInput("", 424, 256, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    $Label1 = GUICtrlCreateLabel("Runde: ", 488, 56, 50, 20, $SS_CENTER)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label2 = GUICtrlCreateLabel("Am zug:", 488, 128, 51, 20, $SS_CENTER)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    $Label3 = GUICtrlCreateLabel(" ", 488, 160, 90, 18, $SS_CENTER)
    GUICtrlSetFont(-1, 8, 400, 0, "Arial")
    $Label4 = GUICtrlCreateLabel(" ", 488, 88, 90, 18, $SS_CENTER)
    GUICtrlSetFont(-1, 8, 800, 0, "Arial")

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

    for $i = 1 to 42
    ;guictrlsetstate($Input[$i], $GUI_DISABLE)
    GUICtrlSetBkColor($Input[$i], 0xFFFFFF)
    next

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

    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    guictrlsetdata($Label3 , $Namesp1&" [X]")
    GUICtrlSetFont(-1, 8, 800, 0, "Arial")
    guictrlsetdata($Label4 , $runde)
    GUICtrlSetFont(-1, 8, 800, 0, "Arial")

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

    While 1
    $Msg = GUIGetMsg()

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

    for $i = 1 to 42
    $inp[$i] = guictrlread($input[$i])
    if $inp[$i] = "" then $inp[$i] = " "
    next

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

    if $msg = $GUI_EVENT_CLOSE then Exit

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

    if $msg = $mitem[1] Then
    neu()
    EndIf

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

    if $msg = $mitem[2] Then Exit

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

    ;//

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

    for $i = 1 to 7
    if $msg = $button[$i] Then
    $h = $i * 6
    if $spieler = 2 then
    $runde = $runde + 1
    guictrlsetdata($Label3 , $Namesp1&" [X]")
    GUICtrlSetFont(-1, 8, 800, 0, "Arial")
    guictrlsetdata($Label4 , $runde)
    GUICtrlSetFont(-1, 8, 800, 0, "Arial")
    guisetstate(@sw_show)
    if $inp[$h] <> " " Then
    $h = $h -1
    if $inp[$h] <> " " Then
    $h = $h -1
    if $inp[$h] <> " " Then
    $h = $h -1
    if $inp[$h] <> " " Then
    $h = $h -1
    if $inp[$h] <> " " Then
    $h = $h -1
    Guictrlsetdata($Input[$h], "O")
    Guictrlsetstate($button[$i],$GUI_DISABLE)
    EndIf
    Guictrlsetdata($Input[$h], "O")
    EndIf
    Guictrlsetdata($Input[$h], "O")
    EndIf
    Guictrlsetdata($Input[$h], "O")
    EndIf
    Guictrlsetdata($Input[$h], "O")
    endif
    Guictrlsetdata($Input[$h], "O")
    $spieler = 1
    elseif $spieler = 1 then
    $runde = $runde + 1
    guictrlsetdata($Label3 , $Namesp2&" [O]")
    GUICtrlSetFont(-1, 8, 800, 0, "Arial")
    guictrlsetdata($Label4 , $runde)
    GUICtrlSetFont(-1, 8, 800, 0, "Arial")
    guisetstate(@sw_show)
    if $inp[$h] <> " " Then
    $h = $h -1
    if $inp[$h] <> " " Then
    $h = $h -1
    if $inp[$h] <> " " Then
    $h = $h -1
    if $inp[$h] <> " " Then
    $h = $h -1
    if $inp[$h] <> " " Then
    $h = $h -1
    Guictrlsetdata($Input[$h], "X")
    Guictrlsetstate($button[$i],$GUI_DISABLE)
    EndIf
    Guictrlsetdata($Input[$h], "X")
    EndIf
    Guictrlsetdata($Input[$h], "X")
    EndIf
    Guictrlsetdata($Input[$h], "X")
    EndIf
    Guictrlsetdata($Input[$h], "X")
    endif
    Guictrlsetdata($Input[$h], "X")
    $spieler = 2
    Guictrlsetdata($Input[$h], "X")
    EndIf
    endif
    next

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

    ;msgbox(0,"",$spieler)

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

    ;// Auswerten

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

    for $k = 1 to 7
    if $k = 1 then $h = 6
    if $k = 2 then $h = 12
    if $k = 3 then $h = 18
    if $k = 4 then $h = 24
    if $k = 5 then $h = 30
    if $k = 6 then $h = 36
    if $k = 7 then $h = 42
    for $i = 1 to 6
    $spalteh[$k][$i] = $inp[$h]
    $h = $h - 1
    next
    next

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

    for $k = 1 to 6
    if $k = 1 then $h = 42
    if $k = 2 then $h = 41
    if $k = 3 then $h = 40
    if $k = 4 then $h = 39
    if $k = 5 then $h = 38
    if $k = 6 then $h = 37
    for $i = 1 to 7
    $spaltev[$k][$i] = $inp[$h]
    $h = $h - 6
    next
    next

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

    for $k = 1 to 12
    if $k = 1 then dim $h = 1, $j = 1
    if $k = 2 then dim $h = 2, $j = 2
    if $k = 3 then dim $h = 3, $j = 3
    if $k = 4 then dim $h = 4, $j = 4
    if $k = 5 then dim $h = 5, $j = 5
    if $k = 6 then dim $h = 6, $j = 6
    if $k = 7 then dim $h = 12, $j = 6
    if $k = 8 then dim $h = 18, $j = 5
    if $k = 9 then dim $h = 24, $j = 4
    if $k = 10 then dim $h = 30, $j = 3
    if $k = 11 then dim $h = 36, $j = 2
    if $k = 12 then dim $h = 42, $j = 1
    for $i = 1 to $j
    $spaltero[$k][$i] = $inp[$h]
    $h = $h + 5
    Next
    next

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

    for $k = 1 to 12
    if $k = 1 then dim $h = 37, $j = 1
    if $k = 2 then dim $h = 31, $j = 2
    if $k = 3 then dim $h = 25, $j = 3
    if $k = 4 then dim $h = 19, $j = 4
    if $k = 5 then dim $h = 13, $j = 5
    if $k = 6 then dim $h = 7, $j = 6
    if $k = 7 then dim $h = 1, $j = 6
    if $k = 8 then dim $h = 2, $j = 5
    if $k = 9 then dim $h = 3, $j = 4
    if $k = 10 then dim $h = 4, $j = 3
    if $k = 11 then dim $h = 5, $j = 2
    if $k = 12 then dim $h = 6, $j = 1
    for $i = 1 to $j
    $spaltelo[$k][$i] = $inp[$h]
    $h = $h + 7
    Next
    next

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

    auswerten()
    WEnd

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

    func auswerten()

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

    for $j = 1 to 6
    for $i = 1 to 7
    $vsplate[$j] = $vsplate[$j] & $spaltev[$j][$i]
    If StringInStr($vsplate[$j], "XXXX") Then
    if $spieler = 2 then $spieler = 1
    if $spieler = 1 then $spieler = 2
    msgbox(0,"Gewonnen","Spieler: "&$spieler&" hat gewonnen")
    exit
    endif
    If StringInStr($vsplate[$j], "OOOO") Then
    if $spieler = 2 then $spieler = 1
    if $spieler = 1 then $spieler = 2
    msgbox(0,"Gewonnen","Spieler: "&$spieler&" hat gewonnen")
    exit
    endif
    Next
    Next

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

    for $j = 1 to 7
    for $i = 1 to 6
    $hsplate[$j] = $hsplate[$j] & $spalteh[$j][$i]
    If StringInStr($hsplate[$j], "XXXX") Then
    if $spieler = 2 then $spieler = 1
    if $spieler = 1 then $spieler = 2
    msgbox(0,"Gewonnen","Spieler: "&$spieler&" hat gewonnen")
    exit
    endif
    If StringInStr($hsplate[$j], "OOOO") Then
    if $spieler = 2 then $spieler = 1
    if $spieler = 1 then $spieler = 2
    msgbox(0,"Gewonnen","Spieler: "&$spieler&" hat gewonnen")
    exit
    endif
    Next
    Next

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

    for $j = 1 to 12
    for $i = 1 to 12
    $rospalte[$j] = $rospalte[$j] & $spaltero[$j][$i]
    If StringInStr($rospalte[$j], "XXXX") Then
    if $spieler = 2 then $spieler = 1
    if $spieler = 1 then $spieler = 2
    msgbox(0,"Gewonnen","Spieler: "&$spieler&" hat gewonnen")
    exit
    endif
    If StringInStr($rospalte[$j], "OOOO") Then
    if $spieler = 2 then $spieler = 1
    if $spieler = 1 then $spieler = 2
    msgbox(0,"Gewonnen","Spieler: "&$spieler&" hat gewonnen")
    exit
    endif
    Next
    Next

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

    for $j = 1 to 12
    for $i = 1 to 12
    $rospalte[$j] = $rospalte[$j] & $spaltelo[$j][$i]
    If StringInStr($rospalte[$j], "XXXX") Then
    if $spieler = 2 then $spieler = 1
    if $spieler = 1 then $spieler = 2
    msgbox(0,"Gewonnen","Spieler: "&$spieler&" hat gewonnen")
    exit
    endif
    If StringInStr($rospalte[$j], "OOOO") Then
    if $spieler = 2 then $spieler = 1
    if $spieler = 1 then $spieler = 2
    msgbox(0,"Gewonnen","Spieler: "&$spieler&" hat gewonnen")
    exit
    endif
    Next
    Next

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

    for $i = 1 to 6
    $vsplate[$i] = ""
    Next

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

    for $i = 1 to 7
    $hsplate[$i] = ""
    Next

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

    for $i = 1 to 12
    $lospalte[$i] = ""
    Next

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

    for $i = 1 to 12
    $rospalte[$i] = ""
    Next

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

    endfunc

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

    func neu()
    for $i = 1 to 6
    $vsplate[$i] = ""
    Next

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

    for $i = 1 to 7
    $hsplate[$i] = ""
    Next

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

    for $i = 1 to 12
    $lospalte[$i] = ""
    Next

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

    for $i = 1 to 12
    $rospalte[$i] = ""
    Next
    endfunc

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

    MfG
    Griss

  • So kann man schonmal einiges in der Gui-Section einsparen:

    [autoit]

    For $i = 0 To Ubound ($Button) -1
    $Button[$i] = GUICtrlCreateButton("Feld " & $i+ 1, 24 + $i * 64, 8, 49, 33, 0)
    Next
    For $i = 0 To UBound($input) -1
    $Input[$i] = GUICtrlCreateInput("", 40 + INT($i/ 6) * 64 , 56 + Mod($i, 6) * 40, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    GUICtrlSetBkColor($Input[$i], 0xFFFFFF)
    Next

    [/autoit]

    Zum Rest hab ich im moment keinen Nerv :pinch:

  • Aso ja, hatte bemerkt, das die Zahl in deinem input/button-Array jeweils 1 zu groß war...

    Also:

    [autoit]

    dim $input[42]
    dim $button[7]

    [/autoit]
  • könntest mit den _GDIPlus befehlen ein richtiges 4gewinnt mit Bildern machen ;)
    guckst du autoit ordern -> hilfe^^

  • hi,
    dann geht der rest vom code nicht mehr :D ...
    Aus irgendeinen Grund muss ich immer einen array mehr nehmen sonst funktionierts nicht.

    Einmal editiert, zuletzt von Griss (31. März 2009 um 22:25)

  • Jo wollte grade den Array-Fehler beheben, da hab ich mir gedacht, dass ich auch einfach dein script etwas verkürzen könnte :P
    Hab schonmal den Anfang gemacht, sodass die spieler ihre Markierungen setzen können, jetzt fehlt nur noch ne bessere Variante um den gewinner zu bestimmen...

    Hier ist der Code, hoffe man kann ihn noch einigermaßen nachvollziehen :D:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <EditConstants.au3>
    #include <ButtonConstants.au3>
    #include <StaticConstants.au3>

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

    Opt("GuiOnEventMode", 1)

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

    dim $Ok = false
    dim $input[42]
    dim $button[7]
    dim $spieler = True, $runde = 0
    dim $mitem[4]
    Global $row[7]

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

    #Region gui
    $Form2 = GUICreate("Spieler Name", 274, 131)
    GuiSetOnEvent(-1 , "_Exit")
    GUICtrlCreateGroup("", 32, 9, 209, 81)
    $Input1 = GUICtrlCreateInput("Spieler 1", 48, 24, 177, 21)
    $Input2 = GUICtrlCreateInput("Spieler 2", 48, 56, 177, 21)
    $Button1 = GUICtrlCreateButton("&OK", 96, 96, 73, 25, $BS_DEFPUSHBUTTON)
    GuiCtrlSetOnEvent(-1, "_OkPressed")
    GUISetState(@SW_SHOW)
    #EndRegion gui

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

    Do
    sleep(200)
    Until $Ok = True

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

    $Form1_1 = GUICreate("Form1", 593, 314, 210, 175)
    GuiSetOnEvent(-1 , "_Exit")
    $Menu = GuiCtrlCreateMenu("&Menu")
    $mitem[1] = GUICtrlCreateMenuItem("Neues Spiel Starten",$menu)
    $mitem[2] = GUICtrlCreateMenuItem("Beenden",$menu)
    $about = GuiCtrlCreateMenu("&About")
    For $i = 0 To Ubound ($Button) -1
    $Button[$i] = GUICtrlCreateButton("Feld " & $i+1, 24 + $i * 64, 8, 49, 33, 0)
    GuiCtrlSetOnEvent(-1, "_ButtonEscape")
    Next
    For $i = 0 To UBound($input) -1
    $Input[$i] = GUICtrlCreateInput("", 40 + INT($i/6) * 64 , 56 + Mod($i, 6) * 40, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    GUICtrlSetBkColor($Input[$i], 0xFFFFFF)
    Next
    GUISetFont(10, 400, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("Runde: ", 488, 56, 50, 20, $SS_CENTER)
    $Label2 = GUICtrlCreateLabel("Am zug:", 488, 128, 51, 20, $SS_CENTER)
    GUISetFont(8, 400, 0, "Arial")
    $Label3 = GUICtrlCreateLabel(GuiCtrlRead($Input1) &" [X]", 488, 160, 90, 18, $SS_CENTER)
    $Label4 = GUICtrlCreateLabel($runde, 488, 88, 90, 18, $SS_CENTER)
    GUISetState(@SW_SHOW)

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

    While 1
    sleep(200)
    Wend

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

    Func _ButtonEscape()
    For $i = 0 To Ubound ($Button) -1
    If @GUI_CtrlId = $Button[$i] Then
    If $spieler = True Then
    $row[$i] = $row[$i] & "X"
    _SetItems($i)
    Else
    $row[$i] = $row[$i] & "O"
    _SetItems($i)
    EndIf
    EndIf
    Next
    $spieler = Not $spieler
    EndFunc

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

    Func _SetItems($i)
    $rowSplit = StringSplit($row[$i], "")
    For $j = ((7 + ($i + 1)) * 6 - Ubound ($input)) - 6 To (Ubound ($input) - (7 - ($i + 1)) * 6) - 1
    If $j - ((7 + ($i + 1)) * 6 - Ubound ($input)) +6 < $rowsplit[0] Then
    GuiCtrlSetData($input[($i+1)*5 - Mod($j,6)+ ($i > 0) * $i],$rowsplit[$j - ((7 + ($i + 1)) * 6 - Ubound ($input))+6+1])
    EndIf
    Next
    EndFunc

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

    Func _OkPressed()
    $Ok = True
    GUISetState(@SW_HIDE)
    EndFunc

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

    Func _Exit()
    Exit
    EndFunc

    [/autoit]

    2 Mal editiert, zuletzt von ChaosKeks (1. April 2009 um 00:24)

  • hi,
    ja du hast recht mein code is nicht gerade kleine gehalten aber is ja auch eins meiner ersten Programme (Spiele).
    Nur leider verstehe ich deinen code teils nicht^^
    Bin noch anfänger... ^^
    Was bringt z. B. das?

    [autoit]

    Func _SetItems($i)
    $rowSplit = StringSplit($row[$i], "")
    For $j = ((7 + ($i + 1)) * 6 - Ubound ($input)) - 6 To (Ubound ($input) - (7 - ($i + 1)) * 6) - 1
    If $j - ((7 + ($i + 1)) * 6 - Ubound ($input)) +6 < $rowsplit[0] Then
    GuiCtrlSetData($input[($i+1)*5 - Mod($j,6)+ ($i > 0) * $i],$rowsplit[$j - ((7 + ($i + 1)) * 6 - Ubound ($input))+6+1])
    EndIf
    Next
    EndFunc

    [/autoit]
  • So sry das ich so spät schreibe (stand noch im letzten klausurstress)... also hab grade nochmal an deinem 4-Gewinnt weitergemacht, sodass jetzt das meißte steht... habs mit gut 100 Zeilen (ohne Kommentare) geschafft =] Ersparnis von 300 Zeilen ist meiner Meinung nach nich übel :D
    Bin nich so der beste im Erklären, habs aber mal versucht, hoffe du verstehst es ungefähr oder vllt. kann dir jemand anders das ganze ein bisschen besser schildern ;)

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <EditConstants.au3>
    #include <ButtonConstants.au3>
    #include <StaticConstants.au3>

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

    Opt("GuiOnEventMode", 1)

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

    Local $Ok = False, $spieler = True
    Local $input[42], $button[7], $mItem[4], $plName[2], $runde = 0
    Global $rowY[7], $rowX[6][8]

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

    GUICreate("Spieler Name", 274, 131)
    GuiSetOnEvent(-1 , "_Exit")
    GUICtrlCreateGroup("", 32, 9, 209, 81)
    $plName[0] = GUICtrlCreateInput("Spieler 1", 48, 24, 177, 21)
    $plName[1] = GUICtrlCreateInput("Spieler 2", 48, 56, 177, 21)
    GUICtrlCreateButton("&OK", 96, 96, 73, 25, $BS_DEFPUSHBUTTON)
    GuiCtrlSetOnEvent(-1, "_OkPressed")
    GUISetState(@SW_SHOW)

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

    While Not $Ok
    sleep(200)
    Wend

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

    Func _OkPressed()
    $Ok = True
    GUISetState(@SW_HIDE)
    EndFunc

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

    GUICreate("Form1", 593, 314, 210, 175)
    GuiSetOnEvent(-1 , "_Exit")
    $Menu = GuiCtrlCreateMenu("&Menu")
    $mItem[1] = GUICtrlCreateMenuItem("Neues Spiel Starten",$menu)
    $mItem[2] = GUICtrlCreateMenuItem("Beenden",$menu)
    $about = GuiCtrlCreateMenu("&About")
    ;Schleife stellt alle Buttons her mithilfe einer einfachen rechnung und weißt jedem Button die Funktion _ButtonEscape zu!
    For $i = 0 To Ubound ($Button) -1
    $Button[$i] = GUICtrlCreateButton("Feld " & $i+1, 24 + $i * 64, 8, 49, 33, 0)
    GuiCtrlSetOnEvent(-1, "_ButtonEscape")
    Next
    ;Schleife stellt alle Inputfelder und setzt Bk_Farbe
    ;X-Stellen (40 + INT($i/6) * 64) -> da die schleife alle Reihen >horizontal< abarbeitet, muss folglich nach einer Reihe (bestehend aus 6 inputfeldern)
    ; ein neuer X-Wert kommen... Dieser ist pro Reihe jeweils 64 größer als vorher..Das heißt wenn nun die erste Reihe abarbeitet
    ; ist, wird aus INT($i/6) plötzlich eine 1 die mit 64 multipliziert wird und dem Grundwert (40) hinzugefügt wird...
    ;Y-Stellen (56 + Mod($i, 6) * 40)-> Währendessen alle 6 Inputfelder in den horinzontalen Reihen abgearbeitet werden, muss nun für jedes neue Inputfeld
    ; der Y-Wert neu gesetzt werden. Dieser wird bei jedem Inputfeld um 40 größer...Das heißt wir brauchen einen Rechenterm,
    ; der für eine Abfolge von zahlen (Horinzontale Reihen) pro Inputfeld eine um 1 größere Zahl angibt, wie zuvor und bei jeder
    ; neuen Reihe die angefangen wird, wieder auf 0 gesetzt wird. Genau das macht die Operation Mod. Diese sucht den größten gemeinsamen
    ; Vielfachen von 2 Zahlen und gibt den Rest, der nicht dividiert werden konnte zurück. Ist jedoch die erste Zahl kleiner als die
    ; zweite, so wird (da es keinen ggT gibt) die ganze Zahl zurückgegeben!
    ; Beispiel: $i = 5 (letztes Kästchen der ersten h.Reihe) => Mod(5,6) => ggT nicht vorhanden: 5 < 6 => 5 wird zurückgegeben => 40 + 5*64
    ; $i = 6 (erstes Kästchen der zweiten h.Reihe) => Mod(6,6) => ggT = 6 => Rest 0 => 40 + 0*64
    ; $i = 7 (zweites Kästchen der zweiten h.Reihe) => Mod(7,6) => ggT = 6 => Rest 1 => 40+ 1*64
    ; Der ggT ist immer die 6er-Multiplikation, die am nächsten an der zweiten Zahl ist.. Bei $i = 13 => ggT = 12 (Rest = 1), $i = 27 => ggT = 24 (Rest = 3)
    For $i = 0 To UBound($input) -1
    $Input[$i] = GUICtrlCreateInput(" ", 40 + INT($i/6) * 64 , 56 + Mod($i, 6) * 40, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY))
    GUICtrlSetBkColor($Input[$i], 0xFFFFFF)
    Next
    GUISetFont(10, 400, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("Runde: ", 488, 56, 50, 20, $SS_CENTER)
    $Label2 = GUICtrlCreateLabel("Am zug:", 488, 128, 51, 20, $SS_CENTER)
    GUISetFont(8, 400, 0, "Arial")
    $Label3 = GUICtrlCreateLabel(GuiCtrlRead($plName[0]), 488, 160, 90, 18, $SS_CENTER)
    $Label4 = GUICtrlCreateLabel($runde, 488, 88, 90, 18, $SS_CENTER)
    GUISetState(@SW_SHOW)

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

    While 1
    sleep(200)
    Wend

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

    Func _ButtonEscape()
    For $i = 0 To Ubound ($Button) -1
    ; @Gui_CtrlId = Button der zuletzt gedrückt wurde
    If @GUI_CtrlId = $Button[$i] Then
    If $spieler Then
    $rowY[$i] = $rowY[$i] & "X"
    _SetItems($i)
    Else
    $rowY[$i] = $rowY[$i] & "O"
    _SetItems($i)
    EndIf
    EndIf
    Next
    $spieler = Not $spieler
    $runde += 1
    GuiCtrlSetdata($label4, $runde)
    GuiCtrlSetData($Label3, GuiCtrlRead($plName[Mod($runde+2,2)]))
    EndFunc

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

    ;Meine Taktik: Sobald einer der Buttons gedrückt wurde, wird bestimmt welcher Spieler diesen gedrückt hat, dann wird einem Array $rowY die
    ;spezifische Markierung des Spielers hinzugefügt; daraufhin werden die Inputfelder bestimmt die sich unter dem Button befinden, der zuletzt gedrückt wurde
    ;zuletzt wird jedes Array vom StringSplit von $rowY in Reihenfolge auf die Inputs geschrieben...
    Func _SetItems($i)
    $rowYSplit = StringSplit($rowY[$i], "")
    ;Anfang des InputBereiches (bei der zweiten h.Reihe wäre dies Input[6] >To< Ende des InputBereiches (bei der zweiten h.Reihe wäre dies Input[11])
    For $j = ((7 + ($i + 1)) * 6 - Ubound ($input)) - 6 To (Ubound ($input) - (7 - ($i + 1)) * 6) - 1
    ;Input wird nur beschrieben falls die letzte Zahl der Arrays in $rowYsplit größer als das aktuelle Input ist
    If $j - ((7 + ($i + 1)) * 6 - Ubound ($input)) +6 < $rowYsplit[0] Then
    GuiCtrlSetData($input[($i+1)*5 - Mod($j,6)+ ($i > 0) * $i],$rowYsplit[$j - ((7 + ($i + 1)) * 6 - Ubound ($input))+6+1])
    EndIf
    Next
    If GuiCtrlRead( $input[((7 + ($i + 1)) * 6 - Ubound ($input))-6] ) <> " " Then
    GuiCtrlSetState($Button[$i], $Gui_Disable)
    Endif
    _Results()
    EndFunc

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

    Func _Results()
    For $k = 0 To Ubound($rowY) - 1
    If StringInStr($rowY[$k], "XXXX") Then
    MsgBox(0,"Ergebnis!", GuiCtrlRead($plName[0]) &" hat das Spiel gewonnen!")
    ElseIf StringInStr($rowY[$k], "OOOO") Then
    MsgBox(0,"Ergebnis!", GuiCtrlRead($plName[1]) &" hat das Spiel gewonnen!")
    EndIf
    Next
    For $l = 0 To 5
    For $m = $l To $l + 36 Step +6
    $rowX[$l][$m/6] = GuiCtrlRead($input[$m])
    Next
    $rowX[$l][0] = $rowX[$l][0] & $rowX[$l][1] & $rowX[$l][2] & $rowX[$l][3] & $rowX[$l][4] & $rowX[$l][5] & $rowX[$l][6]
    If StringInStr($rowX[$l][0], "XXXX") Then
    MsgBox(0,"Ergebnis!", GuiCtrlRead($plName[0]) &" hat das Spiel gewonnen!")
    ElseIf StringInStr($rowX[$l][0], "OOOO") Then
    MsgBox(0,"Ergebnis!", GuiCtrlRead($plName[1]) &" hat das Spiel gewonnen!")
    EndIf
    Next
    EndFunc

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

    Func _Exit()
    Exit
    EndFunc

    [/autoit]

    LG, ChaosKeks

  • @ChaosKeks

    Das Spiel selber arbeitet super, aber das Menü oben arbeitet gar nicht und das Fenster schließen über das "X" auch nicht.

    Lieben Gruß,
    Alina

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Geheime Information: ;)
    OuBVU5ebLhHu5QvlnAyQB4A7SzBrvWulwL7RLl2BdH5tI6sIYspeMKeXMSXl

  • hi,
    danke das du dir die mühe gemacht hast das script zu verbesser und eine erklärung zu schreiben!
    Und das script braucht auch viel weniger cpu auslastung ^^
    Nur leider ist es nicht möglich schräg zu gewinnen.
    Ich werde es mal selbst versuchen...

  • Ich weiß, das die diagonalen noch nich drinne sind und noch einiges mehr und das das Fenster noch recht karg aussieht etc etc..
    Wollte nur das Script soweit schreiben,...

    sodass jetzt das meißte steht

    Wenn du das mit den Diagonalen nicht richtig hinbekommst, helfe ich natürlich =p (Im Prinzip musste nur die gleiche Taktik haben wie bei den h.Reihen/v.Reihen)...

  • hi,
    ich komme nicht weiter ^^
    ich wüsste zwar wie ich es machen könnte aber das wird dann wieder so lang.^^
    :edit
    ja weil ich es selbst rausgefunden habe und oben geschaut habe.

    3 Mal editiert, zuletzt von Griss (1. April 2009 um 22:02)

  • Es gibt zwar 42 Felder aber es gibt nicht das 42ste Feld :P Fängt bei Input[0] an und geht bis Input[41] :D

    Edit: Schäm dich du hast deine Frage wegge-edited xP Jo sekunde Ich setz mich ebn dran!

    Edit2: So hab mich vor ner halben stunde drangesetzt und hab endlich die erste lösung!!! also von links nach rechts diagonal geht jetzt... mir raucht aber der kopf, deswegen hau ich nochmal für ne weile ab und mach später weiter :D

    Einmal editiert, zuletzt von ChaosKeks (1. April 2009 um 23:33)

  • Und für die Oberfläche hätte ich hier einen Designvorschlag ;)
    http://www.abload.de/image.php?img=4gewinntpte3.png
    Und ich prüfe immer vom aktuell gesetzten Feld aus mit dieser Funktion:

    Spoiler anzeigen
    [autoit]

    Func _TesteSieg($Reihe,$Spalte)
    ; Prog@ndy
    If $GewinntMatrix[$Reihe][$Spalte] < 1 Then Return 0
    If $Reihe >= $MaxReihe Or $Reihe < 0 Or $Spalte<0 Or $Spalte >= $MaxSpalte Then Return 0

    Local $Spalte1, $Reihe1

    ; senkrecht:
    Local Const $Spieler = $GewinntMatrix[$Reihe][$Spalte]
    Local $Anzahl = 1
    For $Reihe1 = 1 To $GEWINNANZAHL-1
    If ($Reihe+$Reihe1) >= $MaxReihe Or $GewinntMatrix[$Reihe+$Reihe1][$Spalte] <> $Spieler Then ExitLoop
    $Anzahl += 1
    Next
    For $Reihe1 = 1 To $GEWINNANZAHL-1
    If ($Reihe-$Reihe1) < 0 Or $GewinntMatrix[$Reihe-$Reihe1][$Spalte] <> $Spieler Then ExitLoop
    $Anzahl += 1
    Next

    If $Anzahl >= $GEWINNANZAHL Then Return $Spieler

    ;waagrecht
    $Anzahl = 1
    For $Spalte1 = 1 To $GEWINNANZAHL-1
    If ($Spalte+$Spalte1) >= $MaxReihe Or $GewinntMatrix[$Reihe][$Spalte+$Spalte1] <> $Spieler Then ExitLoop
    $Anzahl += 1
    Next
    For $Spalte1 = 1 To $GEWINNANZAHL-1
    If ($Spalte-$Spalte1) < 0 Or $GewinntMatrix[$Reihe][$Spalte-$Spalte1] <> $Spieler Then ExitLoop
    $Anzahl += 1
    Next

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

    If $Anzahl >= $GEWINNANZAHL Then Return $Spieler

    ; Diagonal links oben -> rechts unten
    $Anzahl = 1
    For $DIAGONAL = 1 To $GEWINNANZAHL-1
    If $Reihe-$DIAGONAL < 0 Then ExitLoop
    If $Spalte-$DIAGONAL < 0 Then ExitLoop
    If $GewinntMatrix[$Reihe-$DIAGONAL][$Spalte-$DIAGONAL] <> $Spieler Then ExitLoop
    $Anzahl += 1
    Next
    For $DIAGONAL = 1 To $GEWINNANZAHL-1
    If $Reihe+$DIAGONAL >= $MaxReihe Then ExitLoop
    If $Spalte+$DIAGONAL >= $MaxSpalte Then ExitLoop
    If $GewinntMatrix[$Reihe+$DIAGONAL][$Spalte+$DIAGONAL] <> $Spieler Then ExitLoop
    $Anzahl += 1
    Next

    If $Anzahl >= $GEWINNANZAHL Then Return $Spieler

    ; Diagonal links unten -> rechts oben
    $Anzahl = 1
    For $DIAGONAL = 1 To $GEWINNANZAHL-1
    If $Reihe-$DIAGONAL < 0 Then ExitLoop
    If $Spalte+$DIAGONAL >= $MaxSpalte Then ExitLoop
    If $GewinntMatrix[$Reihe-$DIAGONAL][$Spalte+$DIAGONAL] <> $Spieler Then ExitLoop
    $Anzahl += 1
    Next
    For $DIAGONAL = 1 To $GEWINNANZAHL-1
    If $Reihe+$DIAGONAL >= $MaxReihe Then ExitLoop
    If $Spalte-$DIAGONAL < 0 Then ExitLoop
    If $GewinntMatrix[$Reihe+$DIAGONAL][$Spalte-$DIAGONAL] <> $Spieler Then ExitLoop
    $Anzahl += 1
    Next

    If $Anzahl >= $GEWINNANZAHL Then Return $Spieler

    If __testUnentschieden() Then Return -1

    Return 0
    EndFunc

    [/autoit]
  • Wow klasse Design progandy :thumbup:

    Puuh, also ich bin jetzt bis auf Kleinigkeiten mit dem Script fertig!
    Bitteschön:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <EditConstants.au3>
    #include <ButtonConstants.au3>
    #include <StaticConstants.au3>
    Opt("GuiOnEventMode", 1)

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

    Local $Ok = False, $spieler = True
    Local $input[42], $button[7], $mItem[4], $plName[2], $runde = 0
    Global $rowY[7], $rowX[6][8], $rowZ1[9][39], $rowZ2[6][42]

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

    GUICreate("Spieler-Namen", 274, 131)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUICtrlCreateGroup("", 32, 9, 209, 81)
    $plName[0] = GUICtrlCreateInput("Spieler 1", 48, 24, 177, 21)
    $plName[1] = GUICtrlCreateInput("Spieler 2", 48, 56, 177, 21)
    GUICtrlCreateButton("&OK", 96, 96, 73, 25, $BS_DEFPUSHBUTTON)
    GuiCtrlSetOnEvent(-1, "_OkPressed")
    GUISetState(@SW_SHOW)

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

    While Not $Ok
    sleep(200)
    Wend

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

    Func _OkPressed()
    $Ok = True
    GUISetState(@SW_HIDE)
    EndFunc

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

    GUICreate("4 - Gewinnt", 593, 314, 210, 175)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    $Menu = GuiCtrlCreateMenu("&Menu")
    $mItem[1] = GUICtrlCreateMenuItem("Neues Spiel Starten",$menu)
    GuiCtrlSetOnEvent(-1, "_Neu")
    $mItem[2] = GUICtrlCreateMenuItem("Beenden",$menu)
    GuiCtrlSetOnEvent(-1, "_Exit")
    $about = GuiCtrlCreateMenu("&About")
    For $i = 0 To Ubound ($Button) -1
    $Button[$i] = GUICtrlCreateButton("Feld " & $i+1, 24 + $i * 64, 8, 49, 33, 0)
    GuiCtrlSetOnEvent(-1, "_ButtonEscape")
    Next
    For $i = 0 To UBound($input) -1
    $Input[$i] = GUICtrlCreateInput(" ", 40 + INT($i/6) * 64 , 56 + Mod($i, 6) * 40, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL, $ES_ReadOnly))
    GUICtrlSetBkColor($Input[$i], 0xFFFFFF)
    Next
    GUISetFont(10, 400, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("Runde: ", 488, 56, 50, 20, $SS_CENTER)
    $Label2 = GUICtrlCreateLabel("Am zug:", 488, 128, 51, 20, $SS_CENTER)
    GUISetFont(8, 400, 0, "Arial")
    $Label3 = GUICtrlCreateLabel(GuiCtrlRead($plName[0]), 488, 160, 90, 18, $SS_CENTER)
    $Label4 = GUICtrlCreateLabel($runde, 488, 88, 90, 18, $SS_CENTER)
    GUISetState(@SW_SHOW)

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

    While 1
    sleep(200)
    Wend

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

    Func _ButtonEscape()
    For $i = 0 To Ubound ($Button) -1
    If @GUI_CtrlId = $Button[$i] Then
    If $spieler Then
    $rowY[$i] = $rowY[$i] & "X"
    _SetItems($i)
    Else
    $rowY[$i] = $rowY[$i] & "O"
    _SetItems($i)
    EndIf
    EndIf
    Next
    $spieler = Not $spieler
    $runde += 1
    GuiCtrlSetdata($label4, $runde)
    GuiCtrlSetData($Label3, GuiCtrlRead($plName[Mod($runde+2,2)]))
    EndFunc

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

    Func _SetItems($i)
    $rowYSplit = StringSplit($rowY[$i], "")
    For $j = ((7 + ($i + 1)) * 6 - Ubound ($input)) - 6 To (Ubound ($input) - (7 - ($i + 1)) * 6) - 1
    If $j - ((7 + ($i + 1)) * 6 - Ubound ($input)) +6 < $rowYsplit[0] Then
    GuiCtrlSetData($input[($i+1)*5 - Mod($j,6)+ ($i > 0) * $i],$rowYsplit[$j - ((7 + ($i + 1)) * 6 - Ubound ($input))+6+1])
    EndIf
    Next
    If GuiCtrlRead( $input[((7 + ($i + 1)) * 6 - Ubound ($input))-6] ) <> " " Then
    GuiCtrlSetState($Button[$i], $Gui_Disable)
    Endif
    _Results()
    EndFunc

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

    Func _Results()
    For $k = 0 To Ubound($rowY) - 1
    If StringInStr($rowY[$k], "XXXX") Then
    MsgBox(0,"Ergebnis!", GuiCtrlRead($plName[0]) &" hat das Spiel gewonnen!")
    ElseIf StringInStr($rowY[$k], "OOOO") Then
    MsgBox(0,"Ergebnis!", GuiCtrlRead($plName[1]) &" hat das Spiel gewonnen!")
    EndIf
    Next
    For $l = 0 To 5
    For $m = $l To $l + 36 Step +6
    $rowX[$l][$m/6] = GuiCtrlRead($input[$m])
    Next
    $rowX[$l][0] = $rowX[$l][0] & $rowX[$l][1] & $rowX[$l][2] & $rowX[$l][3] & $rowX[$l][4] & $rowX[$l][5] & $rowX[$l][6]
    _WinnerEscape($rowX[$l][0])
    Next
    For $n = 0 To 5
    For $o = $n + ($n > 2) * Int($n/2) * $n + ($n > 4) * 3 To ($n < 3) * 35 - ($n < 3) * 6 * $n + ($n > 2) * 41 - ($n > 2) * ($n - 3) step +7
    $rowZ2[$n][$o] = GuiCtrlRead($input[$o])
    Next
    $z = $n + ($n > 2) * Int($n/2) * $n + ($n > 4) * 3
    For $p = 1 To (((($n < 3) * 35 - ($n < 3) * 6 * $n + ($n > 2) * 41 - ($n > 2) * ($n - 3))-$z) / 7)+1
    $rowZ2[$n][0] = $rowZ2[$n][0] & $rowZ2[$n][$z]
    $z += 7
    Next
    _WinnerEscape($rowZ2[$n][0])
    For $q = 0 To 5
    $rowZ2[$q][0] = ""
    Next
    Next
    For $n = 3 To 8
    For $o = $n + ($n > 5) * Mod($n,5) * 5 To ($n < 6) * ($n + ($n * 5)) + (($n > 5) * 30 + ($n > 5) * $n) step +5
    $rowZ1[$n][$o] = GuiCtrlRead($input[$o])
    Next
    $z = $n + ($n > 5) * Mod($n,5) * 5
    For $p = 1 To ((($n < 6) * ($n + ($n * 5)) + (($n > 5) * 30 + ($n > 5) * $n)-$z)/5)+1
    $rowZ1[$n][0] = $rowZ1[$n][0] & $rowZ1[$n][$z]
    $z += 5
    Next
    _WinnerEscape($rowZ1[$n][0])
    For $q = 3 To 8
    $rowZ1[$q][0] = ""
    Next
    Next
    EndFunc

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

    Func _WinnerEscape($hRow)
    If StringInStr($hRow, "XXXX") Then
    MsgBox(0,"Ergebnis!", GuiCtrlRead($plName[0]) &" hat das Spiel gewonnen!")
    ElseIf StringInStr($hRow, "OOOO") Then
    MsgBox(0,"Ergebnis!", GuiCtrlRead($plName[1]) &" hat das Spiel gewonnen!")
    EndIf
    EndFunc

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

    Func _Exit()
    Exit
    EndFunc

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

    Func _Neu()
    For $i = 0 To UBound($input) -1
    If $i < 7 Then
    GuiCtrlSetState($button[$i], $Gui_Enable)
    $rowY[$i] = ""
    EndIf
    GUICtrlSetData($Input[$i], " ")
    Next
    EndFunc

    [/autoit]

    Wollte, hier und da nochmal ein wenig versuchen die Terme zu vereinfachen... aber bin im Prinzip mit 250 Zeilen Ersparnis zufrieden! =P
    Wenn dir noch irgendetwas nicht gefällt --> ich bin immer über Beschwerden und neue Herausforderungen glücklich :D

    LG, ChaosKeks

    Einmal editiert, zuletzt von ChaosKeks (2. April 2009 um 07:17)

  • hi,
    ich hab noch ein paar sachen verbessert - eingebaut.

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <EditConstants.au3>
    #include <ButtonConstants.au3>
    #include <StaticConstants.au3>
    Opt("GuiOnEventMode", 1)

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

    Local $Ok = False, $spieler = True
    Local $input[42], $button[7], $mItem[4], $plName[2], $runde = 0
    Global $rowY[7], $rowX[6][8], $rowZ1[9][39], $rowZ2[6][42]

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

    GUICreate("Spieler-Namen", 274, 131)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUICtrlCreateGroup("", 32, 9, 209, 81)
    $plName[0] = GUICtrlCreateInput("Spieler 1", 48, 24, 177, 21)
    $plName[1] = GUICtrlCreateInput("Spieler 2", 48, 56, 177, 21)
    GUICtrlCreateButton("&OK", 96, 96, 73, 25, $BS_DEFPUSHBUTTON)
    GuiCtrlSetOnEvent(-1, "_OkPressed")
    GUISetState(@SW_SHOW)

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

    While Not $Ok
    sleep(200)
    Wend

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

    Func _OkPressed()
    $Ok = True
    GUISetState(@SW_HIDE)
    EndFunc

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

    GUICreate("4 - Gewinnt", 593, 314, 210, 175)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    $Menu = GuiCtrlCreateMenu("&Menu")
    $mItem[1] = GUICtrlCreateMenuItem("Neues Spiel Starten",$menu)
    GuiCtrlSetOnEvent(-1, "_Neu")
    $mItem[2] = GUICtrlCreateMenuItem("Beenden",$menu)
    GuiCtrlSetOnEvent(-1, "_Exit")
    $about = GuiCtrlCreateMenu("&About")
    For $i = 0 To Ubound ($Button) -1
    $Button[$i] = GUICtrlCreateButton("Feld " & $i+1, 24 + $i * 64, 8, 49, 33, 0)
    GuiCtrlSetOnEvent(-1, "_ButtonEscape")
    Next
    For $i = 0 To UBound($input) -1
    $Input[$i] = GUICtrlCreateInput(" ", 40 + INT($i/6) * 64 , 56 + Mod($i, 6) * 40, 25, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL, $ES_ReadOnly))
    GUICtrlSetBkColor($Input[$i], 0xFFFFFF)
    Next
    GUISetFont(10, 400, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("Runde: ", 488, 56, 50, 20, $SS_CENTER)
    $Label2 = GUICtrlCreateLabel("Am zug:", 488, 128, 51, 20, $SS_CENTER)
    GUISetFont(8, 400, 0, "Arial")
    $Label3 = GUICtrlCreateLabel(GuiCtrlRead($plName[0]), 488, 160, 90, 18, $SS_CENTER)
    $Label4 = GUICtrlCreateLabel($runde, 488, 88, 90, 18, $SS_CENTER)
    GUISetState(@SW_SHOW)

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

    While 1
    sleep(200)
    Wend

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

    Func _ButtonEscape()
    For $i = 0 To Ubound ($Button) -1
    If @GUI_CtrlId = $Button[$i] Then
    If $spieler Then
    $rowY[$i] = $rowY[$i] & "X"
    _SetItems($i)
    Else
    $rowY[$i] = $rowY[$i] & "O"
    _SetItems($i)
    EndIf
    EndIf
    Next
    $spieler = Not $spieler
    $runde += 1
    GuiCtrlSetdata($label4, $runde)
    GuiCtrlSetData($Label3, GuiCtrlRead($plName[Mod($runde+2,2)]))
    EndFunc

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

    Func _SetItems($i)
    $rowYSplit = StringSplit($rowY[$i], "")
    For $j = ((7 + ($i + 1)) * 6 - Ubound ($input)) - 6 To (Ubound ($input) - (7 - ($i + 1)) * 6) - 1
    If $j - ((7 + ($i + 1)) * 6 - Ubound ($input)) +6 < $rowYsplit[0] Then
    GuiCtrlSetData($input[($i+1)*5 - Mod($j,6)+ ($i > 0) * $i],$rowYsplit[$j - ((7 + ($i + 1)) * 6 - Ubound ($input))+6+1])
    EndIf
    Next
    If GuiCtrlRead( $input[((7 + ($i + 1)) * 6 - Ubound ($input))-6] ) <> " " Then
    GuiCtrlSetState($Button[$i], $Gui_Disable)
    Endif
    _Results()
    EndFunc

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

    Func _Results()
    For $k = 0 To Ubound($rowY) - 1
    If StringInStr($rowY[$k], "XXXX") Then
    MsgBox(0,"Ergebnis!", GuiCtrlRead($plName[0]) &" hat das Spiel gewonnen!"& @crlf &"In der Runde: " & $runde + 1)
    _Disable()
    ElseIf StringInStr($rowY[$k], "OOOO") Then
    MsgBox(0,"Ergebnis!", GuiCtrlRead($plName[1]) &" hat das Spiel gewonnen!"& @crlf &"In der Runde: " & $runde + 1)
    _Disable()
    EndIf
    Next
    For $l = 0 To 5
    For $m = $l To $l + 36 Step +6
    $rowX[$l][$m/6] = GuiCtrlRead($input[$m])
    Next
    $rowX[$l][0] = $rowX[$l][0] & $rowX[$l][1] & $rowX[$l][2] & $rowX[$l][3] & $rowX[$l][4] & $rowX[$l][5] & $rowX[$l][6]
    _WinnerEscape($rowX[$l][0])
    Next
    For $n = 0 To 5
    For $o = $n + ($n > 2) * Int($n/2) * $n + ($n > 4) * 3 To ($n < 3) * 35 - ($n < 3) * 6 * $n + ($n > 2) * 41 - ($n > 2) * ($n - 3) step +7
    $rowZ2[$n][$o] = GuiCtrlRead($input[$o])
    Next
    $z = $n + ($n > 2) * Int($n/2) * $n + ($n > 4) * 3
    For $p = 1 To (((($n < 3) * 35 - ($n < 3) * 6 * $n + ($n > 2) * 41 - ($n > 2) * ($n - 3))-$z) / 7)+1
    $rowZ2[$n][0] = $rowZ2[$n][0] & $rowZ2[$n][$z]
    $z += 7
    Next
    _WinnerEscape($rowZ2[$n][0])
    For $q = 0 To 5
    $rowZ2[$q][0] = ""
    Next
    Next
    For $n = 3 To 8
    For $o = $n + ($n > 5) * Mod($n,5) * 5 To ($n < 6) * ($n + ($n * 5)) + (($n > 5) * 30 + ($n > 5) * $n) step +5
    $rowZ1[$n][$o] = GuiCtrlRead($input[$o])
    Next
    $z = $n + ($n > 5) * Mod($n,5) * 5
    For $p = 1 To ((($n < 6) * ($n + ($n * 5)) + (($n > 5) * 30 + ($n > 5) * $n)-$z)/5)+1
    $rowZ1[$n][0] = $rowZ1[$n][0] & $rowZ1[$n][$z]
    $z += 5
    Next
    _WinnerEscape($rowZ1[$n][0])
    For $q = 3 To 8
    $rowZ1[$q][0] = ""
    Next
    Next
    EndFunc

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

    Func _WinnerEscape($hRow)
    If StringInStr($hRow, "XXXX") Then
    MsgBox(0,"Ergebnis!", GuiCtrlRead($plName[0]) &" hat das Spiel gewonnen!"& @crlf &"In der Runde: " & $runde + 1)
    _Disable()
    ElseIf StringInStr($hRow, "OOOO") Then
    MsgBox(0,"Ergebnis!", GuiCtrlRead($plName[1]) &" hat das Spiel gewonnen!"& @crlf &"In der Runde: " & $runde + 1)
    _Disable()
    EndIf
    EndFunc

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

    Func _Exit()
    Exit
    EndFunc

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

    Func _Neu()
    For $i = 0 To UBound($input) -1
    If $i < 7 Then
    GuiCtrlSetState($button[$i], $Gui_Enable)
    $rowY[$i] = ""
    EndIf
    GUICtrlSetData($Input[$i], " ")
    Next
    $runde = 0
    $spieler = $plName[0]
    GuiCtrlSetdata($label4, $runde)
    GuiCtrlSetData($Label3, GuiCtrlRead($plName[Mod($runde+2,2)]))
    EndFunc

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

    func _Disable()
    for $i = 0 to Ubound($button) -1
    GuiCtrlSetState($Button[$i], $Gui_Disable)
    Next
    endfunc

    [/autoit]


    Das nächste wäre vllt. einen Bot zu machen :D aber ich habe keine Ahnung wie ich das anfang soll.^^
    Dann vllt. noch ein Desing... aber erstmal ein Bot.

  • Deine Verbesserung (Die Disable-Funktion) packste am besten ans Ende von _WinnerEscape, das spart Zeilen...(Ansonsten hab ich im Prinzip keine Veränderungen bemerkt xD)

    Für Design bettelste am besten progandy für sein stylisches Design an ;)
    Bot wird sich sehr schwer gestalten (trotzdem machbar)... naja stehe im moment etwas im Zeitdruck, deswegen lass ich dich mal die ganze sache versuchen und helf dann später weiter =p

    Wäre auch nicht schlecht wenn der User bestimmen kann wieviele h.Reihen bzw v.Reihen es gibt..

    Chaoskeks

  • Hab mir mal ein paar Bots angeschaut... das ist nicht einfach. Ein billiger Random-Bot dagegen schon :P