BBjGridData

Description

In BBj 18.00 and higher, this object collects a snapshot of data from a particular group of user specified grid cells.

Creation

BBjAPI > BBjSysGui > BBjWindow > BBjStandardGrid > BBjGridData

A BBjGridData object is created through the BBjGrid using one of the following methods:

Return Value

Method

BBjGridData

getCellRange(int startRow, int startCol, int endRow, int endCol)

BBjGridData

geColumnData(int col, int startRow, int endRow)

BBjGridData

getRowData(int row)

getRowData(int startRow, int endRow)

Methods of BBjGridData

Return Value

Method

boolean

contains(int row, int col)

BBjGridCell

first()

BBjGridCell

get(int row, int col)

BBjVector

getList()

int

getSize()

boolean

hasNext()

boolean

isEmpty()

BBjGridCell

last()

BBjGridCell

next()

boolean

remove(int row, int col)

void

startIteration()

Example

rem Object-oriented Guessing Game
rem Try to find the secret cell in the fewest clicks!
declare GridDataGuessingGame game!
game! = new GridDataGuessingGame(15,15)
process_events

class public GridDataGuessingGame
    field public BBjSysGui sysgui!
    field public BBjStandardGrid grid!
    field public BBjGridData remainingCells!
    field private BBjInt secretRow!
    field private BBjInt secretCol!

    method public GridDataGuessingGame(BBjNumber rows, BBjNumber cols)
        declare auto BBjWindow window!
        cellSize = 25
        #sysgui! = bbjapi().openSysGui("X0")
        window! = #sysgui!.addWindow(10,10,(cellSize+1)*cols,(cellSize+1)*rows,"BBjGridData Guessing Game",$00010082$)
        window!.setCallback(window!.ON_CLOSE, #this!, "onClose")
        #grid! = window!.addGrid(101,102,103,10,10,(cellSize+2)*cols,(cellSize+2)*rows,$8040$, rows, cols) 
        #grid!.setRowHeight(cellSize)
        #grid!.setDefaultColumnWidth(cellSize)
        #grid!.setCallback(#grid!.ON_GRID_MOUSE_DOWN, #this!, "onMouseDown")
        #restart()
    methodend

    method public void restart()
        #grid!.deselectAllCells()
        #secretRow! = rnd(#grid!.getNumRows())
        #secretCol! = rnd(#grid!.getNumColumns())
        #remainingCells! = #grid!.getCellRange(0,0,#grid!.getNumRows()-1,#grid!.getNumColumns()-1)
        #remainingCells!.startIteration()
        while #remainingCells!.hasNext()
            cell! = #remainingCells!.next()
            cell!.setBackColor(#sysgui!.makeColor(#sysgui!.WHITE))
            #grid!.setCell(cell!)
        wend
    methodend

    method public void onMouseDown(BBjGridMouseDownEvent event!)
        row = event!.getRow()
        col = event!.getColumn()
        selectedCell! = #grid!.getCell(row,col)
        selectedCell!.setBackColor(#sysgui!.makeColor(#sysgui!.GRAY))
        #grid!.setCell(selectedCell!)
        rowData! = #grid!.getRowData(row)
        colData! = #grid!.getColumnData(col,0,#grid!.getNumRows())
        proxData! = #grid!.getCellRange(row-1,col-1,row+1,col+1)
        #remainingCells!.remove(row,col)

        if (row = #secretRow! and col = #secretCol!) then
            winMessage = msgbox("You win! Score: "+ str(#remainingCells!.getSize()))
            print #remainingCells!.getList()
            #restart()
            methodret
        endif

        #checkData(rowData!)
        #checkData(colData!)
        #checkData(proxData!)
    methodend

    method public void checkData(BBjGridData gridData!)
        if (gridData!.contains(#secretRow!, #secretCol!)) then
            methodret
        endif

        red! = #sysgui!.makeColor(#sysgui!.RED)
        gridData!.startIteration()
        while gridData!.hasNext()
            dataCell! = gridData!.next()
            row = dataCell!.getRow()
            col = dataCell!.getColumn()
            if (#remainingCells!.contains(row,col)) then
                gridCell! = #grid!.getCell(row,col)
                gridCell!.setBackColor(red!)
                #grid!.setCell(gridCell!)
                #remainingCells!.remove(row,col)
            endif
        wend
    methodend

    method public void onClose(BBjCloseEvent event!)
        release
    methodend
classend

See Also

BBjAPI

BBjGrid

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.