Jump to content

[GAME] 4Images1Word


johnmcloud
 Share

Recommended Posts

I have just notice i don't have never post in this section if i remember well...bad. So in this Saturday i have think what i can post here, something that someone never already script, something different so...

4Images1Word

Based on the popular mobile game, just a "proof of concept" but working fine, 5 levels but can be added ( by you lol )

I'll release the source but if you want to use in a compiled project i want to know before any development. I have take the images from Google Images, if someone of that has some form of copyright i'll remove it.

Interface:

30cq1ro.png

Source:

;~ Johnmcloud - 2016
;~ #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

_GDIPlus_Startup()

Global $iLetter[16]
Global $iSolution[8]
Global $sGuessWord, $aWord, $iLevel = 1
Global $sPng1, $iPic1, $sPng2, $iPic2, $sPng3, $iPic3, $sPng4, $iPic4

_ChoiceLevel($iLevel, False)

Global $hGUI = GUICreate("4Images1Word", 455, 520, -1, -1)
For $i = 0 To 7
    $iLetter[$i] = GUICtrlCreateLabel($aWord[$i], 10 + ($i * 55), 408, 45, 45, BitOR($SS_CENTER, $SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 25, 400, 0, "Arial")
    GUICtrlSetBkColor(-1, 0xFFFFFF)
Next
For $i = 0 To 7
    $iLetter[$i + 8] = GUICtrlCreateLabel($aWord[$i + 8], 10 + ($i * 55), 465, 45, 45, BitOR($SS_CENTER, $SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 25, 400, 0, "Arial")
    GUICtrlSetBkColor(-1, 0xFFFFFF)
Next
For $i = 0 To StringLen($sGuessWord) - 1
    $iSolution[$i] = GUICtrlCreateLabel("", 10 + ($i * 55), 350, 45, 45, BitOR($SS_CENTER, $SS_CENTERIMAGE))
    GUICtrlSetFont(-1, 25, 400, 0, "Arial")
    GUICtrlSetBkColor(-1, 0x000000)
    GUICtrlSetColor(-1, 0xFFFFFF)
Next
$iPic1 = GUICtrlCreatePic("", 65, 10, 150, 150)
$iPic2 = GUICtrlCreatePic("", 225, 10, 150, 150)
$iPic3 = GUICtrlCreatePic("", 65, 180, 150, 150)
$iPic4 = GUICtrlCreatePic("", 225, 180, 150, 150)

GUISetState(@SW_SHOW)

_GUICtrlCreatePic_SetImage($iPic1, $sPng1)
_GUICtrlCreatePic_SetImage($iPic2, $sPng2)
_GUICtrlCreatePic_SetImage($iPic3, $sPng3)
_GUICtrlCreatePic_SetImage($iPic4, $sPng4)

Local $iMsg
While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            _SetReadLetter()
    EndSwitch
WEnd

Func _SetReadLetter()
    Local Static $sTempSolution
    For $i = 0 To UBound($iLetter) - 1
        If $iMsg <> "" And $iMsg = $iLetter[$i] Then
            For $y = 0 To UBound($iSolution) - 1
                If GUICtrlRead($iSolution[$y]) = "" Then
                    GUICtrlSetData($iSolution[$y], GUICtrlRead($iLetter[$i]))
                    GUICtrlSetData($iLetter[$i], "")
                    $sTempSolution &= GUICtrlRead($iSolution[$y])
                    ExitLoop
                EndIf
            Next
            If $sTempSolution = $sGuessWord Then
                MsgBox(64, "Congratulations!", "You have beat the Level " & $iLevel & "!", "", $hGUI)
                $sTempSolution = "" ; reset
                $iLevel += 1
                _ChoiceLevel($iLevel)
            EndIf
            ExitLoop
        EndIf
    Next
    For $x = 0 To UBound($iSolution) - 1
        If $iMsg <> "" And $iMsg = $iSolution[$x] Then
            For $z = 0 To UBound($iLetter) - 1
                If GUICtrlRead($iLetter[$z]) = "" Then
                    GUICtrlSetData($iLetter[$z], GUICtrlRead($iSolution[$x]))
                    GUICtrlSetData($iSolution[$x], "")
                    $sTempSolution = StringMid($sTempSolution, 1, ($x + 1) - 1) & StringMid($sTempSolution, ($x + 1) + 1)
                    ExitLoop
                EndIf
            Next
            ExitLoop
        EndIf
    Next
EndFunc   ;==>_SetReadLetter

Func _RandomizeShuffle($sString, $iNum = 16)
    Local $sText, $sTemp, $iLength = $iNum - StringLen($sString)
    For $i = 1 To $iLength
        $sTemp = Random(65, 90, 1)
        $sText &= Chr($sTemp + 6 * ($sTemp > 90))
    Next
    Local $aArray = StringSplit($sText & $sString, "", 2)
    Local $iNumber, $aTmp, $iUBound = UBound($aArray) - 1
    While $iUBound > 1
        $iNumber = Random(0, $iUBound - 1, 1)
        $aTmp = $aArray[$iUBound]
        $aArray[$iUBound] = $aArray[$iNumber]
        $aArray[$iNumber] = $aTmp
        $iUBound -= 1
    WEnd
    Return $aArray
EndFunc   ;==>_RandomizeShuffle

Func _GetURLImage($sURL, $sDirectory = @TempDir) ; author is guinness, nothing changed from original one
    Local $hDownload, $sFile
    $sFile = StringRegExpReplace($sURL, "^.*/", "")
    If @error Then
        Return SetError(1, 0, $sFile)
    EndIf
    If StringRight($sDirectory, 1) <> "" Then
        $sDirectory = $sDirectory & ""
    EndIf
    $sDirectory = $sDirectory & $sFile
    If FileExists($sDirectory) Then
        Return $sDirectory
    EndIf
    $hDownload = InetGet($sURL, $sDirectory, 17, 1)
    While InetGetInfo($hDownload, 2) = 0
        If InetGetInfo($hDownload, 4) <> 0 Then
            InetClose($hDownload)
            Return SetError(1, 0, $sDirectory)
        EndIf
        Sleep(100)
    WEnd
    InetClose($hDownload)
    Return $sDirectory
EndFunc   ;==>_GetURLImage

Func _GUICtrlCreatePic_SetImage($hWnd, $sImage) ; original author Yashied, i have changed it and merge in one function
    If Not IsHWnd($hWnd) Then
        $hWnd = GUICtrlGetHandle($hWnd)
        If $hWnd = 0 Then
            Return 0
        EndIf
    EndIf
    Local $Result, $hImage, $hBitmap, $hFit
    $hImage = _GDIPlus_BitmapCreateFromFile($sImage)
    Local $tRect = DllStructCreate($tagRECT)
    Local $Ret = DllCall('user32.dll', 'int', 'GetClientRect', 'hwnd', $hWnd, 'ptr', DllStructGetPtr($tRect))
    If (@error) Or ($Ret[0] = 0) Then Return 0
    Local $Size[2] = [DllStructGetData($tRect, 3) - DllStructGetData($tRect, 1), DllStructGetData($tRect, 4) - DllStructGetData($tRect, 2)]
    If ($Size[0] = 0) Or ($Size[1] = 0) Then Return 0
    If $Size = 0 Then Return SetError(1, 0, $hImage)

    Local $Width = _GDIPlus_ImageGetWidth($hImage), $Height = _GDIPlus_ImageGetHeight($hImage)
    If Not ($Width = -1) Or Not ($Height = -1) Then
        If ($Width <> $Size[0]) Or ($Height <> $Size[1]) Then
            $Ret = DllCall($ghGDIPDll, 'int', 'GdipGetImageThumbnail', 'ptr', $hImage, 'int', $Size[0], 'int', $Size[1], 'ptr*', 0, 'ptr', 0, 'ptr', 0)
            If (Not @error) And ($Ret[0] = 0) Then
                _GDIPlus_ImageDispose($hImage)
                $hImage = $Ret[4]
            EndIf
        EndIf
    EndIf
    $hFit = $hImage
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hFit)
    _GDIPlus_ImageDispose($hFit)

    Local $Style = _WinAPI_GetWindowLong($hWnd, 0xFFFFFFF0)
    If @error Then
        Return 0
    EndIf
    _WinAPI_SetWindowLong($hWnd, 0xFFFFFFF0, BitOR($Style, 0x0E))
    If @error Then
        Return 0
    EndIf
    Local $Pos = ControlGetPos($hWnd, '', '')
    If (@error) Or ($Pos[2] = 0) Or ($Pos[3] = 0) Then
        Return 0
    EndIf
    $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, 1, $Pos[0])
    DllStructSetData($tRect, 2, $Pos[1])
    DllStructSetData($tRect, 3, $Pos[0] + $Pos[2])
    DllStructSetData($tRect, 4, $Pos[1] + $Pos[3])
    Local $hPrev = _SendMessage($hWnd, 0x0172, 0, $hBitmap)
    If @error Then
        Return 0
    EndIf
    If $hPrev Then
        _WinAPI_DeleteObject($hPrev)
    EndIf
    If (Not $hBitmap) And (IsDllStruct($tRect)) Then
        _WinAPI_MoveWindow($hWnd, DllStructGetData($tRect, 1), DllStructGetData($tRect, 2), DllStructGetData($tRect, 3) - DllStructGetData($tRect, 1), DllStructGetData($tRect, 4) - DllStructGetData($tRect, 2), 0)
    EndIf
    If IsDllStruct($tRect) Then
        _WinAPI_InvalidateRect(_WinAPI_GetParent($hWnd), $tRect)
    EndIf

    $hImage = _SendMessage($hWnd, 0x0173, 0, 0)
    If (@error) Or ($hBitmap = $hImage) Then
        $hBitmap = 0
    EndIf

    If $hBitmap Then _WinAPI_DeleteObject($hBitmap)
    FileDelete($sImage)
    Return SetError(1 - $Result, 0, $Result)
