• Hallo liebe gemeinde :)

    Ich habe mich mal rangesetzt und 4 Gewinnt geschrieben :)
    Man kann die Namen der Spieler eingeben und dann wie bei dem normalen 4 Gewinnt abwechselnd spielen...

    Hier mal der Quellcode:

    Spoiler anzeigen
    [autoit]

    #include <Constants.au3>
    #include <Array.au3>
    #include <GUIConstants.au3>
    #include <WindowsConstants.au3>
    #include <GuiButton.au3>

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

    ;Gui
    ;Gui
    Global $title="4 Gewinnt"
    Global $buttonanzahl=42
    Global $high
    Global $width
    Global $buttonh=40
    Global $buttonw=40
    Global $button[$buttonanzahl]
    Global $buttonhoriz=7
    Global $buttonverti=6
    Global $main
    Global $reset
    ;Zählervariabeln
    Global $i,$h,$c,$v=$buttonanzahl-1
    Global $abstandweite=0
    Global $abstandhoehe=0
    ;Spielervariabeln
    Global $p1rot="Rot"
    Global $p2gelb="Gelb"
    Global $gelb=0xffff00
    Global $rot=0xff0000
    Global $scorerot=0
    Global $scoregelb=0
    Global $unentschieden=0
    Global $turn=$rot
    Global $aktuell
    Global $win=0
    Global $rottext=" "
    Global $gelbtext=" "
    Global $scorebuttonred
    Global $scorebuttongelb
    Global $labeltext=$p1rot

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

    $high=$buttonh*$buttonverti+80
    $width=$buttonw*$buttonhoriz+20
    Guicreate("Spielernamen",220,100)
    $input1=GUICtrlCreateInput("Roter Spieler",10,10)
    $input2=GUICtrlCreateInput("Gelber Spieler",10,40)
    $check=GUICtrlCreateButton("Spiel Starten",85,70)

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

    GUISetState(@SW_SHOW)
    Do
    $msg = GUIGetMsg($main)
    If $msg = $check Then
    $p1rot=GUICtrlRead($input1)
    $p2gelb=GUICtrlRead($input2)
    GUIDelete()
    ExitLoop
    EndIf
    Until $msg = -3

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

    $labeltext=$p1rot
    ; Gui
    $main=GUICreate($title,$width,$high)
    ;Buttons erstellen
    For $i=0 to $buttonverti-1 step +1
    For $h=0 to $buttonhoriz-1 step +1
    $button[$v]=GUICtrlCreateButton(" ",10+$abstandweite,75+$abstandhoehe,$buttonw,$buttonh)
    $abstandweite=$abstandweite+$buttonw
    $v=$v-1
    Next
    $abstandhoehe=$abstandhoehe+$buttonh
    $abstandweite=0
    Next
    ;Text oben
    GUICtrlCreateLabel("4 Gewinnt - Coded by me ^^",10,10,160)
    Guictrlsetfont(-1,9)
    GUICtrlCreateLabel("Spielerstände:",10,30,80)
    Guictrlsetfont(-1,9)
    GUICtrlCreateLabel("Rot:",120,30,80)
    Guictrlsetfont(-1,9)
    $scorebuttonred=GUICtrlCreateLabel($scorerot,145,30)
    Guictrlsetfont(-1,11)
    GUICtrlCreateLabel("Gelb:",200,30,80)
    Guictrlsetfont(-1,9)
    $scorebuttongelb=GUICtrlCreateLabel($scoregelb,232,30)
    Guictrlsetfont(-1,11)
    $reset=GUICtrlCreateButton("Reset",255,5)
    $aktuell=GUICtrlCreateLabel("--- Du bist dran "&$labeltext&". ---",60,50,200)
    Guictrlsetfont(-1,9)

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

    ;GUI Anzeigen
    GUISetState(@SW_SHOW)
    Do
    $msg = GUIGetMsg($main)
    ;Reset button Funktion
    If $reset = $msg Then
    _clearall()
    EndIf
    ;Alle buttons abfragen
    For $i=0 to Ubound($button)-1
    If $button[$i] = $msg Then
    If GUICtrlRead($button[$i])=" " Then
    ;Wenn über 1. Zeile dann nachschauen ob darunter leer sind
    If $i>=7 Then
    $mod=mod($i,7)
    If Guictrlread($button[$mod])=" " Then
    _setfield($mod)
    _gewinner()
    _checkall()
    Else
    For $mod=$mod to $buttonanzahl-1 step +$buttonhoriz
    If Guictrlread($button[$mod])=" " Then
    _setfield($mod)
    _gewinner()
    _checkall()
    ExitLoop
    EndIf
    Next
    EndIf
    Else
    ;Wenn 1. Zeile Feld Setzen
    _setfield($i)
    EndIf
    EndIf

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

    EndIf
    Next
    Until $msg = -3

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

    Func _gewinner()
    Local $w=0
    Local $s=0
    Local $winr=0,$wing=0
    ;Horizontale Abfrage auf gewinner
    For $c=0 to $buttonanzahl-1 step +7
    For $w=0 to 3 step +1
    For $s=0 to 3 step +1
    If Guictrlread($button[$w+$s+$c])=$rottext Then
    $winr=$winr+1
    EndIf
    If Guictrlread($button[$w+$s+$c])=$gelbtext Then
    $wing=$wing+1
    EndIf
    Next
    If $winr=4 Then
    MsgBox(0,"Gewinner","Spieler Rot hat gewonnen!")
    _clearall()
    $scorerot=$scorerot+1
    GUICtrlSetData($scorebuttonred,$scorerot)
    $winr=0
    $wing=0
    Elseif $wing=4 Then
    MsgBox(0,"Gewinner","Spieler Gelb hat gewonnen!")
    _clearall()
    $scoregelb=$scoregelb+1
    GUICtrlSetData($scorebuttongelb,$scoregelb)
    $wing=0
    $winr=0
    Else
    $winr=0
    $wing=0
    EndIf
    Next
    Next
    ; Horizontale abfrage fertig

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

    ;Vertikale abfrage auf gewinner
    For $c=0 to 7 step +1
    For $w=0 to 13 step +1
    For $s=0 to 21 step +7
    If Guictrlread($button[$w+$s+$c])=$rottext Then
    $winr=$winr+1
    EndIf
    If Guictrlread($button[$w+$s+$c])=$gelbtext Then
    $wing=$wing+1
    EndIf
    Next
    If $winr=4 Then
    MsgBox(0,"Gewinner","Spieler Rot hat gewonnen!")
    _clearall()
    $scorerot=$scorerot+1
    GUICtrlSetData($scorebuttonred,$scorerot)
    $winr=0
    $wing=0
    Elseif $wing=4 Then
    MsgBox(0,"Gewinner","Spieler Gelb hat gewonnen!")
    _clearall()
    $scoregelb=$scoregelb+1
    GUICtrlSetData($scorebuttongelb,$scoregelb)
    $wing=0
    $winr=0
    Else
    $winr=0
    $wing=0
    EndIf
    Next
    Next
    ;Vertikale abfrage fertig

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

    ;Diagonale abfrage auf gewinner
    ;Diagonal von unten rechts nach oben Links
    For $c=0 to 7 step +1
    For $w=0 to 10 step +1
    For $s=0 to 24 step +8
    If Guictrlread($button[$w+$s+$c])=$rottext Then
    $winr=$winr+1
    EndIf
    If Guictrlread($button[$w+$s+$c])=$gelbtext Then
    $wing=$wing+1
    EndIf
    Next
    If $winr=4 Then
    MsgBox(0,"Gewinner","Spieler Rot hat gewonnen!")
    _clearall()
    $scorerot=$scorerot+1
    GUICtrlSetData($scorebuttonred,$scorerot)
    $winr=0
    $wing=0
    Elseif $wing=4 Then
    MsgBox(0,"Gewinner","Spieler Gelb hat gewonnen!")
    _clearall()
    $scoregelb=$scoregelb+1
    GUICtrlSetData($scorebuttongelb,$scoregelb)
    $wing=0
    $winr=0
    Else
    $winr=0
    $wing=0
    EndIf
    Next
    Next
    ;Diagonal von unten links nach oben rechts
    For $c=3 to 17 step +7
    For $w=0 to 4 step +1
    For $s=0 to 18 step +6
    If Guictrlread($button[$w+$s+$c])=$rottext Then
    $winr=$winr+1
    EndIf
    If Guictrlread($button[$w+$s+$c])=$gelbtext Then
    $wing=$wing+1
    EndIf
    Next
    If $winr=4 Then
    MsgBox(0,"Gewinner","Spieler Rot hat gewonnen!")
    _clearall()
    $scorerot=$scorerot+1
    GUICtrlSetData($scorebuttonred,$scorerot)
    $winr=0
    $wing=0
    Elseif $wing=4 Then
    MsgBox(0,"Gewinner","Spieler Gelb hat gewonnen!")
    _clearall()
    $scoregelb=$scoregelb+1
    GUICtrlSetData($scorebuttongelb,$scoregelb)
    $wing=0
    $winr=0
    Else
    $winr=0
    $wing=0
    EndIf
    Next
    Next
    ;Diagonale abfrage fertig
    EndFunc

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

    Func _setfield($i)
    GUICtrlSetBkColor($button[$i],$turn)
    If $turn=$rot Then
    GUICtrlSetData($button[$i],$rottext)
    $turn=$gelb
    $labeltext=$p2gelb
    GUICtrlSetData($aktuell,"--- Du bist dran "&$labeltext&". ---")
    Else
    GUICtrlSetData($button[$i],$gelbtext)
    $turn=$rot
    $labeltext=$p1rot
    GUICtrlSetData($aktuell,"--- Du bist dran "&$labeltext&". ---")
    EndIf
    EndFunc

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

    Func _checkall()
    Local $allcheck=0
    For $c=0 to 41 step +1
    If Guictrlread($button[$c])=" " Then
    sleep(0)
    Else
    $allcheck=$allcheck+1
    EndIf
    Next
    If $allcheck=42 Then
    MsgBox(0,"Unentschieden","Das Spiel ist unentschieden ausgegangen, probiert es doch einfach nochmal")
    _clearall()
    $allcheck=0
    Else
    $allcheck=0
    EndIf
    EndFunc

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

    Func _clearall()
    For $c=0 to 41 step +1
    _GUICtrlButton_SetStyle($button[$c], $GUI_SS_DEFAULT_GUI)
    GUICtrlSetData($button[$c]," ")
    Next
    EndFunc

    [/autoit]

    Im Anhand die .au3 zum Download...

    Würde mich über verbesserungen, Lob, Kritik freuen...

    Was ich mir noch vorgestellt habe ist das man das über Netzwerk spielen kann aber damit habe ich mich noch nie befasst... weiß also nicht wie ich da anfangen sollt und umschreiben müsste... aber nunja so ist es finde ich auch schonmal ausreichend :)

    MFG: Blacky911

    Kleiner AutoIt Lehrling :)

  • @ Blume: Das geht bei Autoit auch? ^^ hab das nie versucht kannt das nur bei C++

    @ Andere: Klar kann man das Grafisch noch etwas aufwerten aber finde es so erstmal ausreichend...
    Aber hättet ihr ein paar links wo ich mir mal anschauen könnte das etwas grafischer zu machen?

    Und wie sieht es aus mit der Lan fähigkeit habe mir das so vorgestellt das ich oben noch 2 Buttons mache mit einmal Spiel Hosten und Spiel suchen... aber weiß nicht in wie weit das realisierbar ist und ob sich es da nich lohnen würd alles neu zu schreiben...

    MFG: Blacky911

    Kleiner AutoIt Lehrling :)

  • Lan Fähigkeit? Dafür sollte TCP sehr gut geeignet sein.
    Fals du dich mit GDI+ noch nicht auskennst, oder noch nicht so gut, ("Aber hättet ihr ein paar links wo ich mir mal anschauen könnte das etwas grafischer zu machen?")
    kannst du dir das hier mal anschauen. Es gibt aber auch noch andere sehr gute Tutorials.

    mfg BB

    "IF YOU'RE GOING TO KILL IT
    OPEN SOURCE IT!"

    by Phillip Torrone

    Zitat von Shoutbox

    [Heute, 11:16] Andy: ....böseböseböseböse....da erinnere ich mich daran, dass man den Puschelschwanz eines KaRnickels auch "Blume" nennt....ob da eins zum anderen passt? :rofl: :rofl: :rofl: :rofl:

    https://autoit.de/index.php?page…leIt#post251138

    Neon Snake