PDA

Click to See Complete Forum and Search --> : move a button w/ just a click


pnj
Mar 20th, 2001, 05:22 PM
I asked this in another area and did not get a response.
but it IS a game question so I will ask it here.

I have some command buttons on my form and they are inside picture box's. one of the picture box's is empty(no button) and I want to be able to detect what one is empty, then put the command button that was clicked inside the empty picture box.

does that make sense?

there is more to it than that but right now i'm just trying to figure this part out.

i hope you can make sense of that
thanks

Mar 20th, 2001, 05:52 PM
Im not sure how to move a command button from one picture box to another, but you can move the picture box itself. Just switch the empty box with the box with the button.

Z.

pnj
Mar 21st, 2001, 09:51 AM
your right you can't move an object that is inside a picture box but you can move the picture box itself.(i just read that in the help files)

but with my situation I have 16 picture box's and 15 have command buttons in them. the box's w/ buttons can only trade places with the the empty box if it is directly above ,below or to the left or right.

the box's are laid out in a 4 by 4 grid.
what i thought i could to is have a function that works somewhat like this:

function Checker(index as integer)
dim i
i = index
for i = i step 5
if [the fifth box is empty] then
command(i).move left[wherever the emtpy box is]
emtpybox.move [wherever the button was]
next

end function

I would need a function to check forward one box and also forward 5 box's
then one to check back one box and back 5 box's

I know the syntax is incorrect in that function and that is kind of my question.
how do i tell the computer to check the fifth, or first box(starting from the right of the botton clicked) and see if the box is empty?

I know I am not explaining this very well, sorry.

thanks

kedaman
Mar 21st, 2001, 03:33 PM
are you making some kind of puzzle game where you switch boxes until you have them all in order from 1 to 16? In that case why do you have both pictureboxes and command buttons?

pnj
Mar 21st, 2001, 03:52 PM
I am doing that.
what i have is 16 picture box's and 15 have buttons in them.I know I can write a bunch of code that checks
for each possible movement and then i would have 16 different else/if statements but I thought
i could write a function that would run some simple math.(see my crappy attemt in the other post in this
thread)

becouse the button pushed can only move if the empty button is directly to the left or right or if it is
five to the left or right. if the picture box's are numbered 1 to 16.

i think..... my problem is i'm not exactly sure of the syntax.
i've looked in the books i have and in the help files but i'm not getting it....

any suggestions kedaman?

thanks

Mar 21st, 2001, 04:33 PM
Create a second array in the program, of Boolean
values. This array should be 2 dimensional (a grid).
every one of these elements should have a true value,
except for the empty box. Then, you can use this code:

'// Direction values: 1 = Up, 2 = Down, 3 = Left, 4 = Right
'// this code assumes there is a 2 dimensional array
'// called locations defined as public, with rows from 0 -
'// 3, and columns from 0 - 3. It wont check if you
'// are on an edge.
function checker(Boxindex as integer, direction as integer) as boolean
Dim x as integer
Dim y as integer
'// get x and y values of the box
if boxindex < 4 then
y = 0: x = boxindex - 1
else
boxindex = boxindex - 4
if boxindex > 4 then
boxindex = boxindex - 4
if boxindex > 4 then
boxindex = boxindex - 4
y = 3: x = boxindex - 1
else
y = 2: x = boxindex - 1
end if
else
y = 1: x = boxindex - 1
end if
end if
'// thats horrid code, but it works
select case direction
case 1:
if Locations(x, y - 1) = true then
checker = false
exit function
end if
case 2:
if Locations(x, y + 1) = true then
checker = false
exit function
end if
case 3:
if Locations(x - 1, y) = true then
checker = false
exit function
end if
case 4:
if Locations(x + 1, y) = true then
checker = false
exit function
end if
end select
'// if we got here, the box in the direction specified is empty
checker = true
end function


that should work, but its all from the top of my head, so
i dont know =).

Z.

pnj
Mar 21st, 2001, 05:03 PM
i'll give this a try when i get home from work....

thanks a bunch.

kedaman
Mar 22nd, 2001, 01:01 AM
Skip the commandbuttons and stick to 16 pictureboxes, of a control array indexed from 0 to 15. you could for instance place a picture in each indicating their number.

you should have a byte array indicating each number placed in the pictureboxes, let the pictureboxes stay while the numbers swaps when you click on them. Second you need a byte number indicating the empty picturebox index so that you can determine if a click should lead to a swap and if so with this index.

pnj
Mar 22nd, 2001, 09:39 AM
ok kedaman i'll give it a try

thanks