EndFunc   ;==>_GUICtrlCreatePic_SetImage

Func _ChoiceLevel($Level, $sLoadImage = True)
    Select
        Case $Level = 1
            $sGuessWord = "AUTOIT"
            $sPng1 = _GetURLImage("https://upload.wikimedia.org/wikipedia/commons/d/d8/Autoit-icon.png")
            $sPng2 = _GetURLImage("http://www.tech2tech.fr/wp-content/uploads/2013/06/autoit-autocompletion.png")
            $sPng3 = _GetURLImage("https://www.autoitscript.com/forum/uploads/monthly_2015_04/profile_egypt.jpg.656c82deaa5d3f40f8dd3cead64a67c4.thumb.jpg.911aa23cb8c21db2434388eb7138fecf.jpg")
            $sPng4 = _GetURLImage("https://www.autoitscript.com/forum/screenshots/monthly_2015_07/autoit_screenshot_128x128.thumb.png.3e6c4b91bbeb05b8b88f070a077e018a.png")
        Case $Level = 2
            $sGuessWord = "CAR"
            $sPng1 = _GetURLImage("http://auto.ferrari.com/it_IT/wp-content/uploads/sites/8/2014/02/ferrari-official-web.jpg")
            $sPng2 = _GetURLImage("http://www.usa.philips.com/c-dam/b2c/category-pages/lighting/car-lights/master/footer/nafta-car.png")
            $sPng3 = _GetURLImage("https://www.enterprise.ca/content/dam/global-vehicle-images/cars/CHRY_200_2015.png")
            $sPng4 = _GetURLImage("https://upload.wikimedia.org/wikipedia/commons/thumb/d/d0/1957_Rambler_Rebel_hardtop_rfd-Cecil'10.jpg/800px-1957_Rambler_Rebel_hardtop_rfd-Cecil'10.jpg")
        Case $Level = 3
            $sGuessWord = "NUMBERS"
            $sPng1 = _GetURLImage("http://st.hzcdn.com/simgs/ff5158970576289a_4-8128/mediterranean-house-numbers.jpg")
            $sPng2 = _GetURLImage("http://static.nautil.us/3006_5f268dfb0fbef44de0f668a022707b86.jpg")
            $sPng3 = _GetURLImage("http://www.barnlightelectric.com/images/detailed/19/60587_NUMBERS---RED.jpg")
            $sPng4 = _GetURLImage("http://www.yareah.com/wp-content/uploads/2014/04/numbers.jpg")
        Case $Level = 4
            $sGuessWord = "BLIZZARD"
            $sPng1 = _GetURLImage("https://upload.wikimedia.org/wikipedia/en/9/93/StarCraft_box_art.jpg")
            $sPng2 = _GetURLImage("http://www.gannett-cdn.com/-mm-/af47823baecdb03f6081ce254672a5777756878b/c=118-0-1881-1322&r=x404&c=534x401/local/-/media/AsburyPark/2015/03/06/B9316488430Z.1_20150306130352_000_GHLA4R7D4.1-0.jpg")
            $sPng3 = _GetURLImage("http://cdn.abclocal.go.com/content/creativeContent/images/cms/012615-cc-past-blizzards-2-4.jpg")
            $sPng4 = _GetURLImage("http://imgc.allpostersimages.com/images/P-473-488-90/21/2169/9RJCD00Z/posters/thorsten-milse-snow-storm-blizzard-churchill-hudson-bay-manitoba-canada.jpg")
        Case $Level = 5
            $sGuessWord = "HAPPY"
            $sPng1 = _GetURLImage("http://cdn.tinybuddha.com/wp-content/uploads/2015/04/Happy-Hands.jpg")
            $sPng2 = _GetURLImage("http://i.livescience.com/images/i/000/051/022/original/happy-worker.jpg")
            $sPng3 = _GetURLImage("http://findicons.com/files/icons/2770/ios_7_icons/512/happy.png")
            $sPng4 = _GetURLImage("http://law2.umkc.edu/faculty/projects/ftrials/happylawyers/jumpinglawyer.JPG")
        Case Else
            Exit MsgBox(64, "Game Over", "Thanks for the playing - Johnmcloud")
    EndSelect
    $iLevel = $Level ; update the selection level
    If StringLen($sGuessWord) > 8 Or StringLen($sGuessWord) < 3 Then Exit ; max-min allowed character
    $aWord = _RandomizeShuffle($sGuessWord)
    For $i = 0 To 7
        GUICtrlSetData($iLetter[$i], $aWord[$i])
    Next
    For $i = 0 To 7
        GUICtrlSetData($iLetter[$i + 8], $aWord[$i + 8])
    Next
    For $i = 0 To UBound($iSolution) - 1
        GUICtrlDelete($iSolution[$i])
    Next
    For $i = 0 To StringLen($sGuessWord) - 1
        $iSolution[$i] = GUICtrlCreateLabel("", 10 + ($i * 55), 350, 45, 45, BitOR($SS_CENTER, $SS_CENTERIMAGE))
        GUICtrlSetFont(-1, 25, 400, 0, "Arial")
        GUICtrlSetBkColor(-1, 0x000000)
        GUICtrlSetColor(-1, 0xFFFFFF)
    Next
    If $sLoadImage Then
        _GUICtrlCreatePic_SetImage($iPic1, $sPng1)
        _GUICtrlCreatePic_SetImage($iPic2, $sPng2)
        _GUICtrlCreatePic_SetImage($iPic3, $sPng3)
        _GUICtrlCreatePic_SetImage($iPic4, $sPng4)
    EndIf
EndFunc   ;==>_ChoiceLevel

Have fun ;)

P.S. Change $ghGDIPDll with $__g_hGDIPDll if you are using an Autoit version over the 3.3.8.1

Edited by johnmcloud
Link to comment
Share on other sites

wakillon,

I'm still using the old old stable for XP compatibility, i'll add it has reminder/memorandum. Don't spoiler the solutions lol

JohnOne,

The gamplay is easy, there are 4 images and the images has a word in common can be applied to all of that. In the example "Autoit" can be applied to all of that so is the solution.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...