📄 weiqiply.cpp
字号:
DrawStone( WhichSide, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
}
}
bTurn = false;
}
else // GamePlay == gtPlay; It's the oppenent's go.
{
ReceivePlaceToGoTo();
if( StonePlaceToGoTo.bX && StonePlaceToGoTo.bY )
{
// ShowMessage( WeiqiBoard->Order );
if( WeiqiBoard->Phase[ StonePlaceToGoTo.nX ][ StonePlaceToGoTo.nY ] == wqSideNone )
{
if( WhichSide == wqSideBlack )
{
SetStoneCoordination( wqSideWhite, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
WeiqiBoard->InsertStone( wqSideWhite, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
ImageListStones->Add( BitmapStoneWhite, NULL );
ImageListStonesLived->Add( BitmapStoneWhite, NULL );
StatusBarWeiqi->Panels->Items[0]->Text = "Order: " + IntToStr( WeiqiBoard->Order );
StatusBarWeiqi->Panels->Items[4]->Text = "White to move...";
DrawStone( wqSideWhite, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
}
else if( WhichSide == wqSideWhite )
{
SetStoneCoordination( wqSideBlack, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
WeiqiBoard->InsertStone( wqSideBlack, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
ImageListStones->Add( BitmapStoneBlack, NULL );
ImageListStonesLived->Add( BitmapStoneBlack, NULL );
StatusBarWeiqi->Panels->Items[0]->Text = "Order: " + IntToStr( WeiqiBoard->Order );
StatusBarWeiqi->Panels->Items[4]->Text = "Black to move...";
DrawStone( wqSideBlack, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
}
}
}
bTurn = true;
}
}
else if( GameType == gtLearn )
{
GetPlaceToGoTo();
// Record the place to go to in Weiqi->Board, and show it in the main form.
if( StonePlaceToGoTo.bX && StonePlaceToGoTo.bY )
{
// ShowMessage( WeiqiBoard->Order );
if( WeiqiBoard->Phase[ StonePlaceToGoTo.nX ][ StonePlaceToGoTo.nY ] == wqSideNone )
{
SetStoneCoordination( WhichSide, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
if( WhichSide == wqSideBlack )
{
WeiqiBoard->InsertStone( WhichSide, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
ImageListStones->Add( BitmapStoneBlack, NULL );
ImageListStonesLived->Add( BitmapStoneBlack, NULL );
StatusBarWeiqi->Panels->Items[0]->Text = "Order: " + IntToStr( WeiqiBoard->Order );
StatusBarWeiqi->Panels->Items[4]->Text = "White to move...";
DrawStone( WhichSide, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
WhichSide = wqSideWhite;
}
else if( WhichSide == wqSideWhite )
{
WeiqiBoard->InsertStone( WhichSide, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
ImageListStones->Add( BitmapStoneWhite, NULL );
ImageListStonesLived->Add( BitmapStoneWhite, NULL );
StatusBarWeiqi->Panels->Items[0]->Text = "Order: " + IntToStr( WeiqiBoard->Order );
StatusBarWeiqi->Panels->Items[4]->Text = "Black to move...";
DrawStone( WhichSide, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
WhichSide = wqSideBlack; // The oppenent is going.
}
// bTurn == false;
}
}
}
else // GameType == gtWatch
{
Application->MessageBox("观棋不语!", "严正警告", MB_OK );
return;
}
/* div_t nDiv1, nDiv2;
int nX, nY;
bool bX = false, bY = false;
// Determine whether the mouse is near a point.
if( ( MousePoint.x <= 500 ) & ( MousePoint.x >= 0 ) &
( MousePoint.y <= 500 ) & ( MousePoint.y >= 0 ) )
{
nDiv1 = div( MousePoint.x, 25 );
if( nDiv1.rem <= 5 )
{
nX = nDiv1.quot;
bX = true;
}
else if( nDiv1.rem >= 20 )
{
nX = nDiv1.quot + 1;
bX = true;
}
nDiv2 = div( MousePoint.y, 25 );
if( nDiv2.rem <= 5 )
{
nY = nDiv2.quot;
bY = true;
}
else if( nDiv2.rem >= 20 )
{
nY = nDiv2.quot + 1;
bY = true;
}
*/
/* if( bTurn & bX & bY )
{
// bTurn == false;
if( WhichSide == wqSideBlack )
{
WeiqiBoard->Order = ImageListStones->Add( StoneBlack, NULL );
WhichSide = wqSideWhite;
// WeiqiBoard->InsertStone( WhichSide, nX, nY );
}
else if( WhichSide == wqSideWhite )
{
WeiqiBoard->Order = ImageListStones->Add( StoneWhite, NULL );
WhichSide = wqSideBlack;
// WeiqiBoard->InsertStone( WhichSide, nX, nY );
}
// ShowMessage( WeiqiBoard->Order );
if( WeiqiBoard->Phase[nX][nY] == wqSideNone )
{
bTurn == false;
WeiqiBoard->InsertStone( WhichSide, nX, nY );
DrawStone( wqSideBlack, nX, nY );
ShowStonePosition( wqSideBlack, nX, nY );
}
}
else if( !bTurn )
{
// bTurn == true;
// if( WhichSide == wqSideBlack )
// WeiqiBoard->Order = ImageListStones->Add( StoneBlack, NULL ) + 1;
// else if( WhichSide == wqSideWhite )
// WeiqiBoard->Order = ImageListStones->Add( StoneWhite, NULL ) + 1;
// ShowMessage( WeiqiBoard->Order );
// DrawStone( wqSideWhite, nX, nY );
ShowMessage( "You lose! No one can go twice at one time." );
}
#if defined( __DEBUG__ )
if( WeiqiBoard->Phase[X][Y] == wqSideBlack )
ShowMessage( 1 );
#endif
}
*/
}
//---------------------------------------------------------------------------
void __fastcall TMainFormWeiqi::ImageFrontierMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
MousePoint.x = X;
MousePoint.y = Y;
}
//---------------------------------------------------------------------------
void __fastcall TMainFormWeiqi::EditGoKeyPress(TObject *Sender, char &Key)
{
if( Key == 13 ) // Enter pressed
{
GetStoneCoordination();
if( GameType == gtPlay )
{
if( bTurn )
{
if( StonePlaceToGoTo.bX & StonePlaceToGoTo.bY )
{
// ShowMessage( WeiqiBoard->Order );
if( WeiqiBoard->Phase[ StonePlaceToGoTo.nX ][ StonePlaceToGoTo.nY ] == wqSideNone )
{
// SetStoneCoordination( WhichSide, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
if( WhichSide == wqSideBlack )
{
ImageListStones->Add( BitmapStoneBlack, NULL );
ImageListStonesLived->Add( BitmapStoneBlack, NULL );
}
else if( WhichSide == wqSideWhite )
{
ImageListStones->Add( BitmapStoneWhite, NULL );
ImageListStonesLived->Add( BitmapStoneWhite, NULL );
}
WeiqiBoard->InsertStone( WhichSide, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
StatusBarWeiqi->Panels->Items[0]->Text = "Order: " + IntToStr( WeiqiBoard->Order );
StatusBarWeiqi->Panels->Items[4]->Text = "Black to move...";
DrawStone( WhichSide, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
}
}
bTurn = false;
}
else // GamePlay == gtPlay; It's the oppenent's go.
{
if( StonePlaceToGoTo.bX & StonePlaceToGoTo.bY )
{
// ShowMessage( WeiqiBoard->Order );
if( WeiqiBoard->Phase[ StonePlaceToGoTo.nX ][ StonePlaceToGoTo.nY ] == wqSideNone )
{
if( WhichSide == wqSideBlack )
{
// SetStoneCoordination( wqSideWhite, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
WeiqiBoard->InsertStone( wqSideWhite, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
ImageListStones->Add( BitmapStoneWhite, NULL );
ImageListStonesLived->Add( BitmapStoneWhite, NULL );
StatusBarWeiqi->Panels->Items[0]->Text = "Order: " + IntToStr( WeiqiBoard->Order );
StatusBarWeiqi->Panels->Items[4]->Text = "White to move...";
DrawStone( wqSideWhite, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
}
else if( WhichSide == wqSideWhite )
{
// SetStoneCoordination( wqSideBlack, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
WeiqiBoard->InsertStone( wqSideBlack, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
ImageListStones->Add( BitmapStoneBlack, NULL );
ImageListStonesLived->Add( BitmapStoneBlack, NULL );
StatusBarWeiqi->Panels->Items[0]->Text = "Order: " + IntToStr( WeiqiBoard->Order );
StatusBarWeiqi->Panels->Items[4]->Text = "Black to move...";
DrawStone( wqSideBlack, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
}
}
}
bTurn = true;
}
}
else if( GameType == gtLearn )
{
// Record the place to go to in Weiqi->Board, and show it in the main form.
if( StonePlaceToGoTo.bX & StonePlaceToGoTo.bY )
{
// ShowMessage( WeiqiBoard->Order );
if( WeiqiBoard->Phase[ StonePlaceToGoTo.nX ][ StonePlaceToGoTo.nY ] == wqSideNone )
{
// SetStoneCoordination( WhichSide, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
if( WhichSide == wqSideBlack )
{
ImageListStones->Add( BitmapStoneBlack, NULL );
ImageListStonesLived->Add( BitmapStoneBlack, NULL );
StatusBarWeiqi->Panels->Items[0]->Text = "Order: " + IntToStr( WeiqiBoard->Order );
StatusBarWeiqi->Panels->Items[4]->Text = "White to move...";
WeiqiBoard->InsertStone( WhichSide, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
DrawStone( WhichSide, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
WhichSide = wqSideWhite;
}
else if( WhichSide == wqSideWhite )
{
WeiqiBoard->InsertStone( WhichSide, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
ImageListStones->Add( BitmapStoneWhite, NULL );
ImageListStonesLived->Add( BitmapStoneWhite, NULL );
StatusBarWeiqi->Panels->Items[0]->Text = "Order: " + IntToStr( WeiqiBoard->Order );
StatusBarWeiqi->Panels->Items[4]->Text = "Black to move...";
DrawStone( WhichSide, StonePlaceToGoTo.nX, StonePlaceToGoTo.nY );
WhichSide = wqSideBlack;
}
// bTurn == false;
}
}
}
else // GameType == gtWatch
{
Application->MessageBox("观棋不语!", "严正警告", MB_OK );
return;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TMainFormWeiqi::FormActivate(TObject *Sender)
{
if( EditGo->Focused() )
EditGo->SelectAll();
}
//---------------------------------------------------------------------------
bool __fastcall TMainFormWeiqi::RedrawFrontier( int order, int X, int Y )
{
int nX, nY;
if( GetDeletedStonePlace( X, Y ) == spNormal )
ImageListStones->Replace( order, BitmapNormalCross, NULL );
else if( GetDeletedStonePlace( X, Y ) == spStar )
ImageListStones->Replace( order, BitmapStarCross, NULL );
else if( GetDeletedStonePlace( X, Y ) == spTop )
ImageListStones->Replace( order, BitmapTopCross, NULL );
else if( GetDeletedStonePlace( X, Y ) == spBottom )
ImageListStones->Replace( order, BitmapBottomCross, NULL );
else if( GetDeletedStonePlace( X, Y ) == spLeft )
ImageListStones->Replace( order, BitmapLeftCross, NULL );
else if( GetDeletedStonePlace( X, Y ) == spRight )
ImageListStones->Replace( order, BitmapRightCross, NULL );
else if( GetDeletedStonePlace( X, Y ) == spLeftTop )
ImageListStones->Replace( order, BitmapLeftTopCross, NULL );
else if( GetDeletedStonePlace( X, Y ) == spLeftBottom )
ImageListStones->Replace( order, BitmapLeftBottomCross, NULL );
else if( GetDeletedStonePlace( X, Y ) == spRightTop )
ImageListStones->Replace( order, BitmapRightTopCross, NULL );
else if( GetDeletedStonePlace( X, Y ) == spRightBottom )
ImageListStones->Replace( order, BitmapRightBottomCross, NULL );
nX = 25 * X - 12;
nY = 25 * Y - 12;
ImageListStones->Draw( MainFormWeiqi->Canvas, nX, nY, order );
AnsiString asBlack, asWhite;
if( WeiqiBoard->BlackDeadStones <= 9 )
asBlack = AnsiString( " " ) + AnsiString( WeiqiBoard->BlackDeadStones );
else
asBlack = AnsiString( WeiqiBoard->BlackDeadStones );
if( WeiqiBoard->WhiteDeadStones <= 9 )
asWhite = AnsiString( " " ) + AnsiString( WeiqiBoard->WhiteDeadStones );
else
asWhite = AnsiString( WeiqiBoard->WhiteDeadStones );
StatusBarWeiqi->Panels->Items[3]->Text
= "Dead Stones: Black " + asBlack + ", White " + asWhite;
return( true );
}
//---------------------------------------------------------------------------
TStonePlace __fastcall TMainFormWeiqi::GetDeletedStonePlace( int X, int Y )
{
if( ( ( X == 4 ) && ( Y == 4 ) ) || ( ( X == 4 ) && ( Y == 10 ) ) ||
( ( X == 4 ) && ( Y == 16 ) ) || ( ( X == 10 ) && ( Y == 4 ) ) ||
( ( X == 10 ) && ( Y == 10 ) ) || ( ( X == 10 ) && ( Y == 16 ) ) ||
( ( X == 16 ) && ( Y == 4 ) ) || ( ( X == 16 ) && ( Y == 10 ) ) ||
( ( X == 16 ) && ( Y == 16 ) ) )
return( spStar );
else if( ( Y == 1 ) && ( X < 19 ) && ( X > 1 ) )
return( spTop );
else if( ( Y == 19 ) && ( X < 19 ) && ( X > 1 ) )
return( spBottom );
else if( ( X == 1 ) && ( Y < 19 ) && ( Y > 1 ) )
return( spLeft );
else if( ( X == 19 ) && ( Y < 19 ) && ( Y > 1 ) )
return( spRight );
else if( ( X == 1 ) && ( Y == 1 ) )
return( spLeftTop );
else if( ( X == 1 ) && ( Y == 19 ) )
return( spLeftBottom );
else if( ( X == 19 ) && ( Y == 1 ) )
return( spRightTop );
else if( ( X == 19 ) && ( Y == 19 ) )
return( spRightBottom );
else
return( spNormal );
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -