finding the right placie

Advanced game related topics
Behnood
User
User
Posts: 72
Joined: Fri Apr 25, 2003 10:07 pm
Location: Australia
Contact:

finding the right placie

Post 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
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post 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

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Behnood
User
User
Posts: 72
Joined: Fri Apr 25, 2003 10:07 pm
Location: Australia
Contact:

Post 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
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post 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

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Post Reply