Page 1 of 1
finding the right placie
Posted: Wed Oct 15, 2003 11:24 am
by Behnood
hi
i'm writing a puzzle game base on a dots and lines puzzle.
right now i have a problem about finding the user choice.
in my game user must select a empty place in the board and fill it by a dot to arrange 5 dot in a line(horizental , vertical or orthagonal)
the board is a matrix of dots (2d) assume 20 point*20 point
so a dot can be in more than one line (a line will contain 5 dot)
i want to find where is the mouse pointer and base on this find which lines can be selected.
any idea?!
regards
Reza Behnood
Posted: Wed Oct 15, 2003 1:10 pm
by LarsG
Hi Behnood,
Youd probably start by setting up an Array, 20x20 in size.
This array you would fill a value on the correct spot, but getting the mousex and mousey values (and most likely dividing this by the size of you "squares" (grid)).
Hope this helps you a bit..
(I can show you a working code snippet of this, but I'd rather you try it on your own first!!

)
-Lars
Posted: Thu Oct 16, 2003 5:45 am
by Behnood
thanks for your reply
i made a array (30*30) for creating game board in computer.
then i filled he array with 0 (for dots yet empty) and 1 (for dots are full)
now i want to find which possible lines player will select?
problem is the possible lines (and dots) for each series of dots ae more than one and are share some dots.
right now i use spritecollision command to find which dot sprite overlaped with mouse pointer.
any idea?
regards
Reza Behnood
Posted: Thu Oct 16, 2003 9:16 am
by LarsG
So what you're saying is that a "line" i a series of dots in a row?!
If this is the case, then you just have to make a little FOR loop to
run through the array to see if there are any dots (1's in the array) that are placed next to eachother...
Perhaps like this:
Code: Select all
x = 5 ; the x value of the current dot in the array
y = 5 ; the y value of the current dot in the array
found = 0 ; variable to hold the current no. of dots in a row
tofind = 4 ; the number of dots we're looking for in a row
line = 0 ; boolean to see if we've found a line or not
; now, to check if there are any dots lying after one-another in the array
; (forming a line)
for i = x-5 to x+5
if game_board(i,y) = 1
; add one to the found variable
found +1
if found = tofind
; then we've found enough dots in a row
line = 1
; break the loop (no need to check anymore
break
endif
else
; the array at that spot is not a dot
; reset the found var
found = 0
endif
next
I hope this is what you were looking for..
(oh, and btw: I haven't tested the example, but I think it should work)
-Lars