Jump to content

Recommended Posts

Posted

Maybe something like this

#include <winapi.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include "G:\icons\Icons.au3"
$square = 20;how many squares on each side of the board
$side = 40;the size of the label(square)
$pitch = 41

Dim $board[$square][$square], $gameboard[$square][$square]


$captionHt = _WinAPI_GetSystemMetrics(4)
$borderWid = _WinAPI_GetSystemMetrics(33)


$GUI = GUICreate("game board", $square * $pitch + 2 * $borderWid, $square * $pitch + 2 * $borderWid + $captionHt, -1, -1, BitOR(0x0000080, 8))



$x = -$pitch + Ceiling(($pitch - $side) / 2)

$count = 0
For $o = 0 To $square - 1
    $x += $pitch
    $y = -$side
    $count += 1;the count of columns drawn
    $Bcount = $count;the count of labels in the column
    For $oo = 0 To $square - 1
    $y += $pitch
    $board[$o][$oo] = GUICtrlCreateLabel('', $x, $y, $side, $side, BitOR($SS_CENTER, $SS_CENTERIMAGE))
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetBkColor(-1, SquareCol($Bcount))
    ;GUICtrlSetBkColor($gameboard[$o][9],0xF222FE)
    $Bcount += 1;the number of squares drawn so far
    Next
Next
GUISetState()
Global $x = 50, $y = 50, $wayx = 1, $wayy = 1
$Pic1 = GUICtrlCreatePic("", 50, 50, 32, 32)
_SetImage($Pic1, "mmm2.png")


$va = GUICtrlCreateIcon("mmm2.ico", 34, 34, 50, 50)
$cs = WinGetClientSize($GUI)
ConsoleWrite($cs[0] & ', ' & $cs[1] & @CRLF)


AdlibRegister("moveit", 30)
While GUIGetMsg() <> -3

WEnd
Func Moveit()
    $x += 2*$wayx
    If $x < 0 Then
    $x = 2
    $wayx = 1
    EndIf
    If $x > $square * $pitch - 34 Then
    $x = $square * $pitch - 36
    $wayx = -1
    EndIf

     $y += 3*$wayy
     If $y < 0 Then
    $y = 3
    $wayy = 1
    EndIf
    If $y > $square * $pitch - 34 Then
    $y = $square * $pitch - 36
    $wayy = -1
    EndIf
controlmove($GUI,"",$pic1,$x,$y)
_SetImage($Pic1, "mmm2.png")
EndFunc ;==>Moveit

Func SquareCol($i)
    If Mod($i, 2) = 0 Then Return 0x00ff00;even colours

    Return 0x0000ff;odd colours

EndFunc ;==>SquareCol
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Posted (edited)

ohhh its so hard function for my level but i will try to understand it))) thank you so much martin you very help me.

how to put $x and $y to be board[x][y] and gameboard[x][y]? if $square = 20 and $side = 30 we have 400 boxes [20][20] and coordinates of [1][1] is 30x30 and coordinates of [3][3] is 93x93 bc after evry box we have 1 pixel of pitch.

realy sorry for so more questions, i have so more idies and so little experience in programing :mellow:

Edited by toader

[center][font=courier new,courier,monospace]Die die die my darling[/font][/center][center][font=courier new,courier,monospace]Don't utter a single word[/font][/center][center][font=courier new,courier,monospace]Die die die my darling[/font][/center][center][font=courier new,courier,monospace]Just shut your pretty mouth[/font][/center][center][font=courier new,courier,monospace]I'll be seeing you again[/font][/center][center][font=courier new,courier,monospace]I'll be seeing you[/font][/center][center][font=courier new,courier,monospace]In hell[/font][/center]

Posted

ohhh its so hard function for my level but i will try to understand it))) thank you so much martin you very help me.

how to put $x and $y to be board[x][y] and gameboard[x][y]? if $square = 20 and $side = 30 we have 400 boxes [20][20] and coordinates of [1][1] is 30x30 and coordinates of [3][3] is 93x93 bc after evry box we have 1 pixel of pitch.

