Probleme bei ein Würfel Spiel

  • Hey,

    Ich bin relativ neu bei Autoit die grundlagen und ein bisschen kann ich schon doch ich habe ein problem bei ein schreiben von ein Spiel. Ich versuche das so hinzubekommen das 2 Spieler spielen, der erste würfelt und der punkt geht dann so weit, der 2 würfelt und geht dann soweit... usw. doch es scheitert schon bei der umsetztung ;( . Bisher habe ich nur den 1. Würfelzug so das die spieler bis max. 6 felder vorrücken doch wenn ich dann ein 2. mal würfel und die zahl kleiner ist gehen die figuren wieder zurück :huh: . Bitte um hilfe (Am ende des schwarzen balkens soll das ziel sein!)

    Spoiler anzeigen

    Global $Ysp1 = 72
    Global $Ysp2 = 104
    Global $X1 = 16
    Global $X2 = 24
    Global $X3 = 32
    Global $X4 = 40
    Global $X5 = 48
    Global $X6 = 56
    Global $X7 = 64
    Global $X8 = 72
    Global $X9 = 80
    Global $X10 = 88
    Global $X11 = 96
    Global $X12 = 104
    Global $X13 = 112
    Global $X14 = 120
    Global $X15 = 128
    Global $X16 = 136
    Global $X17 = 144
    Global $X18 = 152
    Global $X19 = 160
    Global $X20 = 168
    Global $X21 = 176
    Global $X22 = 184
    Global $X23 = 192
    Global $X24 = 200
    Global $X25 = 208
    Global $X26 = 216
    Global $X27 = 224
    Global $X28 = 232
    Global $X29 = 240
    Global $X30 = 248
    Global $X31 = 256
    Global $X32 = 264
    Global $X33 = 272


    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

    #Region
    $Form1 = GUICreate("Spiel", 315, 169, 354, 345)
    GUISetBkColor(0x00FF00)
    $Spieler1 = GUICtrlCreateLabel("", 8, 72, 20, 20)
    GUICtrlSetColor(-1, 0xFF0000)
    GUICtrlSetBkColor(-1, 0xFF0000)
    $Label1 = GUICtrlCreateLabel("Label1", 8, 48, 284, 9)
    GUICtrlSetBkColor(-1, 0x000000)
    $Spieler2 = GUICtrlCreateLabel("", 8, 104, 20, 20)
    GUICtrlSetBkColor(-1, 0x0000FF)
    $MyButton1 = GUICtrlCreateButton("Würfel für Sp. 1", 24, 8, 100, 30, $BS_FLAT)
    $MyButton2 = GUICtrlCreateButton("Würfel für Sp. 2", 152, 8, 100, 30, $BS_FLAT)
    GUISetState(@SW_SHOW)
    #EndRegion

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

    Case $MyButton1
    Switch Random (1,6,1)
    Case 1
    GUICtrlSetPos($Spieler1,$X1,$Ysp1)
    ToolTip ("Du hast 1 gewürfelt!",369,522)
    Sleep (500)
    Case 2
    GUICtrlSetPos($Spieler1,$X2,$Ysp1)
    ToolTip ("Du hast 2 gewürfelt!",369,522)
    Sleep (500)
    Case 3
    GUICtrlSetPos($Spieler1,$X3,$Ysp1)
    ToolTip ("Du hast 3 gewürfelt!",369,522)
    Sleep (500)
    Case 4
    GUICtrlSetPos($Spieler1,$X4,$Ysp1)
    ToolTip ("Du hast 4 gewürfelt!",369,522)
    Sleep (500)
    Case 5
    GUICtrlSetPos($Spieler1,$X5,$Ysp1)
    ToolTip ("Du hast 5 gewürfelt!",369,522)
    Sleep (500)
    Case 6
    GUICtrlSetPos($Spieler1,$X6,$Ysp1)
    ToolTip ("Du hast 6 gewürfelt!",369,522)
    Sleep (500)
    EndSwitch
    MsgBox (0,"Spieler Wechsel","Spieler 2 du bist dran!")

    Case $MyButton2
    Switch Random (1,6,1)
    Case 1
    GUICtrlSetPos($Spieler2,$X1,$Ysp2)
    ToolTip ("Du hast 1 gewürfelt!",369,522)
    Sleep (500)
    Case 2
    GUICtrlSetPos($Spieler2,$X2,$Ysp2)
    ToolTip ("Du hast 2 gewürfelt!",369,522)
    Sleep (500)
    Case 3
    GUICtrlSetPos($Spieler2,$X3,$Ysp2)
    ToolTip ("Du hast 3 gewürfelt!",369,522)
    Sleep (500)
    Case 4
    GUICtrlSetPos($Spieler2,$X4,$Ysp2)
    ToolTip ("Du hast 4 gewürfelt!",369,522)
    Sleep (500)
    Case 5
    GUICtrlSetPos($Spieler2,$X5,$Ysp2)
    ToolTip ("Du hast 5 gewürfelt!",369,522)
    Sleep (500)
    Case 6
    GUICtrlSetPos($Spieler2,$X6,$Ysp2)
    ToolTip ("Du hast 6 gewürfelt!",369,522)
    Sleep (500)
    EndSwitch

    MsgBox (0,"Spieler Wechsel","Spieler 1 du bist dran!")


    EndSwitch
    WEnd

    Hoffe um hilfe

    PS: wenns geht mit erklärung wie ihr auf die lösung gekommen seid

  • Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    $x1 = 8 ;Startposition Spieler 1
    $x2 = 8 ;Startposition Spieler 2

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

    #region
    $Form1 = GUICreate("Spiel", 315, 169, 354, 345)
    GUISetBkColor(0x00FF00)
    $Spieler1 = GUICtrlCreateLabel("", 8, 72, 20, 20)
    GUICtrlSetBkColor(-1, 0xFF0000)
    $Label1 = GUICtrlCreateLabel("Label1", $x1, 48, 284, 9)
    GUICtrlSetBkColor(-1, 0x000000)
    $Spieler2 = GUICtrlCreateLabel("", $x2, 104, 20, 20)
    GUICtrlSetBkColor(-1, 0x0000FF)
    $MyButton1 = GUICtrlCreateButton("Würfel für Sp. 1", 24, 8, 100, 30, $BS_FLAT)
    $MyButton2 = GUICtrlCreateButton("Würfel für Sp. 2", 152, 8, 100, 30, $BS_FLAT)
    GUICtrlSetState(-1, $GUI_DISABLE) ;Button disabled damit Spieler 2 nicht würfeln kann
    GUISetState(@SW_SHOW)
    #endregion

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $MyButton1
    $random = Random(1, 6, 1) ;würfeln
    $x1 += $random * 8 ;den gewürfelten Wert * 8 Pixel zur x-Position des Spielers addieren
    GUICtrlSetPos($Spieler1, $x1, 72) ;neue Position setzen
    ToolTip("Du hast eine " & $random & " gewürfelt!", 369, 522)
    Sleep(500)
    MsgBox(0, "Spieler Wechsel", "Spieler 2 du bist dran!")
    GUICtrlSetState($MyButton2, $GUI_ENABLE)
    GUICtrlSetState($MyButton1, $GUI_DISABLE)
    Case $MyButton2
    $random = Random(1, 6, 1)
    $x2 += $random * 8
    GUICtrlSetPos($Spieler2, $x2, 104)
    ToolTip("Du hast eine " & $random & " gewürfelt!", 369, 522)
    Sleep(500)
    MsgBox(0, "Spieler Wechsel", "Spieler 2 du bist dran!")
    GUICtrlSetState($MyButton1, $GUI_ENABLE)
    GUICtrlSetState($MyButton2, $GUI_DISABLE)
    EndSwitch
    WEnd

    [/autoit]
  • Wie kan ich das den machen, das wenn ich jetzt sagen will das er fertig ist? also in der zielliene? z.B. das eine msgbox kommt und sagt das sp. 1 im ziel ist? Und gibt es irgendein Befehl der erkennt wo das Label gerade ist? so das ich das Spiel z.B. auch um die ecke laufen alssen kann?

    Einmal editiert, zuletzt von Nico9132 (12. Oktober 2010 um 15:06) aus folgendem Grund: Eine frage Vergessen :P

  • Indem du $x1 und $x2 nach dem Setzen prüfst.

    Spoiler anzeigen
    [autoit]


    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    $x1 = 8 ;Startposition Spieler 1
    $x2 = 8 ;Startposition Spieler 2

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

    #region
    $Form1 = GUICreate("Spiel", 315, 169, 354, 345)
    GUISetBkColor(0x00FF00)
    $Spieler1 = GUICtrlCreateLabel("", 8, 72, 20, 20)
    GUICtrlSetBkColor(-1, 0xFF0000)
    $Label1 = GUICtrlCreateLabel("Label1", $x1, 48, 284, 9)
    GUICtrlSetBkColor(-1, 0x000000)
    $Spieler2 = GUICtrlCreateLabel("", $x2, 104, 20, 20)
    GUICtrlSetBkColor(-1, 0x0000FF)
    $MyButton1 = GUICtrlCreateButton("Würfel für Sp. 1", 24, 8, 100, 30, $BS_FLAT)
    $MyButton2 = GUICtrlCreateButton("Würfel für Sp. 2", 152, 8, 100, 30, $BS_FLAT)
    GUICtrlSetState(-1, $GUI_DISABLE) ;Button disabled damit Spieler 2 nicht würfeln kann
    GUISetState(@SW_SHOW)
    #endregion

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $MyButton1
    GUICtrlSetState($MyButton1, $GUI_DISABLE)
    $random = Random(1, 6, 1) ;würfeln
    $x1 += $random * 8 ;den gewürfelten Wert * 8 Pixel zur x-Position des Spielers addieren
    GUICtrlSetPos($Spieler1, $x1, 72) ;neue Position setzen
    ToolTip("Du hast eine " & $random & " gewürfelt!", 369, 522)
    Sleep(500)
    If $x1 >= 272 Then
    MsgBox(64, "Sieg!", "Spieler 1 hat das Spiel gewonnen.")
    Exit
    Else
    MsgBox(0, "Spieler Wechsel", "Spieler 2 du bist dran!")
    GUICtrlSetState($MyButton2, $GUI_ENABLE)
    EndIf
    Case $MyButton2
    GUICtrlSetState($MyButton2, $GUI_DISABLE)
    $random = Random(1, 6, 1)
    $x2 += $random * 8
    GUICtrlSetPos($Spieler2, $x2, 104)
    ToolTip("Du hast eine " & $random & " gewürfelt!", 369, 522)
    Sleep(500)
    If $x2 >= 272 Then
    MsgBox(64, "Sieg!", "Spieler 2 hat das Spiel gewonnen.")
    Exit
    Else
    MsgBox(0, "Spieler Wechsel", "Spieler 2 du bist dran!")
    GUICtrlSetState($MyButton1, $GUI_ENABLE)
    EndIf
    EndSwitch
    WEnd

    [/autoit]