GLY7CH Guest
|
Posted: Fri Aug 11, 2006 5:34 pm Post subject: problem calling OnCellDraw method |
|
|
Hi all.
Bit of a stupid problem i'm having here, i'm sure someone can point out
what to do in an instance, whereas i've been searching for a good hour
now.
Basically I am writing an Othello (the game) app in BCB 6, all the
backend data model stuff is in place and some of the GUI is done. I am
using a DrawGrid to represent the board, which needs each cell to be
filled either black or white depending on the state of each element of
an array of Piece objects (a piece inherits position(int x, int y) and
adds a char state). Inspecting and setting states of each element is of
course a piece of cake, but I need to represent this back to the GUI
DrawGrid. This method would be called at the start of a new game and on
every subsequent move to update the draw grid according to the new
state of the board array.
I have written the following method to determine which colour to use
and then fill the inspected cell with that colour:
void __fastcall TMain::grdBoardDrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if(board->board[ACol][ARow].getState() == 'b')
{
grdBoard->Canvas->Brush->Color = clBlack;
grdBoard->Canvas->FloodFill(ACol, ARow, clBlack,
fsBorder);
}
else if (board->board[ARow][ACol].getState() == 'w')
{
grdBoard->Canvas->Brush->Color = clWhite;
grdBoard->Canvas->FloodFill(ACol, ARow, clWhite,
fsBorder);
}
}
Is this correct? Would this work??
When a new game is started the board is initialised with the centre 4
pieces set, the player's colour is set to 'b' for black, the scores on
the GUI are all updated and then the DrawGrid needs to be updated with
the correct cells shaded. Here's that method:
void __fastcall TMain::btnNewGameClick(TObject *Sender)
{
board->initBoard();
player->setColour('b');
updateAll();
for (int x = boardXMin; x <= boardXMax; x++)
{
for (int y = boardYMin; y <= boardYMax; y++)
{
//grdBoardDrawCell();
}
}
memInfo->Lines->Add("You have started a new game. Click on a
cell to select it, then click on Make Move");
}
The problem I have is I dont know what parameters to pass to the
grdBoardDrawCell method aside from the x and y of course. I assume for
the sender object that 'this' would suffice? As for the Rect and State
objects, I dont even know what they are so unsure what to pass.
If anyone can point out my errors here and show me how to fix them or
even tell me its all wrong and show me the right way to do what im
trying then all the better!
Kind Regards |
|