Jump to content
Sign in to follow this  
smashly

Desktop Jumble game

Recommended Posts

smashly

Hi,

What is:

Desktop Jumble is a short point an click picture game.

It takes a screen capture of your desktop.

Scales the capture to approximate 3/4 the size of your desktop.

Cuts the scaled capture into 48 pieces (8x6 pieces)

Puts the 48 pieces in a jumbled order in a Gui for you to sort out.

Basic play:

Click "Start Jumble" button to start the game.

Click a jumble piece (selected piece has a red border)

Click a different jumble piece where you think the selected piece goes.

If the piece belongs then then it goes there with no border.

If the piece doesn't belong then your selected piece is deselcted.

Click the "Sneak Peak" button to view the unjumbled picture.

Click the "Show Jumble" button to return to the jumbled picture.

("Start Jumble", "Sneak Peak" and "Show Jumble" are all the same button)

Jumbled pieces:

Pieces that are in the correct place don't have a border.

Pieces that are not in the correct place have a black border.

Selected piece has a red border.

Once a piece is in the correct place it can no longer be selected or replaced.

Clicking on a piece that is in the correct place offers no penalty.

Stats

You can see your game stats while playing in the WinTitle.

Stats are:

Time: HH:MM:SS (Timer starts when "Start Jumble" button is pressed)

Missed: (Misses are when a selected piece is attempted to be put in the wrong place)

Sneak: (How many times you sneaked a peak at the unjumbled picture)

Game stats are also displayed in a MsgBox when you've unjumbled the picture.

After the MsgBox the Gui is reset with a new screen capture and "Start Jumble" button is there to do it all again..

Have fun.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <ScreenCapture.au3>
#include <Date.au3>

Opt("MustDeclareVars", 1)

Global $iGuiW, $iGuiH, $iPicW, $iPicH
Global $hGui, $iMsg, $aPic[49][4], $iX = 0, $iY = 0, $iPeek
Global $sGDIPState = False, $iLP, $iIDX, $iTmp1, $iTmp2, $iStart
Global $sTime = "00:00:00", $iMissed = 0, $iSneak = 0
Global $sStartTitle = "Desktop Jumble - Time: 00:00:00 - Missed: 0 - Sneak: 0"

_CalculateSize()

$hGui = GUICreate($sStartTitle, $iGuiW, $iGuiH)
For $i = 1 To UBound($aPic, 1) - 1
    $aPic[$i][0] = GUICtrlCreatePic("", $iX, $iY, $iPicW, $iPicH)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $aPic[$i][1] = $iX & "," & $iY
    If Not Mod($i, 8) Then
        $iX = 0
        $iY += $iPicH
    Else
        $iX += $iPicW
    EndIf
Next
$iPeek = GUICtrlCreateButton("Start Jumble", 5, $iGuiH - 35, $iGuiW - 10, 30)
_LoadImage($iGuiW, $iGuiH - 40, $iPicW, $iPicH, $aPic)
_LoadPieces($aPic)
GUISetState(@SW_SHOW, $hGui)

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            _Exit()
        Case $aPic[1][0] To $aPic[UBound($aPic, 1) - 1][0]
            $iIDX = _ClickToIndex($iMsg, $aPic)
            If Not $aPic[0][0] Then
                $aPic[0][0] = $iIDX
                _hImageToCtrl($aPic[$iIDX][0], $aPic[$aPic[$iIDX][3]][2], 1, 0xFFFF0000)
            ElseIf $aPic[0][0] <> 0 Then
                If $iIDX = $aPic[$aPic[0][0]][3] Then
                    $iTmp1 = $aPic[$aPic[0][0]][3]
                    $iTmp2 = $aPic[$iIDX][3]
                    $aPic[$aPic[0][0]][3] = $iTmp2
                    $aPic[$iIDX][3] = $iTmp1
                    $iLP = _LoadPieces($aPic, 1)
                    $aPic[0][0] = 0
                Else
                    $iMissed += 1
                    _hImageToCtrl($aPic[$aPic[0][0]][0], $aPic[$aPic[$aPic[0][0]][3]][2], 1)
                    $aPic[0][0] = 0
                EndIf
            EndIf
            If _CheckFinish() Then _Finish()
        Case $iPeek
            If GUICtrlRead($iPeek) = "Start Jumble" Then
                $iStart = TimerInit()
                AdlibRegister("_DisplayTimer", 250)
            EndIf
            If $iLP Then
                $aPic[0][0] = 0
                $iLP = _LoadPieces($aPic)
                $iSneak += 1
                GUICtrlSetData($iPeek, "Show Jumble")
            Else
                $iLP = _LoadPieces($aPic, 1)
                GUICtrlSetData($iPeek, "Sneak Peek")
            EndIf
    EndSwitch
