Jump to content
Sign in to follow this  
spudw2k

4-bit Puzzle

Recommended Posts

spudw2k

This is a script I am building to emulate this puzzle.

The script is incomplete but you can at least see some of the initial workings.

The next step is to work out the actual puzzles.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiSlider.au3>

Dim $arrSliders[4][2]
Dim $arrLabels[4][2]

$Form1 = GUICreate("", 422, 291)
$arrSliders[0][0] = GUICtrlCreateSlider(112, 104, 38, 149, BitOR($TBS_VERT,$TBS_BOTH,0x8000))
GUICtrlSetData(-1,100)
$arrSliders[1][0] = GUICtrlCreateSlider(186, 105, 38, 149, BitOR($TBS_VERT,$TBS_BOTH))
GUICtrlSetData(-1,100)
$arrSliders[2][0] = GUICtrlCreateSlider(264, 105, 38, 149, BitOR($TBS_VERT,$TBS_BOTH))
GUICtrlSetData(-1,100)
$arrSliders[3][0] = GUICtrlCreateSlider(343, 105, 38, 149, BitOR($TBS_VERT,$TBS_BOTH))
GUICtrlSetData(-1,100)
$LevelSelect = GUICtrlCreateInput("0", 36, 230, 41, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_READONLY))
$UpDown = GUICtrlCreateUpdown($LevelSelect)
GUICtrlSetLimit(-1,10,0)
$Reset = GUICtrlCreateButton("Reset", 24, 160, 67, 41)
$arrLabels[0][0] = GUICtrlCreateLabel("0", 128, 252, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$arrLabels[1][0] = GUICtrlCreateLabel("0", 202, 252, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$arrLabels[2][0] = GUICtrlCreateLabel("0", 280, 252, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$arrLabels[3][0] = GUICtrlCreateLabel("0", 359, 252, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$arrLabels[0][1] = GUICtrlCreateLabel("1", 128, 86, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$arrLabels[1][1] = GUICtrlCreateLabel("1", 202, 86, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$arrLabels[2][1] = GUICtrlCreateLabel("1", 280, 86, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$arrLabels[3][1] = GUICtrlCreateLabel("1", 359, 86, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$lblTitle = GUICtrlCreateLabel("4-bit Puzzle", 144, 16, 140, 33)
GUICtrlSetFont(-1, 18, 800, 4, "MS Sans Serif")
GUIRegisterMsg($WM_VSCROLL, "WM_Slider")
GUICtrlSetState($lblTitle,$GUI_FOCUS)
_EvalSliders()
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYUP
            _EvalSliders()
        Case $Reset
            _Reset()
        Case $UpDown
            _Reset()
    EndSwitch
    For $x = 0 to 3
        For $y = 0 to 1
            if $nMsg = $arrLabels[$x][$y] Then
                $pos = _GUICtrlSlider_GetPos($arrSliders[$x][0])
                If $pos = 100 Then
                    _SlideUp($arrSliders[$x][0])
                Else
                _SlideDown($arrSliders[$x][0])
                EndIf
            EndIf
        Next
    Next
WEnd

Func _Reset()
    GUICtrlSetState($Reset,$GUI_DISABLE)
    GUICtrlSetState($lblTitle,$GUI_FOCUS)
    _SlideUp($arrSliders)
    _SlideDown($arrSliders)
    GUICtrlSetState($Reset,$GUI_ENABLE)
EndFunc

Func _EvalSliders()
    For $x = 0 to 3
        $arrSliders[$x][1] = _GUICtrlSlider_GetPos($arrSliders[$x][0])
        $pos = $arrSliders[$x][1]
        If $pos > 0 AND $pos < 100 Then
            If $pos > 50 Then
                _SlideDown($arrSliders[$x][0])
            Else
                _SlideUp($arrSliders[$x][0])
            EndIf
        EndIf
        $arrSliders[$x][1] = _GUICtrlSlider_GetPos($arrSliders[$x][0])
    Next
EndFunc

Func _SlideUp($hwnd)
    If IsArray($hwnd) Then
        For $x = 0 to UBound($hwnd)-1
            $hwnd[$x][1] = 100-_GUICtrlSlider_GetPos($hwnd[$x][0])
        Next
        For $pos = 24 to 90
            For $x = 0 to UBound($hwnd)-1
                _GUICtrlSlider_SetPos($hwnd[$x][0],(100-_QuinticEaseInOut($pos, $hwnd[$x][1], 101, 100)))
                If _GUICtrlSlider_GetPos($hwnd[$x][0]) <= 2 Then
                    _GUICtrlSlider_SetPos($hwnd[$x][0],0)
                EndIf
            Next
            $timer = TimerInit()
            While TimerDiff($timer) < 8
            Wend
            $timer = 0
        Next
    Else
        $start = 100-_GUICtrlSlider_GetPos($hwnd)
        For $pos = 24 to 90
            _GUICtrlSlider_SetPos($hwnd,(100-_QuinticEaseInOut($pos, $start, 101, 100)))
            If _GUICtrlSlider_GetPos($hwnd) <= 2 Then
                _GUICtrlSlider_SetPos($hwnd,0)
                $pos = 100
            EndIf
            $timer = TimerInit()
            While TimerDiff($timer) < 8
            Wend
            $timer = 0
        Next
    EndIf
EndFunc

Func _SlideDown($hwnd)
    If IsArray($hwnd) Then
        For $x = 0 to UBound($hwnd)-1
            $hwnd[$x][1] = _GUICtrlSlider_GetPos($hwnd[$x][0])
        Next
        For $pos = 24 to 90
            For $x = 0 to UBound($hwnd)-1
                _GUICtrlSlider_SetPos($hwnd[$x][0],(_QuinticEaseInOut($pos, $hwnd[$x][1], 101, 100)))
                If _GUICtrlSlider_GetPos($hwnd[$x][0]) >= 98 Then
                    _GUICtrlSlider_SetPos($hwnd[$x][0],100)
                EndIf
            Next
            $timer = TimerInit()
            While TimerDiff($timer) < 8
            Wend
            $timer = 0
        Next
    Else
        $start = _GUICtrlSlider_GetPos($hwnd)
        For $pos = 24 to 90
            _GUICtrlSlider_SetPos($hwnd,(_QuinticEaseInOut($pos, $start, 101, 100)))
            If _GUICtrlSlider_GetPos($hwnd) >= 98 Then
                $pos = 100
                _GUICtrlSlider_SetPos($hwnd,100)
            EndIf
            $timer = TimerInit()
            While TimerDiff($timer) < 8
            Wend
            $timer = 0
        Next
    EndIf
EndFunc

Func WM_Slider($hWnd, $iMsg, $wParam, $lParam)
    ;ConsoleWrite($wParam & ":" & $lParam & ":" & _GUICtrlSlider_GetPos($lParam) & @CRLF)
    Switch $lParam
        Case GUICtrlGetHandle($arrSliders[0][0])
            $pos = _GUICtrlSlider_GetPos($arrSliders[0][0])
            If $pos  Then
                If Not $arrSliders[1][1] Then _GUICtrlSlider_SetPos($arrSliders[1][0],101-$pos)
                If Not $arrSliders[3][1] Then _GUICtrlSlider_SetPos($arrSliders[3][0],101-$pos)
            EndIf
        Case GUICtrlGetHandle($arrSliders[1][0])
            $pos = _GUICtrlSlider_GetPos($arrSliders[1][0])
            If $pos  Then
                If Not $arrSliders[2][1] Then _GUICtrlSlider_SetPos($arrSliders[2][0],101-$pos)
                If Not $arrSliders[0][1] Then _GUICtrlSlider_SetPos($arrSliders[0][0],101-$pos)
            EndIf
        Case GUICtrlGetHandle($arrSliders[2][0])
            $pos = _GUICtrlSlider_GetPos($arrSliders[2][0])
            If $pos  Then
                If Not $arrSliders[1][1] Then _GUICtrlSlider_SetPos($arrSliders[1][0],101-$pos)
                If Not $arrSliders[0][1] Then _GUICtrlSlider_SetPos($arrSliders[0][0],101-$pos)
            EndIf
        Case GUICtrlGetHandle($arrSliders[3][0])
            $pos = _GUICtrlSlider_GetPos($arrSliders[3][0])
            If $pos  Then
                If Not $arrSliders[2][1] Then _GUICtrlSlider_SetPos($arrSliders[2][0],101-$pos)
                If Not $arrSliders[1][1] Then _GUICtrlSlider_SetPos($arrSliders[1][0],101-$pos)
            EndIf
    EndSwitch
    ;Return $GUI_RUNDEFMSG
EndFunc

Func _QuinticEaseInOut($iFrame, $iStartValue, $iInterval, $iEndValue) ;Credit to Josh Rowe - http://autoitscript.com/forum/topic/102851-transitions-udf/
    $iFrame = $iFrame / ($iEndValue / 2)
    If $iFrame < 1 Then
        Return $iInterval / 2 * $iFrame * $iFrame * $iFrame * $iFrame * $iFrame + $iStartValue
    EndIf
    $iFrame = $iFrame - 2
    Return $iInterval / 2 * ($iFrame * $iFrame * $iFrame * $iFrame * $iFrame + 2) + $iStartValue
EndFunc ;==>_QuinticEaseInOut

Edited by spudw2k
  • Like 1

Share this post


Link to post
Share on other sites
Wilenty

Hello,

it can help you finish up ;)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiSlider.au3>
Dim $arrSliders[4][2]
Dim $arrLabels[4][2]
$Form1 = GUICreate("", 422, 291)
$arrSliders[0][0] = GUICtrlCreateSlider(112, 104, 38, 149, BitOR($TBS_VERT,$TBS_BOTH,0x8000))
GUICtrlSetData(-1,100)
$arrSliders[1][0] = GUICtrlCreateSlider(186, 105, 38, 149, BitOR($TBS_VERT,$TBS_BOTH))
GUICtrlSetData(-1,100)
$arrSliders[2][0] = GUICtrlCreateSlider(264, 105, 38, 149, BitOR($TBS_VERT,$TBS_BOTH))
GUICtrlSetData(-1,100)
$arrSliders[3][0] = GUICtrlCreateSlider(343, 105, 38, 149, BitOR($TBS_VERT,$TBS_BOTH))
GUICtrlSetData(-1,100)
$LevelSelect = GUICtrlCreateInput("0", 36, 230, 41, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_READONLY))
$UpDown = GUICtrlCreateUpdown($LevelSelect)
GUICtrlSetLimit(-1,10,0)
$Reset = GUICtrlCreateButton("Reset", 24, 160, 67, 41)
$arrLabels[0][0] = GUICtrlCreateLabel("0", 128, 252, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$arrLabels[1][0] = GUICtrlCreateLabel("0", 202, 252, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$arrLabels[2][0] = GUICtrlCreateLabel("0", 280, 252, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$arrLabels[3][0] = GUICtrlCreateLabel("0", 359, 252, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$arrLabels[0][1] = GUICtrlCreateLabel("1", 128, 86, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$arrLabels[1][1] = GUICtrlCreateLabel("1", 202, 86, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$arrLabels[2][1] = GUICtrlCreateLabel("1", 280, 86, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$arrLabels[3][1] = GUICtrlCreateLabel("1", 359, 86, 10, 17)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$lblTitle = GUICtrlCreateLabel("4-bit Puzzle", 144, 16, 140, 33)
GUICtrlSetFont(-1, 18, 800, 4, "MS Sans Serif")
GUIRegisterMsg($WM_VSCROLL, "WM_Slider")
GUICtrlSetState($lblTitle,$GUI_FOCUS)
GUISetState(@SW_SHOW)
_EvalSliders()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Reset
            _Reset()
        Case $UpDown
            _Reset()
        Case $arrLabels[0][0]
   ArrLabels(0, 0)
        Case $arrLabels[1][0]
   ArrLabels(1, 0)
        Case $arrLabels[2][0]
   ArrLabels(2, 0)
        Case $arrLabels[3][0]
   ArrLabels(3, 0)
        Case $arrLabels[0][1]
   ArrLabels(0, 1)
        Case $arrLabels[1][1]
   ArrLabels(1, 1)
        Case $arrLabels[2][1]
   ArrLabels(2, 1)
        Case $arrLabels[3][1]
   ArrLabels(3, 1)
        Case $GUI_EVENT_PRIMARYUP
            _EvalSliders()
    EndSwitch
WEnd
Func ArrLabels($x, $y)
If $y = 1 Then
  If $arrSliders[$x][1]=100 Then
   $arrSliders[$x][1]=_SlideUp($arrSliders[$x][0])
   WM_Slider($Form1, 0x000, 0xfff,GUICtrlGetHandle($arrSliders[$x][0]))
  EndIf
Else
  If $arrSliders[$x][1]=0 Then $arrSliders[$x][1]=_SlideDown($arrSliders[$x][0])
EndIf
EndFunc
Func _Reset()
    GUICtrlSetState($Reset,$GUI_DISABLE)
    GUICtrlSetState($lblTitle,$GUI_FOCUS)
    _SlideUp($arrSliders)
    _SlideDown($arrSliders)
    GUICtrlSetState($Reset,$GUI_ENABLE)
EndFunc
Func _EvalSliders()
    For $x = 0 to 3
        $arrSliders[$x][1] = _GUICtrlSlider_GetPos($arrSliders[$x][0])
        $pos = $arrSliders[$x][1]
        If $pos > 0 AND $pos < 100 Then
            If $pos > 50 Then
                $arrSliders[$x][1]=_SlideDown($arrSliders[$x][0])
            Else
                $arrSliders[$x][1]=_SlideUp($arrSliders[$x][0])
            EndIf
        EndIf
    Next
EndFunc
Func _SlideUp($hwnd)
    If IsArray($hwnd) Then
        For $x = 0 to UBound($hwnd)-1
            $hwnd[$x][1] = 100-_GUICtrlSlider_GetPos($hwnd[$x][0])
        Next
        For $pos = 25 to 100
            For $x = 0 to UBound($hwnd)-1
                _GUICtrlSlider_SetPos($hwnd[$x][0],(100-_QuinticEaseInOut($pos, $hwnd[$x][1], 100, 100)))
                If _GUICtrlSlider_GetPos($hwnd[$x][0]) <= 2 Then
                    _GUICtrlSlider_SetPos($hwnd[$x][0],0)
     ContinueLoop
                EndIf
            Next
   Sleep(10)
        Next
    Else
        $start = 100-_GUICtrlSlider_GetPos($hwnd)
        For $pos = 25 to 100
            _GUICtrlSlider_SetPos($hwnd,(100-_QuinticEaseInOut($pos, $start, 100, 100)))
            If _GUICtrlSlider_GetPos($hwnd) <= 2 Then
                _GUICtrlSlider_SetPos($hwnd,0)
    Return 0
            EndIf
   Sleep(10)
        Next
    EndIf
EndFunc
Func _SlideDown($hwnd)
    If IsArray($hwnd) Then
        For $x = 0 to UBound($hwnd)-1
            $hwnd[$x][1] = _GUICtrlSlider_GetPos($hwnd[$x][0])
        Next
        For $pos = 25 to 100
            For $x = 0 to UBound($hwnd)-1
                _GUICtrlSlider_SetPos($hwnd[$x][0],(_QuinticEaseInOut($pos, $hwnd[$x][1], 100, 100)))
                If _GUICtrlSlider_GetPos($hwnd[$x][0]) >= 98 Then
                    _GUICtrlSlider_SetPos($hwnd[$x][0],100)
     ContinueLoop
                EndIf
            Next
   Sleep(10)
        Next
    Else
        $start = _GUICtrlSlider_GetPos($hwnd)
        For $pos = 25 to 100
            _GUICtrlSlider_SetPos($hwnd,(_QuinticEaseInOut($pos, $start, 100, 100)))
            If _GUICtrlSlider_GetPos($hwnd) >= 98 Then
                _GUICtrlSlider_SetPos($hwnd,100)
    Return 100
            EndIf
   Sleep(10)
        Next
    EndIf
EndFunc
Func WM_Slider($hWnd, $iMsg, $wParam, $lParam)
    ;ConsoleWrite($wParam & ":" & $lParam & ":" & _GUICtrlSlider_GetPos($lParam) & @CRLF & @CRLF)
If $wParam=0xfff Then
  Local $wArray[3][2]
  $wArray[2][0]=0
EndIf
    Switch $lParam
  Case GUICtrlGetHandle($arrSliders[0][0])
   If $wParam=0xfff Then
    If Not $arrSliders[1][1] Then
     $wArray[$wArray[2][0]][0]=$arrSliders[1][0]
     $wArray[2][0]+=1
    EndIf
    If Not $arrSliders[3][1] Then
     $wArray[$wArray[2][0]][0]=$arrSliders[3][0]
     $wArray[2][0]+=1
    EndIf
   Else
    $pos = _GUICtrlSlider_GetPos($arrSliders[0][0])
    If Not $arrSliders[1][1] Then _GUICtrlSlider_SetPos($arrSliders[1][0],100-$pos)
    If Not $arrSliders[3][1] Then _GUICtrlSlider_SetPos($arrSliders[3][0],100-$pos)
   EndIf
        Case GUICtrlGetHandle($arrSliders[1][0])
   If $wParam=0xfff Then
    If Not $arrSliders[2][1] Then
     $wArray[$wArray[2][0]][0]=$arrSliders[2][0]
     $wArray[2][0]+=1
    EndIf
    If Not $arrSliders[0][1] Then
     $wArray[$wArray[2][0]][0]=$arrSliders[0][0]
     $wArray[2][0]+=1
    EndIf
   Else
    $pos = _GUICtrlSlider_GetPos($arrSliders[1][0])
                If Not $arrSliders[2][1] Then _GUICtrlSlider_SetPos($arrSliders[2][0],100-$pos)
                If Not $arrSliders[0][1] Then _GUICtrlSlider_SetPos($arrSliders[0][0],100-$pos)
            EndIf
        Case GUICtrlGetHandle($arrSliders[2][0])
   If $wParam=0xfff Then
    If Not $arrSliders[1][1] Then
     $wArray[$wArray[2][0]][0]=$arrSliders[1][0]
     $wArray[2][0]+=1
    EndIf
    If Not $arrSliders[0][1] Then
     $wArray[$wArray[2][0]][0]=$arrSliders[0][0]
     $wArray[2][0]+=1
    EndIf
   Else
    $pos = _GUICtrlSlider_GetPos($arrSliders[2][0])
                If Not $arrSliders[1][1] Then _GUICtrlSlider_SetPos($arrSliders[1][0],100-$pos)
                If Not $arrSliders[0][1] Then _GUICtrlSlider_SetPos($arrSliders[0][0],100-$pos)
            EndIf
        Case GUICtrlGetHandle($arrSliders[3][0])
   If $wParam=0xfff Then
    If Not $arrSliders[2][1] Then
     $wArray[$wArray[2][0]][0]=$arrSliders[2][0]
     $wArray[2][0]+=1
    EndIf
    If Not $arrSliders[1][1] Then
     $wArray[$wArray[2][0]][0]=$arrSliders[1][0]
     $wArray[2][0]+=1
    EndIf
   Else
    $pos = _GUICtrlSlider_GetPos($arrSliders[3][0])
                If Not $arrSliders[2][1] Then _GUICtrlSlider_SetPos($arrSliders[2][0],100-$pos)
                If Not $arrSliders[1][1] Then _GUICtrlSlider_SetPos($arrSliders[1][0],100-$pos)
            EndIf
    EndSwitch
If $wParam=0xfff Then
  If $wArray[2][0]>0 Then
   ReDim $wArray[$wArray[2][0]][2]
   _SlideDown($wArray)
  EndIf
EndIf
    Return $GUI_RUNDEFMSG
EndFunc
Func _QuinticEaseInOut($iFrame, $iStartValue, $iInterval, $iEndValue) ;Credit to Josh Rowe - http://autoitscript.com/forum/topic/102851-transitions-udf/
    $iFrame = $iFrame / ($iEndValue / 2)
    If $iFrame < 1 Then
        Return $iInterval / 2 * $iFrame * $iFrame * $iFrame * $iFrame * $iFrame + $iStartValue
    EndIf
    $iFrame = $iFrame - 2
    Return $iInterval / 2 * ($iFrame * $iFrame * $iFrame * $iFrame * $iFrame + 2) + $iStartValue
EndFunc ;==>_QuinticEaseInOut

greets wilenty. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×