|
-
Nov 10th, 2002, 02:38 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] 2d grid with 1d control array?
I am making a checkers game, (8x8) and I am using a control array of picture boxes as the grid.... the problem is. How do I determine that if they click on picturebox 10, it is the 2nd in the 2nd row? Things like that...
Thanks.
Last edited by kandieman101; Nov 10th, 2002 at 10:00 PM.
-
Nov 10th, 2002, 03:30 PM
#2
Addicted Member
use this(in your case max=8)
PHP Code:
X = Index - (Index \ max) * max
Y = Index \ max
-
Nov 10th, 2002, 05:13 PM
#3
Thread Starter
Hyperactive Member
You have "index max" is there some operator between them?
-
Nov 10th, 2002, 06:12 PM
#4
Good Ol' Platypus
Well, this is how you do it (I don't know what Arthur's was doing):
VB Code:
X = Index Mod 8
Y = Index \ 8
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Nov 10th, 2002, 08:50 PM
#5
Thread Starter
Hyperactive Member
Originally posted by Sastraxi
Well, this is how you do it (I don't know what Arthur's was doing):
VB Code:
X = Index Mod 8
Y = Index \ 8
That won't work... if my control array is 1 - 64....
64 would be (8,8)... but 64 mod 8 = 0....
-
Nov 10th, 2002, 09:52 PM
#6
Hyperactive Member
one way to do it is to have your control array values "seem" to be 2d you can set them as, this will work in your situation but will not work if your "wana be" 2d control array is more than 99 x 99 controls because the index will not go that hight.
11,12,13,14,15,16,17,18
21,22,23,24,25,26,27,28
.ect
then when every you want to convert them to use in the reg array say something like
y = val(left(str(piccheckersquare.index)),1)
x = val(right(str(piccheckersquare.index)),1)
'the left functoin is a premade (with vb6 at least, not shure about other versions) it gets the chractors starting from the left of the string you speify to the number you specify over
if that didnt make since hers some examples:
get = left("abc",1)
get = "a"
get = left("abc",2)
get = "ab"
get = left("cba",2)
get = "cb"
right does the same but from the right side
-
Nov 10th, 2002, 09:59 PM
#7
Thread Starter
Hyperactive Member
Thanks for all your input guys.. I am well on my way!
-
Nov 10th, 2002, 10:37 PM
#8
Good Ol' Platypus
KandieMan, my code was correct. Controll arrays should be 0 to 63 (for an 8 x 8 grid). Thus:
X = 63 Mod 8
X = 7
Y = 63 \ 8
Y = Int(63 / 8)
Y = Int(7.785)
Y = 7
And as you can see, it returns 7, 7, which is correct.
[EDIT] changed X's to Y's in the 2nd block.
Last edited by Sastraxi; Nov 11th, 2002 at 12:23 AM.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Nov 10th, 2002, 11:45 PM
#9
Hyperactive Member
VB Code:
X = 63 Mod 8
X = 7
X = 63 \ 8
X = Int(63 / 8)
X = Int(7.785)
X = 7
umm yeah this will always return 7
at the end you set X to 7
also what does the Mod operoator to
is it remander of divsion
-
Nov 11th, 2002, 12:23 AM
#10
Good Ol' Platypus
Whoops, the 2nd block is meant to be Y = instead of X =. Anyway, that was just a thought process, look at it, 63 mod 8 IS 7. Int(7.785) IS 7. It's not code, if it was I would've put it in code tags.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|