WEnd

Func _CheckFinish()
    For $i = 1 To UBound($aPic, 1) - 1
        If $i <> $aPic[$i][3] Then Return 0
    Next
    Return 1
EndFunc   ;==>_CheckFinish

Func _ClickToIndex($iD, $aPic)
    For $i = 1 To UBound($aPic, 1) - 1
        If $aPic[$i][0] = $iD Then Return $i
    Next
EndFunc   ;==>_ClickToIndex

Func _LoadPieces($aPic, $iJumble = 0)
    For $i = 1 To UBound($aPic, 1) - 1
        If $iJumble Then
            If $aPic[$i][3] <> $i Then
                If BitAND(GUICtrlGetState($aPic[$i][0]), $GUI_DISABLE) Then GUICtrlSetState($aPic[$i][0], $GUI_ENABLE)
                _hImageToCtrl($aPic[$i][0], $aPic[$aPic[$i][3]][2], 1)
            Else
                If BitAND(GUICtrlGetState($aPic[$i][0]), $GUI_ENABLE) Then GUICtrlSetState($aPic[$i][0], $GUI_DISABLE)
                _hImageToCtrl($aPic[$i][0], $aPic[$aPic[$i][3]][2])
            EndIf
        Else
            If BitAND(GUICtrlGetState($aPic[$i][0]), $GUI_ENABLE) Then GUICtrlSetState($aPic[$i][0], $GUI_DISABLE)
            _hImageToCtrl($aPic[$i][0], $aPic[$i][2])
        EndIf
    Next
    Return $iJumble
EndFunc   ;==>_LoadPieces

Func _LoadImage($iW, $iH, $iPW, $iPH, ByRef $aPic)
    Local $hImage1, $hGraphics, $hBitmap, $hImage2, $aSS, $iRan, $sTmp1 = ",", $aTmp, $x = 1
    $aPic[0][0] = 0
    If $sGDIPState = False Then $sGDIPState = _GDIPlus_Startup()
    $hImage1 = _hImageCreate($iW, $iH)
    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage1)
    $hBitmap = _ScreenCapture_Capture()
    $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage2, 0, 0, $iW, $iH)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_ImageDispose($hImage2)
    For $i = 1 To UBound($aPic, 1) - 1
        If $aPic[$i][2] <> 0 Then _GDIPlus_ImageDispose($aPic[$i][2])
        $aPic[$i][2] = _hImageCreate($iPW, $iPH)
        $hGraphics = _GDIPlus_ImageGetGraphicsContext($aPic[$i][2])
        $aSS = StringSplit($aPic[$i][1], ",", 2)
        _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage1, $aSS[0], $aSS[1], $iPW, $iPH, 0, 0, $iPW, $iPH)
        _GDIPlus_GraphicsDispose($hGraphics)
    Next
    _GDIPlus_ImageDispose($hImage1)
    For $i = 1 To UBound($aPic, 1) - 1
        Do
            $iRan = Random(1, UBound($aPic, 1) - 1, 1)
        Until (Not StringInStr($sTmp1, "," & $iRan & ",")) And $iRan <> $i
        $sTmp1 &= $iRan & ","
        $aPic[$i][3] = $iRan
    Next
