Func GetTopLeftCorner ( $ window )The function checks the colors of points, running diagonally, searches for the left edge of the game window in the browser. Then it scans the colors of the dots, running up, looking for the upper border of the game window. I will consider the found point as a “ point of reference ”. The distance from it to each cell on the game field is fixed and easily calculated by the index. The result of the function is returned in global variables $ x and $ y , which correspond to the coordinates of the point horizontally and vertically, respectively. When you call the function, you must specify the title of the program window as a parameter . It can be set manually by defining it in advance using the AutoIt Window Info utility, which is installed along with AutoIt.The script above uses the self-made CheckRGB function:
Global $ x = 0 , $ y = 0
WinActivate ( $ window , "" )
If WinActive ( $ window ) Then
$ size = WinGetPos ( "[active]" )
For $ i = 1 To $ size [ 3 ]
If CheckRGB ( PixelGetColor ( $ x + $ i , $ y + $ i ) , Dec ( "402215" ) , Dec ( "5A352A" ) ) Then
If CheckRGB ( PixelGetColor ( $ x + $ i - 259 , $ y + $ i ) , Dec ( "331A0D" ) , Dec ( "624232" ) )
For $ j = $ i To 1 Step - 1
If not CheckRGB ( PixelGetColor ( $ i + 1 , $ j ) , Dec ( "000000" ) , Dec ( "3A301D" ) ) Then
$ x = $ i
$ y = $ j
ExitLoop ( 2 )
Endif
Next
Exitloop
Endif
Endif
Next
Endif
Endfunc
Func CheckRGB ( $ color , $ min , $ max )- The function checks the color of the point transmitted as the first parameter $ color to ensure that it is in the color range from $ min to $ max , taking into account the three component colors of the point ( RGB ). Returns, respectively, True or False .
Local $ rgb [ 3 ] [ 3 ]
$ res = True
$ rgb [ 2 ] [ 0 ] = BitAND ( $ min , Dec ( "FF0000" ) ) / Dec ( "10000" )
$ rgb [ 1 ] [ 0 ] = BitAND ( $ min , Dec ( "00FF00" ) ) / Dec ( "100" )
$ rgb [ 0 ] [ 0 ] = BitAND ( $ min , Dec ( "0000FF" ) )
$ rgb [ 2 ] [ 1 ] = BitAND ( $ color , Dec ( "FF0000" ) ) / Dec ( "10000" )
$ rgb [ 1 ] [ 1 ] = BitAND ( $ color , Dec ( "00FF00" ) ) / Dec ( "100" )
$ rgb [ 0 ] [ 1 ] = BitAND ( $ color , Dec ( "0000FF" ) )
$ rgb [ 2 ] [ 2 ] = BitAND ( $ max , Dec ( "FF0000" ) ) / Dec ( "10000" )
$ rgb [ 1 ] [ 2 ] = BitAND ( $ max , Dec ( "00FF00" ) ) / Dec ( "100" )
$ rgb [ 0 ] [ 2 ] = BitAND ( $ max , Dec ( "0000FF" ) )
For $ i = 0 To 2
If $ rgb [ $ i ] [ 0 ] > $ rgb [ $ i ] [ 1 ] Or $ rgb [ $ i ] [ 1 ] > $ rgb [ $ i ] [ 2 ] Then
$ res = False
Exitloop
Endif
Next
Return $ res
Endfunc
For $ i = 1 To 12It's all clear. 10 and 12 in the loop headers is the size of the field in the cells. Constants in MouseClick parameters are calculated using the same AutoIt Window Info utility, relative to the previously defined “reference point”. The value of the delay in the Sleep can be changed at will - this will affect the speed of sticking, but too fast can lead to errors in the execution of the game script.
For $ j = 1 To 10
MouseClick ( "left" , $ x + ( $ i * 40 ) + 103 , $ y + ( $ j * 40 ) + 172 , 1 , 1 )
Sleep ( 25 )
Next
Next
Local $ i , $ j , $ n
Local $ oIE = _IEAttach ( $ gamewindowname )
For $ i = 1 To 12
For $ j = 0 To 9
$ obj = _IEGetObjById ( $ oIE , "f" & ( 12 * $ j + $ i ) )
If $ obj <> 0 Then $ obj . click ( )
Next
Next
$ obj = _IEGetObjById ( $ oIE , "anpflanzen" )Here is this piece of HTML code to insert into the previous snippet:
If $ obj <> 0 Then _
$ obj . outerHTML = "... there is a piece of HTML code, which, for convenience, I cite separately"
< SPAN id = anpflanzen class = link onclick = "The code itself and the JavaScript scripts were borrowed from the original HTML code of the game and the script file loaded with it, and were slightly altered from watering to planting.
selectMode (0, true, selected);
var i, j, s, n = 0;
for (i = 1; i <13; i = i + rackElement [selected] .x)
for (j = 0; j <10; j = j + rackElement [selected] .y) {
s = 12 * j + i; cache_me (" & $ zone & ", s, garten_prod [s], garten_kategorie [s], n ++);} " >
< IMG onmouseover = "this.src = 'http: //mff.wavecdn.de/mff/garden_menue_seed.gif'; showDiv ('tooltipseed')" onmouseout = "this.src = 'http: //mff.wavecdn. de / mff / leer.gif '; hideDiv (' tooltipseed ') " src = " http://mff.wavecdn.de/mff/leer.gif " width = 53 height = 68 >
< DIV style = "DISPLAY: none" id = tooltipseed class = blackbox onmouseover = "showDiv ('tooltipseed')" onmouseout = "hideDiv ('tooltipseed')" src = "http://mff.wavecdn.de/mff/ leer.gif " > plant everything < / div > < / span >
Source: https://habr.com/ru/post/126957/
All Articles