realy sorry for so more questions, i have so more idies and so little experience in programing :mellow:

Ok, but after this you're going to have to produce your own code to show what you have tried before I start spending more time on this.

Your experience in programming isn't what is holding you back in my opinion. More likely not enough understanding of what is being done and why. If you know that each square is 31 from the next one and you want the position of the seventh square then, since the first one starts at 1 and the second one start at 31, isn't it going to be (7-1)*30+1?

#include <winapi.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include "G:\icons\Icons.au3"
$square = 20;how many squares on each side of the board
$side = 40;the size of the label(square)
$pitch = 41

Dim $board[$square][$square], $gameboard[$square][$square]


$captionHt = _WinAPI_GetSystemMetrics(4)
$borderWid = _WinAPI_GetSystemMetrics(33)


$GUI = GUICreate("game board", $square * $pitch + 2 * $borderWid, $square * $pitch + 2 * $borderWid + $captionHt, -1, -1, BitOR(0x0000080, 8))



$x = -$pitch + Ceiling(($pitch - $side) / 2)

$count = 0
For $o = 0 To $square - 1
    $x += $pitch
    $y = -$side
    $count += 1;the count of columns drawn
    $Bcount = $count;the count of labels in the column
    For $oo = 0 To $square - 1
    $y += $pitch
    $board[$o][$oo] = GUICtrlCreateLabel('', $x, $y, $side, $side, BitOR($SS_CENTER, $SS_CENTERIMAGE))
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetBkColor(-1, SquareCol($Bcount))
    ;GUICtrlSetBkColor($gameboard[$o][9],0xF222FE)
    $Bcount += 1;the number of squares drawn so far
    Next
Next

$ipx = GUICtrlCreateInput("1", 400, 5, 50, 28)
$BtnX = GUICtrlCreateButton("Set Colum", 460, 5, 100, 28)
$ipy = GUICtrlCreateInput("1", 400, 38, 50, 28)
$BtnY = GUICtrlCreateButton("Set Row", 460, 35, 100, 28)

$ipcx = GUICtrlCreateInput("16", 400, 85, 50, 28)
$BtncX = GUICtrlCreateButton("Set X coord", 460, 85, 100, 28)
$ipcy = GUICtrlCreateInput("16", 400, 118, 50, 28)
$BtncY = GUICtrlCreateButton("Set Y coord", 460, 115, 100, 28)
GUISetState()

GUISetState()
Global $x = 50, $y = 50, $wayx = 1, $wayy = 1
$Pic1 = GUICtrlCreatePic("", 5, 5, 34, 34)
_SetImage($Pic1, "mmm2.png")


$sqx = 1
$sqy = 1
$x1 = 1
$y1 = 1
While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case - 3
    Exit
    Case $BtnX
    $x1 = GUICtrlRead($ipx)
    ;add some check to make sure $sqx is sensible
    ControlMove($GUI, "", $Pic1, ($x1 - 1) * $pitch + 5, ($y1 - 1) * $pitch + 5)
    _SetImage($Pic1, "mmm2.png")

    Case $BtnY
    $y1 = GUICtrlRead($ipy)
    ;add some check to make sure $sqy is sensible
    ControlMove($GUI, "", $Pic1, ($x1 - 1) * $pitch + 5, ($y1 - 1) * $pitch + 5)
    _SetImage($Pic1, "mmm2.png")

    Case $BtncX
    $coordx = GUICtrlRead($ipcx)

    $x1 = Ceiling($coordx/$pitch)
            ConsoleWrite($x1 & @CRLF)
    ControlMove($GUI, "", $Pic1, ($x1 - 1) * $pitch + 5, ($y1 - 1) * $pitch + 5)
    _SetImage($Pic1, "mmm2.png")

    Case $BtncY
    $coordy = GUICtrlRead($ipcy)
            ConsoleWrite($coordy/$pitch & @CRLF)
    $y1 = Ceiling($coordy / $pitch)
    ControlMove($GUI, "", $Pic1, ($x1 - 1) * $pitch + 5, ($y1 - 1) * $pitch + 5)
    _SetImage($Pic1, "mmm2.png")

    EndSwitch
