So, jetzt haben wir einen LevelEditor und am Programm habe ich auch noch ein paar Ergänzungen vorgenommen!
Komischerweise springt bei mir der Cursor in verkehrter Reihenfolge wenn ich Tab drücke!? ![]()
Der Speichern-Button wird erst aktiviert wenn mindestens 22 Ziffern eingetragen sind! Gibt's auch sinnvolle Rätsel mit weniger Ziffern?
Spoiler anzeigen
#include <GUIConstants.au3>
[/autoit] [autoit][/autoit] [autoit]Opt("GUIOnEventMode", 1)
[/autoit] [autoit][/autoit] [autoit]Const $ciTop = 40
Const $ciLeft = 20
Const $cstrIniFile = @ScriptDir & "\Sudoku.ini"
Dim $arSudokuFeld[9][9] ; Speichert die ControlID's der Inputfelder
Dim $arLevels ; Array für die Spielstufen
Dim $arGames ; Array für die Spiele in den Spielstufen
Global $bLevelsChanged ; Ist True wenn sich an den Levels was geändert hat
Global $bSheetSaveOK ; Ist True wenn das Blatt mit mehr als 21 Ziffern gefüllt ist
Global $bSheetChanged ; Ist True wenn das Blatt verändert wurde
Global $iGameIndex ; Speichert die aktuelle Spielnummer
$FrmMain = GUICreate("Sudoku - Level Editor", 633, 454, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "FormMainClose")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "FormMainMinimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "FormMainMaximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "FormMainRestore")
$PicLeft = GUICtrlCreatePic(@ScriptDir & "\Images\Black.jpg", $ciLeft, $ciTop + 5, 5, 334, BitOR($SS_NOTIFY, $WS_GROUP))
$PicInnerLeft = GUICtrlCreatePic(@ScriptDir & "\Images\Black.jpg", $ciLeft + 113, $ciTop + 5, 5, 334, BitOR($SS_NOTIFY, $WS_GROUP))
$PicInnerRight = GUICtrlCreatePic(@ScriptDir & "\Images\Black.jpg", $ciLeft + 226, $ciTop + 5, 5, 334, BitOR($SS_NOTIFY, $WS_GROUP))
$PicRight = GUICtrlCreatePic(@ScriptDir & "\Images\Black.jpg", $ciLeft + 339, $ciTop + 5, 5, 334, BitOR($SS_NOTIFY, $WS_GROUP))
$PicTop = GUICtrlCreatePic(@ScriptDir & "\Images\Black.jpg", $ciLeft, $ciTop, 344, 5, BitOR($SS_NOTIFY, $WS_GROUP))
$PicInnerTop = GUICtrlCreatePic(@ScriptDir & "\Images\Black.jpg", $ciLeft + 5, $ciTop + 113, 334, 5, BitOR($SS_NOTIFY, $WS_GROUP))
$PicInnerBottom = GUICtrlCreatePic(@ScriptDir & "\Images\Black.jpg", $ciLeft + 5, $ciTop + 226, 334, 5, BitOR($SS_NOTIFY, $WS_GROUP))
$PicBottom = GUICtrlCreatePic(@ScriptDir & "\Images\Black.jpg", $ciLeft, $ciTop + 339, 344, 5, BitOR($SS_NOTIFY, $WS_GROUP))
For $iZeile = 0 To 8
$iTop = $ciTop + 8 + $iZeile * 35 + Int($iZeile / 3) * 8
For $iSpalte = 0 To 8
$iLeft = $ciLeft + 8 + $iSpalte * 35 + Int($iSpalte / 3) * 8
$arSudokuFeld[$iZeile][$iSpalte] = GUICtrlCreateInput("", $iLeft, $iTop, 32, 32, BitOR($ES_CENTER, $ES_NUMBER))
GUICtrlSetOnEvent(-1, "FieldChange")
GUICtrlSetLimit(-1, 1)
GUICtrlSetFont(-1, 16, 400, 0, "Arial")
Next
Next
$LblLevels = GUICtrlCreateLabel("Level:", $ciLeft + 360, $ciTop + 5, 50)
GUICtrlSetFont(-1, 12, 600, 0, "Arial")
$CBLevels = GUICtrlCreateCombo("", $ciLeft + 420, $ciTop + 5, 120, 100, $CBS_DROPDOWNLIST)
GUICtrlSetOnEvent(-1, "LevelChange")
$LblGames = GUICtrlCreateLabel("Spiel:", $ciLeft + 360, $ciTop + 30, 50)
GUICtrlSetFont(-1, 12, 600, 0, "Arial")
$CBGames = GUICtrlCreateCombo("", $ciLeft + 420, $ciTop + 30, 120, 100, $CBS_DROPDOWNLIST)
GUICtrlSetOnEvent(-1, "GameChange")
$ButChangeLevel = GUICtrlCreateButton("Levelbez. ä&ndern", $ciLeft + 360, $ciTop + 130, 190)
GUICtrlSetFont(-1, 12, 600, 0, "Arial")
GUICtrlSetOnEvent(-1, "ButChangeLevelClick")
$ButNewLevel = GUICtrlCreateButton("Neuer &Level", $ciLeft + 360, $ciTop + 160, 190)
GUICtrlSetFont(-1, 12, 600, 0, "Arial")
GUICtrlSetOnEvent(-1, "ButNewLevelClick")
$ButNewSheet = GUICtrlCreateButton("Neues &Blatt", $ciLeft + 360, $ciTop + 210, 190)
GUICtrlSetFont(-1, 12, 600, 0, "Arial")
GUICtrlSetOnEvent(-1, "ButNewSheetClick")
$ButSave = GUICtrlCreateButton("Blatt &speichern", $ciLeft + 360, $ciTop + 240, 190)
GUICtrlSetFont(-1, 12, 600, 0, "Arial")
GUICtrlSetOnEvent(-1, "ButSaveClick")
GUICtrlSetState(-1, $GUI_DISABLE)
$ButUndo = GUICtrlCreateButton("Änderungen &verwerfen", $ciLeft + 360, $ciTop + 270, 190)
GUICtrlSetFont(-1, 12, 600, 0, "Arial")
GUICtrlSetOnEvent(-1, "ButSaveClick")
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
[/autoit] [autoit][/autoit] [autoit]#region -- Initialisierung
$arLevels = IniReadSection($cstrIniFile, "Levels")
If @error Then
Dim $arLevels[2][2]
Dim $arGames[2][2]
$arLevels[0][0] = 1
$arLevels[1][0] = "Stufe1"
$arLevels[1][1] = "Level 1"
GUICtrlSetData($CBLevels, "Level 1", "Level 1")
$arGames[0][0] = 1
$arGames[1][0] = "001"
$arGames[1][1] = StringFormat("%081s", "0")
GUICtrlSetData($CBGames, "001", "001")
IniWriteSection($cstrIniFile,"Levels",$arLevels)
IniWriteSection($cstrIniFile,"Stufe1",$arGames)
GameChange()
$bLevelsChanged = True
$bSheetChanged = True
$bSheetSaveOK = False
Else
$strLevels = ""
For $iIndex = 1 To $arLevels[0][0]
$strLevels &= $arLevels[$iIndex][1] & "|"
Next
$strLevels = StringTrimRight($strLevels, 1)
GUICtrlSetData($CBLevels, $strLevels, StringLeft($strLevels, StringInStr($strLevels, "|") - 1))
LevelChange()
FieldChange()
$bSheetChanged = False
EndIf
#endregion
While 1
If Not $bSheetChanged Then
If BitAND(GUICtrlGetState($CBLevels), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($CBLevels, $GUI_ENABLE)
If BitAND(GUICtrlGetState($CBGames), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($CBGames, $GUI_ENABLE)
If BitAND(GUICtrlGetState($ButNewLevel), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($ButNewLevel, $GUI_ENABLE)
If BitAND(GUICtrlGetState($ButNewSheet), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($ButNewSheet, $GUI_ENABLE)
Else
If BitAND(GUICtrlGetState($CBLevels), $GUI_ENABLE) = $GUI_ENABLE Then GUICtrlSetState($CBLevels, $GUI_DISABLE)
If BitAND(GUICtrlGetState($CBGames), $GUI_ENABLE) = $GUI_ENABLE Then GUICtrlSetState($CBGames, $GUI_DISABLE)
If BitAND(GUICtrlGetState($ButNewLevel), $GUI_ENABLE) = $GUI_ENABLE Then GUICtrlSetState($ButNewLevel, $GUI_DISABLE)
If BitAND(GUICtrlGetState($ButNewSheet), $GUI_ENABLE) = $GUI_ENABLE Then GUICtrlSetState($ButNewSheet, $GUI_DISABLE)
EndIf
If $bSheetChanged And $bSheetSaveOK Then
If BitAND(GUICtrlGetState($ButSave), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($ButSave, $GUI_ENABLE)
Else
If BitAND(GUICtrlGetState($ButSave), $GUI_ENABLE) = $GUI_ENABLE Then GUICtrlSetState($ButSave, $GUI_DISABLE)
EndIf
Sleep(100)
WEnd
Func FormMainClose()
Exit
EndFunc ;==>FormMainClose
Func FormMainMaximize()
EndFunc ;==>FormMainMaximize
Func FormMainMinimize()
EndFunc ;==>FormMainMinimize
Func FormMainRestore()
EndFunc ;==>FormMainRestore
[/autoit] [autoit][/autoit] [autoit]; FieldChange -> eines der Inputfelder wurde geändert
Func FieldChange()
$iCounter = 0
$arGames[$iGameIndex][1] = ""
For $iZeile = 0 To 8
For $iSpalte = 0 To 8
$iWert = Int(GUICtrlRead($arSudokuFeld[$iZeile][$iSpalte]))
If $iWert > 0 Then
$iCounter += 1
$arGames[$iGameIndex][1] &= String($iWert)
Else
$arGames[$iGameIndex][1] &= "0"
EndIf
Next
Next
$bSheetSaveOK = False
If $iCounter > 21 Then $bSheetSaveOK = True
$bSheetChanged = True
EndFunc ;==>FieldChange
; LevelChange -> Schwierigkeitsstufe wurde geändert
Func LevelChange()
$strLevel = GUICtrlRead($CBLevels)
For $iIndex = 1 To $arLevels[0][0]
If $arLevels[$iIndex][1] == $strLevel Then ExitLoop
Next
$arGames = IniReadSection($cstrIniFile, $arLevels[$iIndex][0])
If @error Then
MsgBox(4096, "", "Fehler beim lesen der Ini-Datei!")
Exit
EndIf
Switch $arGames[0][0]
Case 0
MsgBox(4096, "", "Für diesen Level existieren keine Spiele")
Return
Case 1
GUICtrlSetData($CBGames, "|" & $arGames[1][0], $arGames[1][0])
Case Else
$strGames = ""
For $iIndex = 1 To $arGames[0][0]
$strGames &= $arGames[$iIndex][0] & "|"
Next
$strGames = StringTrimRight($strGames, 1)
GUICtrlSetData($CBGames, "|" & $strGames, StringLeft($strGames, StringInStr($strGames, "|") - 1))
EndSwitch
GameChange()
EndFunc ;==>LevelChange
; GameChange -> Neues Spiel wurde gewählt
Func GameChange()
$strGame = GUICtrlRead($CBGames)
For $iIndex = 1 To $arGames[0][0]
If $arGames[$iIndex][0] == $strGame Then ExitLoop
Next
For $iZeile = 0 To 8
For $iSpalte = 0 To 8
$iWert = StringMid($arGames[$iIndex][1], $iZeile * 9 + $iSpalte + 1, 1)
If $iWert <> 0 Then
GUICtrlSetData($arSudokuFeld[$iZeile][$iSpalte], $iWert)
GUICtrlSetStyle($arSudokuFeld[$iZeile][$iSpalte], BitOR($ES_CENTER, $ES_NUMBER))
Else
GUICtrlSetData($arSudokuFeld[$iZeile][$iSpalte], "")
GUICtrlSetStyle($arSudokuFeld[$iZeile][$iSpalte], BitOR($ES_CENTER, $ES_NUMBER))
EndIf
Next
Next
$iGameIndex = $iIndex
EndFunc ;==>GameChange
; Button "Levelbez. ändern" wurde betätigt
Func ButChangeLevelClick()
$StrOldName = GUICtrlRead($CBLevels)
For $iIndex = 1 To $arLevels[0][0]
If $arLevels[$iIndex][1] == $StrOldName Then ExitLoop
Next
$strNewName = InputBox("Levelbezeichnung ändern", "Bitte neue Levelbezeichnung eingeben!" & @CRLF & @CRLF & _
"Die derzeitige Bezeichnung ist: " & $StrOldName)
If $strNewName <> $StrOldName And StringLen($strNewName) Then
$arLevels[$iIndex][1] = $strNewName
$bLevelsChanged = True
$strLevels = ""
For $iIndex = 1 To $arLevels[0][0]
$strLevels &= $arLevels[$iIndex][1] & "|"
Next
$strLevels = StringTrimRight($strLevels, 1)
GUICtrlSetData($CBLevels, $strLevels, $strNewName)
EndIf
EndFunc ;==>ButChangeLevelClick
; Button "Neuer Level" wurde betätigt
Func ButNewLevelClick()
$strNewName = InputBox("Level hinzufügen", "Bitte Bezeichnung für den neuen Level eingeben!")
If StringLen($strNewName) Then
ReDim $arLevels[$arLevels[0][0] + 2][2]
$arLevels[0][0] += 1
$strLevels = ""
For $iIndex = 1 To $arLevels[0][0] - 1
$strLevels &= $arLevels[$iIndex][1] & "|"
If Int(StringMid($arLevels[$iIndex][0],6)) >= Int($arLevels[$arLevels[0][0]][0]) Then
$arLevels[$arLevels[0][0]][0] = Int(StringMid($arLevels[$iIndex][0],6)) + 1
EndIf
Next
$arLevels[$arLevels[0][0]][0] = "Stufe" & $arLevels[$arLevels[0][0]][0]
$arLevels[$arLevels[0][0]][1] = $strNewName
$strLevels &= $strNewName
GUICtrlSetData($CBLevels, $strLevels, $strNewName)
ReDim $arGames[2][2]
$arGames[0][0] = 1
$arGames[1][0] = "001"
$arGames[1][1] = StringFormat("%081s", "0")
GUICtrlSetData($CBGames, "001", "001")
GameChange()
$bLevelsChanged = True
$bSheetChanged = True
$bSheetSaveOK = False
EndIf
EndFunc ;==>ButNewLevelClick
; Button "Neues Blatt" wurde betätigt
Func ButNewSheetClick()
ReDim $arGames[$arGames[0][0] + 2][2]
$arGames[0][0] += 1
$arGames[$arGames[0][0]][1] = StringFormat("%081s", "0")
Switch $arGames[0][0]
Case 0
MsgBox(4096, "", "Für diesen Level existieren keine Spiele!")
Return
Case 1
GUICtrlSetData($CBGames, "|" & $arGames[1][0], $arGames[1][0])
Case Else
$strGames = ""
For $iIndex = 1 To $arGames[0][0] - 1
$strGames &= $arGames[$iIndex][0] & "|"
If Int($arGames[$iIndex][0]) >= Int($arGames[$arGames[0][0]][0]) Then
$arGames[$arGames[0][0]][0] = StringFormat("%03i", Int($arGames[$iIndex][0]) + 1)
EndIf
Next
$strGames &= $arGames[$arGames[0][0]][0]
GUICtrlSetData($CBGames, "|" & $strGames, $arGames[$arGames[0][0]][0])
EndSwitch
GameChange()
$bSheetSaveOK = False
EndFunc ;==>ButNewSheetClick
; Button "Blatt speichern" wurde betätigt
Func ButSaveClick()
If $bLevelsChanged Then
IniWriteSection($cstrIniFile, "Levels", $arLevels)
If @error Then
MsgBox(4096, "", "Fehler beim lesen der Ini-Datei!")
Exit
EndIf
$bLevelsChanged = False
EndIf
$strLevel = GUICtrlRead($CBLevels)
[/autoit] [autoit][/autoit] [autoit]For $iIndex = 1 To $arLevels[0][0]
If $arLevels[$iIndex][1] == $strLevel Then ExitLoop
Next
IniWriteSection($cstrIniFile, $arLevels[$iIndex][0], $arGames)
[/autoit] [autoit][/autoit] [autoit]If @error Then
MsgBox(4096, "", "Fehler beim lesen der Ini-Datei!")
Exit
EndIf
$bSheetChanged = False
$bSheetSaveOK = False
EndFunc ;==>ButSaveClick
Edit: Dateianhang entfernt -> veraltet