I have a problem and I don't understand where I'm going wrong. My program doesn't show any compiler errors.
I am working at a chess project. When I click on a piece, I want an ID to be remembered. When I click on the Board, I want to move the piece with that ID. I have 2 black ROOKS, both with different IDs.
Here is the code:
formaJoc.cpp
void movePiece(int piece, int col, int row)
{
int left = rowColToPixel[col];
int top = rowColToPixel[row];
switch (piece)
{
case(0): {
fJoc->BlackRooks1[1]->imPiece->OnMouseDown = fJoc -> bkRook1MouseDown;
fJoc->BlackRooks1[1]->imPiece->Left=left;
fJoc->BlackRooks1[1]->imPiece->Top=top;
break;
}
case(1): {
fJoc->BlackRooks2[1]->imPiece->OnMouseDown = fJoc -> bkRook2MouseDown;
fJoc->BlackRooks2[1]->imPiece->Left=left;
fJoc->BlackRooks2[1]->imPiece->Top=top;
break;
}
}
}
void __fastcall TfJoc::bkRook1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
id = 0;
}
void __fastcall TfJoc::bkRook2MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
id = 1;
}
void __fastcall TfJoc::imBoardMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if (id != 99) {
col = (X - 40) / 36;
row = (Y - 40) / 36;
//movePiece(id, col, row);
//id=99;
ShowMessage(id);
}
}
formaJoc.h
bkRook* BlackRooks1[1];
bkRook* BlackRooks2[1];
void __fastcall TfJoc::bkRook1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall TfJoc::bkRook2MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall imBoardMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y);
When I run the program and click on ROOK 1, ID is set to 0. When I click on ROOK 2, ID is still 0. Why is it not 1? Why does it take the same ID?