How is the board drawn?
If it's a grid then you calculate the square clicked on from the mouse X and Y positions.
Essentially you take the mouse X position and subtract the X position of the top left corner of the grid. Divide this by the width of the button and you get the horizontal button position.
Next, you take the mouse Y position and subtract the Y position of the top left corner of the grid. Divide this by the height of the button and you get the vertical button position.
The vertical button position is multiplied by the number of buttons in a row and finally the horizontal button position is added.
On a 10x10 grid of buttons this returns 0 to 99 so if you want the first button to be number 1, you add 1 in the final calculation.
Set Display Mode 800,600,16
Sync On: Sync Rate 0: CLS 0
Set Text Opaque
GridTopLeftX=100
GridTopLeftY=100
ButtonCols=10
ButtonRows=10
ButtonSize=32
Grid(GridTopLeftX,GridTopLeftY,ButtonCols,ButtonRows,ButtonSize)
Do
Mx=MouseX(): My=MouseY(): Mc=MouseClick()
If Mx>GridTopLeftX And My>GridTopLeftY And Mx<GridTopLeftX+(ButtonCols*ButtonSize) And My<GridTopLeftY+(ButtonRows*ButtonSize)
OverColumn=(Mx-GridTopLeftX)/ButtonSize
OverRow=(My-GridTopLeftY)/ButtonSize
OverButton=OverRow*ButtonCols+OverColumn+1
Endif
Sync
Text 2,2,"Over Button: "+Str$(OverButton)+" "
Loop
End
Function Grid(tlx,tly,Cols,Rows,Size)
Ink rgb(255,255,255),0
For N=0 To Rows
Line tlx,N*(Size+1)+tly,Cols*(Size+1)+tlx,N*(Size+1)+tly
Next N
For N=0 To Cols
Line N*(Size+1)+tlx,tly,N*(Size+1)+tlx,Rows*(Size+1)+tly
Next N
Endfunction
You can use the same method with buttons as long as they are pretty closely grouped and they are arranged in a rectangular pattern. You just need to know the top left X and Y position that the buttons start, the number of columns and rows, as well as the button's width and height.
TDK_Man