EndFunc   ;==>_LoadImage

Func _hImageToCtrl($cID, $hImage, $iBorder = 0, $iBorderClr = 0xFF000000, $iPenWidth = 2)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local $hBitmap, $hImage1 = $hImage, $hGraphics, $iW, $iH, $hPen = 0
    If $iBorder Then
        $iW = _GDIPlus_ImageGetWidth($hImage)
        $iH = _GDIPlus_ImageGetHeight($hImage)
        $hPen = _GDIPlus_PenCreate($iBorderClr, $iPenWidth)
        $hImage1 = _hImageCreate($iW, $iH)
        $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage1)
        _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iW, $iH)
        _GDIPlus_GraphicsDrawRect($hGraphics, $iPenWidth / 2, $iPenWidth / 2, $iW - $iPenWidth, $iH - $iPenWidth, $hPen)
        _GDIPlus_PenDispose($hPen)
    EndIf
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage1)
    If $iBorder Then
        _GDIPlus_ImageDispose($hImage1)
        _GDIPlus_GraphicsDispose($hGraphics)
    EndIf
    _WinAPI_DeleteObject(GUICtrlSendMsg($cID, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap))
    _WinAPI_DeleteObject($hBitmap)
EndFunc   ;==>_hImageToCtrl

Func _hImageCreate($iW, $iH)
    Local $hBmp, $hBitmap
    $hBmp = _WinAPI_CreateBitmap($iW, $iH, 1, 32)
    $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
    _WinAPI_DeleteObject($hBmp)
    Return $hBitmap
EndFunc   ;==>_hImageCreate

Func _CalculateSize()
    $iPicW = Round(3 * (@DesktopWidth / 4) / 8)
    $iPicH = Round(3 * (@DesktopHeight / 4) / 6)
    $iGuiW = $iPicW * 8
    $iGuiH = ($iPicH * 6) + 40
EndFunc   ;==>_CalculateSize

Func _DisplayTimer()
    Local $Hour, $Mins, $Secs, $OldTitle, $NewTitle
    $OldTitle = WinGetTitle($hGui)
    _TicksToTime(Int(TimerDiff($iStart)), $Hour, $Mins, $Secs)
    $sTime = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
    $NewTitle = "Desktop Jumble - Time: " & $sTime & " - Missed: " & $iMissed & " - Sneak: " & $iSneak
    If $OldTitle <> $NewTitle Then WinSetTitle($hGui, "", $NewTitle)
EndFunc   ;==>_DisplayTimer

Func _Finish()
    AdlibUnRegister("_DisplayTimer")
    MsgBox(64, "Desktop Jumble Success", "Finishing Stats" & @LF & @LF & _
            "Time Taken: " & @TAB & $sTime & @LF & _
            "Missed Clicks: " & @TAB & $iMissed & @LF & _
            "Sneak Peeks: " & @TAB & $iSneak, 0, $hGui)
    _LoadImage($iGuiW, $iGuiH - 40, $iPicW, $iPicH, $aPic)
    $iLP = _LoadPieces($aPic)
    GUICtrlSetData($iPeek, "Start Jumble")
    $iMissed = 0
    $iSneak = 0
    WinSetTitle($hGui, "", $sStartTitle)
EndFunc   ;==>_Finish

Func _Exit()
    For $i = 1 To UBound($aPic, 1) - 1
        _GDIPlus_ImageDispose($aPic[$i][2])
        $aPic[$i][2] = 0
    Next
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit
Note:

I've only tried this on my mum's old Pentium 4, Win XP, 1024x768 and 1280x1024 res.

It should scale on any desktop, but can't promise anything as my maths skill isn't that great.

Cheers

Edited by smashly

Share this post


Link to post
Share on other sites
TinyHacker

It's GREAT!! thank u pal Posted Image

Edited by TinyHacker

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  

×