• Hallo @all,
    ich stelle euch mal mein Spiel vor das ich am Wochenende gecodet habe vor.
    Es ist ein Tic-Tac-Toe Spiel für 2 Personen in AutoIt.

    Bedienung:
    Einfach in das Feld klicken, das man für sich beanspruchen möchte.
    Die Felder werden mit "deiner" Farbe eingefärbt.

    Version 2:
    Vorhandende Features: (neu)
    -> Siegeserkennung (auch bei unentschieden)
    -> Farbe selber festlegen
    -> Abfragen zum Beenden/Neustarten
    -> Anzeige welcher Spiler am Zug ist.
    -> KI (= der PC spielt mit dir) :D

    Geplante Features:
    -

    Hier jetzt aber das Skript:
    [autoit]

    #include <GUIConstantsEx.au3>
    #NoTrayIcon

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

    Global $Felder_Anzeige[10][10]
    Global $Felder_Status[10][10]
    $AS = 1
    For $i1 = 1 to 3;Felder Status auf 0 setzen
    For $i2 = 1 to 3
    $Felder_Status[$i1][$i2] = 0
    Next
    Next
    $KI = false

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

    ; [1][1] | [2][1] | [3][1]
    ;--------|--------|--------
    ; [1][2] | [2][2] | [3][2]
    ;--------|--------|--------
    ; [1][3] | [2][3] | [3][3]

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

    If MsgBox(36, "Wichtige Frage", "Soll Spieler 2 der Computer sein?") = 6 Then;Abfrage zur aktivierung der KI
    $KI = true
    EndIf

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

    Do;Farbe Festlegen
    $FARBE_S1 = InputBox("Welche Farbe? (S1)", "Grün = 0x32CD32 | Gelb = 0xFFD700" & @CRLF & "Rot = 0xFF0000 | Blau = 0x1874CD", "0x32CD32", " M9")
    Until @error = 0
    Do
    If $KI = true Then
    $FARBE_S2 = InputBox("Welche Farbe für den PC-Gegner?", "Grün = 0x32CD32 | Gelb = 0xFFD700" & @CRLF & "Rot = 0xFF0000 | Blau = 0x1874CD", "0xFFD700", " M9")
    Else
    $FARBE_S2 = InputBox("Welche Farbe? (S2)", "Grün = 0x32CD32 | Gelb = 0xFFD700" & @CRLF & "Rot = 0xFF0000 | Blau = 0x1874CD", "0xFFD700", " M9")
    EndIf
    If $FARBE_S1 = $FARBE_S2 Then MsgBox(16, "Kleiner Hinweis!", "Diese Farbe hat schon Spieler !1")
    Until @error = 0 and $FARBE_S1 <> $FARBE_S2

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

    GUIcreate("Tic-Tac-Toe", 305, 325);GUI erstellen
    GUICtrlCreateLabel("", 0, 0, 305, 325)
    GUIctrlSetBkColor(-1, 0x000000)
    GUICtrlSetDefBkColor(0xFFFFFF)
    $SA = GUICtrlCreateLabel("Aktuell am Zug: Spieler 1.", 0, 0, 305)
    $Felder_Anzeige[1][1] = GUICtrlCreateLabel("", 0, 20, 95, 95)
    $Felder_Anzeige[1][2] = GUICtrlCreateLabel("", 0, 125, 95, 95)
    $Felder_Anzeige[1][3] = GUICtrlCreateLabel("", 0, 230, 95, 95)
    $Felder_Anzeige[2][1] = GUICtrlCreateLabel("", 105, 20, 95, 95)
    $Felder_Anzeige[2][2] = GUICtrlCreateLabel("", 105, 125, 95, 95)
    $Felder_Anzeige[2][3] = GUICtrlCreateLabel("", 105, 230, 95, 95)
    $Felder_Anzeige[3][1] = GUICtrlCreateLabel("", 210, 20, 95, 95)
    $Felder_Anzeige[3][2] = GUICtrlCreateLabel("", 210, 125, 95, 95)
    $Felder_Anzeige[3][3] = GUICtrlCreateLabel("", 210, 230, 95, 95)
    GUISetState(@SW_SHOW)

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

    While 1
    $H = WinGetHandle("Tic-Tac-Toe")
    $mouse = GUIGetCursorInfo($H)
    If GUIGetMsg($H) = $GUI_EVENT_CLOSE Then _EXIT1()
    If $mouse[2] = 1 Then
    For $i1 = 1 to 3;Eingaben überprüfen
    For $i2 = 1 to 3
    If $mouse[4] = $Felder_Anzeige[$i1][$i2] and $Felder_Status[$i1][$i2] = 0 Then
    $Felder_Status[$i1][$i2] = $AS
    If $KI = false Then
    If $AS = 1 Then
    GUICtrlSetBkColor($Felder_Anzeige[$i1][$i2], $FARBE_S1)
    $AS = 2
    GUICtrlSetData($SA, "Aktuell am Zug: Spieler 2.")
    Else
    GUICtrlSetBkColor($Felder_Anzeige[$i1][$i2], $FARBE_S2)
    $AS = 1
    GUICtrlSetData($SA, "Aktuell am Zug: Spieler 1.")
    EndIf
    _GU()
    Else
    GUICtrlSetBkColor($Felder_Anzeige[$i1][$i2], $FARBE_S1)
    $AS = 2
    _GU()
    If $AS = 2 Then
    GUICtrlSetData($SA, "Aktuell am Zug: Der Computer.")
    _KI()
    _GU()
    GUICtrlSetData($SA, "Aktuell am Zug: Spieler 1.")
    $AS = 1
    EndIf
    EndIf
    EndIf
    Next
    Next
    Sleep(200)
    EndIf
    WEnd

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

    Func _EXIT1()
    If MsgBox(36, "Wichtige Frage", "Wirklich beenden?") = 6 Then
    Exit
    EndIf
    EndFunc ;==>_EXIT1

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

    Func _EXIT()
    GUICtrlSetData($SA, "Aktuell am Zug: Niemand!")
    If MsgBox(36, "Wichtige Frage", "Nochmal spielen?") = 6 Then
    For $i1 = 1 to 3;Felder Status auf 0 setzen
    For $i2 = 1 to 3
    $Felder_Status[$i1][$i2] = 0
    Next
    Next
    For $i1 = 1 to 3;Felder Farbe auf Weiß setzen
    For $i2 = 1 to 3
    GUICtrlSetBkColor($Felder_Anzeige[$i1][$i2], 0xFFFFFF)
    Next
    Next
    $AS = 1
    GUICtrlSetData($SA, "Aktuell am Zug: Spieler 1.")
    Else
    Exit
    EndIf
    EndFunc ;==>_EXIT

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

    Func _GU()
    For $i = 1 to 2;Auf Gewinn überprüfen
    If $Felder_Status[1][1] = $i and $Felder_Status[1][2] = $i and $Felder_Status[1][3] = $i Then
    MsgBox(0, "Tic-Tac-Toe", "Spieler " & $i & " gewinnt =>> Spalte 1")
    _EXIT()
    EndIf
    If $Felder_Status[2][1] = $i and $Felder_Status[2][2] = $i and $Felder_Status[2][3] = $i Then
    MsgBox(0, "Tic-Tac-Toe", "Spieler " & $i & " gewinnt =>> Spalte 2")
    _EXIT()
    EndIf
    If $Felder_Status[3][1] = $i and $Felder_Status[3][2] = $i and $Felder_Status[3][3] = $i Then
    MsgBox(0, "Tic-Tac-Toe", "Spieler " & $i & " gewinnt =>> Spalte 3")
    _EXIT()
    EndIf

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

    If $Felder_Status[1][1] = $i and $Felder_Status[2][1] = $i and $Felder_Status[3][1] = $i Then
    MsgBox(0, "Tic-Tac-Toe", "Spieler " & $i & " gewinnt =>> Zeile 1")
    _EXIT()
    EndIf
    If $Felder_Status[1][2] = $i and $Felder_Status[2][2] = $i and $Felder_Status[3][2] = $i Then
    MsgBox(0, "Tic-Tac-Toe", "Spieler " & $i & " gewinnt =>> Zeile 2")
    _EXIT()
    EndIf
    If $Felder_Status[1][3] = $i and $Felder_Status[2][3] = $i and $Felder_Status[3][3] = $i Then
    MsgBox(0, "Tic-Tac-Toe", "Spieler " & $i & " gewinnt =>> Zeile 3")
    _EXIT()
    EndIf

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

    If $Felder_Status[1][1] = $i and $Felder_Status[2][2] = $i and $Felder_Status[3][3] = $i Then
    MsgBox(0, "Tic-Tac-Toe", "Spieler " & $i & " gewinnt =>> Quer 1 (LO <-> RU)")
    _EXIT()
    EndIf
    If $Felder_Status[1][3] = $i and $Felder_Status[2][2] = $i and $Felder_Status[3][1] = $i Then
    MsgBox(0, "Tic-Tac-Toe", "Spieler " & $i & " gewinnt =>> Quer 2 (LU <-> RO)")
    _EXIT()
    EndIf
    Next
    If $Felder_Status[1][1] <> 0 and $Felder_Status[1][2] <> 0 and $Felder_Status[1][3] <> 0 and $Felder_Status[2][1] <> 0 and $Felder_Status[2][2] <> 0 and $Felder_Status[2][3] <> 0 and $Felder_Status[3][1] <> 0 and $Felder_Status[3][2] <> 0 and $Felder_Status[3][3] <> 0 Then
    MsgBox(0, "Tic-Tac-Toe", "Unentschieden!")
    _EXIT()
    EndIf
    EndFunc ;==>_GU

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

    Func _KI()
    For $i = 1 to 3;Testen ob es eine reihe zu Blocken/Vervollständigen gibt.
    If $Felder_Status[$i][1] <> 0 and $Felder_Status[$i][2] <> 0 Then
    $NF = $Felder_Status[$i][3]
    $NF_2 = $i
    $NF_3 = 3
    $R_V = true
    ExitLoop
    ElseIf $Felder_Status[$i][1] <> 0 and $Felder_Status[$i][3] <> 0 Then
    $NF = $Felder_Status[$i][2]
    $NF_2 = $i
    $NF_3 = 2
    $R_V = true
    ExitLoop
    ElseIf $Felder_Status[$i][2] <> 0 and $Felder_Status[$i][3] <> 0 Then
    $NF = $Felder_Status[$i][1]
    $NF_2 = $i
    $NF_3 = 1
    $R_V = true
    ExitLoop

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

    ElseIf $Felder_Status[1][$i] <> 0 and $Felder_Status[2][$i] <> 0 Then
    $NF = $Felder_Status[3][$i]
    $NF_2 = 3
    $NF_3 = $i
    $R_V = true
    ExitLoop
    ElseIf $Felder_Status[1][$i] <> 0 and $Felder_Status[3][$i] <> 0 Then
    $NF = $Felder_Status[2][$i]
    $NF_2 = 2
    $NF_3 = $i
    $R_V = true
    ExitLoop
    ElseIf $Felder_Status[2][$i] <> 0 and $Felder_Status[3][$i] <> 0 Then
    $NF = $Felder_Status[1][$i]
    $NF_2 = 1
    $NF_3 = $i
    $R_V = true
    ExitLoop

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

    ElseIf $Felder_Status[1][1] = $i and $Felder_Status[2][2] = $i Then
    $NF = $Felder_Status[3][3]
    $NF_2 = 3
    $NF_3 = 3
    $R_V = true
    ExitLoop
    ElseIf $Felder_Status[3][3] = $i and $Felder_Status[2][2] = $i Then
    $NF = $Felder_Status[1][1]
    $NF_2 = 1
    $NF_3 = 1
    $R_V = true
    ExitLoop
    ElseIf $Felder_Status[1][1] = $i and $Felder_Status[3][3] = $i Then
    $NF = $Felder_Status[2][2]
    $NF_2 = 2
    $NF_3 = 2
    $R_V = true
    ExitLoop

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

    ElseIf $Felder_Status[1][3] = $i and $Felder_Status[2][2] = $i Then
    $NF = $Felder_Status[3][1]
    $NF_2 = 3
    $NF_3 = 1
    $R_V = true
    ExitLoop
    ElseIf $Felder_Status[3][1] = $i and $Felder_Status[2][2] = $i Then
    $NF = $Felder_Status[1][3]
    $NF_2 = 1
    $NF_3 = 3
    $R_V = true
    ExitLoop
    ElseIf $Felder_Status[1][3] = $i and $Felder_Status[3][1] = $i Then
    $NF = $Felder_Status[2][2]
    $NF_2 = 2
    $NF_3 = 2
    $R_V = true
    ExitLoop
    Else
    $R_V = false
    EndIf
    Next

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

    If $R_V = true Then;Testen ob gefundenes Feld unbelegt ist
    If $NF = 0 Then
    $Felder_Status[$NF_2][$NF_3] = 2
    GUICtrlSetBkColor($Felder_Anzeige[$NF_2][$NF_3], $FARBE_S2)
    Else
    $R_V = false
    EndIf
    EndIf

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

    If $R_V = false Then;Solange ein Feld per Zufall aussuchen, bis eins gefunden ist, dass frei ist.
    Do
    $R1 = Random(1, 3, 1)
    $R2 = Random(1, 3, 1)
    Until $Felder_Status[$R1][$R2] = 0
    $Felder_Status[$R1][$R2] = 2
    GUICtrlSetBkColor($Felder_Anzeige[$R1][$R2], $FARBE_S2)
    EndIf
    EndFunc ;==>_KI

    [/autoit]


    Lob/Kritik/Verbesserungsvorschläge werden immer gerne gesehen. ;)

  • Hi Script-Bär !

    Ich finde das Spiel richtig gut :)
    Aber was man verändern könnte wäre vielleicht
    das man selbst die Farben der Spieler auswählen kann
    und das nach jedem Spiel eine MsgBox() kommt wo gefragt
    wird ob man noch einmal Spielen möchte ich finde das nämlich ein
    bisschen lästig immer wieder das Spiel neu zu Starten.

    Aber ein Super GamePlay :)

  • Kleiner Bug noch. Das Spiel endet nicht wenn es unentschieden ausgeht.

    Andy hat mir ein Schnitzel gebacken aber da war ein Raupi drauf und bevor Oscar das Bugfixen konnte kam Alina und gab mir ein AspirinJunkie.

  • Schöne Spielumsetzung, gefällt mir. Allerdings denke ich, dass du dringend einen Algorythmus brauchst, der dir die Felder nach Übereinstimmungen absucht - so ist das ein sehr (evtl unnötig?) großes unübersichtliches Script. Ich denke ein Rekursiver Ansatz könnte evtl. helfen.