WEnd

Func SquareCol($i)
    If Mod($i, 2) = 0 Then Return 0x00ff00;even colours

    Return 0x0000ff;odd colours

EndFunc ;==>SquareCol
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Posted (edited)

Ohhh.. martin.. Thank you so much!!

Its greate work, Thank you!

now i try to move it)) don't work but i will try more))

$x2 = GUICtrlRead($ipx)
    If $x2 > $x1 Then
        For $x1 to $x1 = $x2 Step +1
            ControlMove($GUI, "", $Pic1, ($x1 - 1) + $pitch + 2, ($y1 - 1) + $pitch + 2)
            _SetImage($Pic1, "mmm2.png")
        Next
    ElseIf $x2 = $x1 Then
        ControlMove($GUI, "", $Pic1, ($x1 - 1) * $pitch + 5, ($y1 - 1) * $pitch + 5)
        _SetImage($Pic1, "mmm2.png")
    Else
        For $x1 to $x1 = $x2 Step -1
            ControlMove($GUI, "", $Pic1, ($x1 - 1) - $pitch + 2, ($y1 - 1) - $pitch + 2)
            _SetImage($Pic1, "mmm2.png")
        Next
    EndIf

i know that don't work but this is first attempt to manipulate image to can move where need.

And about

More likely not enough understanding of what is being done and why

I try to do first cool game what are done in AutoIt :mellow: i know that will be the best game :( Edited by toader

[center][font=courier new,courier,monospace]Die die die my darling[/font][/center][center][font=courier new,courier,monospace]Don't utter a single word[/font][/center][center][font=courier new,courier,monospace]Die die die my darling[/font][/center][center][font=courier new,courier,monospace]Just shut your pretty mouth[/font][/center][center][font=courier new,courier,monospace]I'll be seeing you again[/font][/center][center][font=courier new,courier,monospace]I'll be seeing you[/font][/center][center][font=courier new,courier,monospace]In hell[/font][/center]

Posted (edited)

Add this line somewhere near the start of your script

Global Const $movepause 100; How long to wait before moving to next square

Then, here is a change to the code you wrote

Case $BtnX

    $x2 = GUICtrlRead($ipx)
            ;add some check to make sure $x2 is sensible ie within 1 to 20
            
    If $x2 > $x1 Then
    For $n = $x1 To $x2 Step +1
    ControlMove($GUI, "", $Pic1, ($n - 1) * $pitch + 2, ($y1 - 1) * $pitch + 2);these 3 lines....
    _SetImage($Pic1, "mmm2.png")
                    sleep($movepause)
    Next
    ElseIf $x2 = $x1 Then
    ControlMove($GUI, "", $Pic1, ($x2 - 1) * $pitch + 5, ($y1 - 1) * $pitch + 5):.....................use exactly the same
    _SetImage($Pic1, "mmm2.png")
    Else
    For $n= $x1 To $x2 Step -1
    ControlMove($GUI, "", $Pic1, ($n - 1) * $pitch + 2, ($y1 - 1) * $pitch + 2);............................... calculation for the X and the Y coordinates.
    _SetImage($Pic1, "mmm2.png")
                    sleep($movepause)
    Next
    EndIf
    $x1 = $x2;update current X position

You need to read the help section about for...next loops.

Always use a dedicated variable for the for/next loop. It makes it easier to understand (for me anyway) and it avoids problems with using the variable outside of the loop because for next loop variables are treated in a special way and you can get strange problems. So use a loop variable that is only used for the loop count.

I try to do first cool game what are done in AutoIt :mellow: i know that will be the best game :(

I think that maybe you misunderstood what I meant, but either way, good luck Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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
×
×
  • Create New...