Declare IsOK(RiegelNr.l) Declare Switch(Nr.l) N = 6 #WinWidth = 140 #WinWidth2 = 260 #WinHeight = 400 WinXPos = (GetSystemMetrics_(#SM_CXSCREEN) - #WinWidth2) / 2 WinYPos = (GetSystemMetrics_(#SM_CYSCREEN) - #WinHeight) / 2 #Left = 5 #Top = 5 NewList Ergebnis.l() OpenWindow(0, WinXPos, WinYPos, #WinWidth, #WinHeight, #PB_Window_Systemmenu | #PB_Window_Borderless, "Graf Rüdeger") If N < 4 : End : EndIf Dim Status.b(N - 1) Dim Status2.b(N - 1) For a.l = 0 To N - 1 Status(a) = 1 Next If CreateGadgetList(WindowID()) ButtonHeight = 24 Width = #WinWidth - (#Left * 2) ListHeight = #WinHeight - (ButtonHeight * 3) - (#Top * 5) Column1Width = 70 Column2Width = 56 ListIconGadget(0, #Left, #Top, Width, ListHeight, "Riegel", Column1Width, #PB_ListIcon_FullRowSelect) AddGadgetColumn(0, 1, "Status", Column2Width) ;ButtonGadget(2, #Left, (#Top * 2) + ListHeight, (Width - #Left) / 2, ButtonHeight, "Zufall") ButtonGadget(5, (#Left * 2) + ((Width - 5) / 2), (#Top * 2) + ListHeight, (Width - #Left) / 2, ButtonHeight, " << OK >>") StringGadget(6, #Left, (#Top * 2) + ListHeight, (Width - #Left) / 2, ButtonHeight, Str(N), #PB_String_Numeric) ButtonGadget(1, #Left, (#Top * 3) + ListHeight + ButtonHeight, Width, ButtonHeight, "System an", #PB_Button_Toggle) ButtonGadget(3, #Left, (#Top * 4) + ListHeight + (ButtonHeight * 2), (Width - #Left) / 2, ButtonHeight, "Alles Auf") ButtonGadget(4, (#Left * 2) + ((Width - 5) / 2), (#Top * 4) + ListHeight + (ButtonHeight * 2), (Width - #Left) / 2, ButtonHeight, "Alles Zu") EndIf For a.l = 0 To N - 1 AddGadgetItem(0, a + 1, "Riegel " + Str(a + 1)) If Status(a) = 1 SetGadgetItemText(0, a, "zu", 1) Else SetGadgetItemText(0, a, "auf", 1) EndIf Next Declare RiegelZu(Nr.l) Declare RiegelAuf(Nr.l) Procedure RiegelZu(Nr.l) If Status(Nr) = 0 Select Nr Case 0 Switch(0) Case 1 RiegelAuf(0) Switch(1) Case N - 1 For a.l = Nr - 1 To 0 Step -1 RiegelZu(a) Next Switch(Nr) Default RiegelAuf(Nr - 1) For a.l = Nr - 2 To 0 Step -1 RiegelZu(a) Next Switch(Nr) EndSelect EndIf EndProcedure Procedure RiegelAuf(Nr.l) If Status(Nr) = 1 Select Nr Case 0 Switch(0) Case 1 RiegelAuf(0) Switch(1) Case N - 1 For a.l = Nr - 1 To 0 Step -1 RiegelZu(a) Next Switch(Nr) Default RiegelAuf(Nr - 1) For a.l = Nr - 2 To 0 Step -1 RiegelZu(a) Next Switch(Nr) EndSelect EndIf EndProcedure Repeat EventID.l = WaitWindowEvent() Yes = 0 If EventID = #PB_EventGadget Select EventMenuID() Case 2 For a.l = 0 To N - 1 Status(a) = Random(1) Next Yes = 1 Case 11 FreeGadget(10) FreeGadget(11) ResizeWindow(#WinWidth, #WinHeight) For a.l = 1 To 6 DisableGadget(a, 0) Next ;"Alles auf" - A L G O R H Y T H M U S Case 3 For a.l = 0 To N - 1 Status2(a) = Status(a) Next ClearList(Ergebnis()) If Status(N - 1) = 1 For a.l = N - 2 To 0 Step -1 RiegelZu(a) Next EndIf For a.l = N - 1 To 0 Step -1 RiegelAuf(a) Next For a.l = 0 To N - 1 Status(a) = Status2(a) Next Gosub ShowErgebnis ;"Alles zu" - A L G O R H Y T H M U S Case 4 For a.l = 0 To N - 1 Status2(a) = Status(a) Next ClearList(Ergebnis()) For a.l = N - 1 To 0 Step -1 RiegelZu(a) Next For a.l = 0 To N - 1 Status(a) = Status2(a) Next Gosub ShowErgebnis Case 5 TmpL.l = Val(GetGadgetText(6)) If TmpL > 3 ClearGadgetItemList(0) N = TmpL Dim Status.b(N - 1) Dim Status2.b(N - 1) For a.l = 0 To N - 1 Status(a) = 1 Next For a.l = 0 To N - 1 AddGadgetItem(0, a + 1, "Riegel " + Str(a + 1)) If Status(a) = 1 SetGadgetItemText(0, a, "zu", 1) Else SetGadgetItemText(0, a, "auf", 1) EndIf Next EndIf EndSelect EndIf If Yes = 0 RiegelNr.l = GetGadgetState(0) Yes = IsOK(RiegelNr) EndIf If Yes Or (GetGadgetState(1) = 0 And GetGadgetState(0) > - 1) Status(RiegelNr) = 1 - Status(RiegelNr) For a.l = 0 To N - 1 If Status(a) = 1 SetGadgetItemText(0, a, "zu", 1) Else SetGadgetItemText(0, a, "auf", 1) EndIf Next For a.l = 0 To N - 1 If Status(a) = 0 : tmp.s = "auf" : Else : tmp.s = "zu" : EndIf ;If IsOK(a) = 0 : tmp = " - " + tmp + " - " : EndIf SetGadgetItemText(0, a, tmp, 1) Next EndIf SetGadgetState(0, -1) Until EventID = #WM_Close CloseWindow(0) End Procedure IsOK(RiegelNr.l) Shared Status Select RiegelNr Case -1: Yes = 0 Case 0: Yes = 1 Case 1: If Status(0) = 0 : Yes = 1 : EndIf Case N - 1 Yes = 1 For a.l = RiegelNr - 1 To 0 Step -1 If Status(a) = 0 : Yes = 0 : EndIf Next Default If Status(RiegelNr - 1) = 1 Yes = 0 Else Yes = 1 For a.l = RiegelNr - 2 To 0 Step -1 If Status(a) = 0 : Yes = 0 : EndIf Next a EndIf EndSelect ProcedureReturn Yes EndProcedure Procedure Switch(Nr.l) Shared Ergebnis Shared Status AddElement(Ergebnis()) Ergebnis() = Nr Status(Nr) = 1 - Status(Nr) EndProcedure ShowErgebnis: ResizeWindow(#WinWidth2, #WinHeight) Height = #WinHeight - ButtonHeight - (#Top * 3) Width = #WinWidth2 - #WinWidth - #Left ListViewGadget(10, #WinWidth, #Top, Width, Height) SetGadgetState(1, 1) For a.l = 1 To 6 DisableGadget(a, 1) Next ButtonGadget(11, #WinWidth, (#Top * 2) + Height, Width, ButtonHeight, "<<< Zurück <<<") ResetList(Ergebnis()) AddGadgetItem(10, -1, Str(CountList(Ergebnis())) + " Bewegungen:") AddGadgetItem(10, -1, "---------------------------") While NextElement(Ergebnis()) AddGadgetItem(10, -1, "Riegel " + Str(Ergebnis() + 1)) Wend Return ; ExecutableFormat=Windows ; EnableXP ; Executable=C:\Programme\PureBasic\Programme\InfoOlymp\Graf Rüdeger.exe ; DisableDebugger