//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#if !defined( globalH )
#include "global.h"
#endif
#include <stdlib.h>
#include "weiqiply.h"
#if !defined( weiqibrdH )
#include "weiqibrd.h"
#endif
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainFormWeiqi *MainFormWeiqi;
extern TWeiqiBoard *WeiqiBoard;
//---------------------------------------------------------------------------
__fastcall TMainFormWeiqi::TMainFormWeiqi(TComponent* Owner)
: TForm(Owner)
{
bTurn = true;
GameType = gtLearn;
WhichSide = wqSideBlack;
BitmapNormalCross = new( Graphics::TBitmap );
BitmapNormalCross->LoadFromFile( "nrmlcrs.bmp" );
BitmapStarCross = new( Graphics::TBitmap );
BitmapStarCross->LoadFromFile( "starcrs.bmp" );
BitmapTopCross = new( Graphics::TBitmap );
BitmapTopCross->LoadFromFile( "topcrs.bmp" );
BitmapBottomCross = new( Graphics::TBitmap );
BitmapBottomCross->LoadFromFile( "btmcrs.bmp" );
BitmapLeftCross = new( Graphics::TBitmap );
BitmapLeftCross->LoadFromFile( "leftcrs.bmp" );
BitmapRightCross = new( Graphics::TBitmap );
BitmapRightCross->LoadFromFile( "rightcrs.bmp" );
BitmapLeftTopCross = new( Graphics::TBitmap );
BitmapLeftTopCross->LoadFromFile( "lefttop.bmp" );
BitmapRightTopCross = new( Graphics::TBitmap );
BitmapRightTopCross->LoadFromFile( "righttop.bmp" );
BitmapLeftBottomCross = new( Graphics::TBitmap );
BitmapLeftBottomCross->LoadFromFile( "leftbtm.bmp" );
BitmapRightBottomCross = new( Graphics::TBitmap );
BitmapRightBottomCross->LoadFromFile( "rightbtm.bmp" );
BitmapStoneBlack = new( Graphics::TBitmap );
BitmapStoneBlack->LoadFromFile( "blkstone.bmp" );
BitmapStoneWhite = new( Graphics::TBitmap );
BitmapStoneWhite->LoadFromFile( "whtstone.bmp" );
BitmapStoneNewBlack = new( Graphics::TBitmap );
BitmapStoneNewBlack->LoadFromFile( "nwblkstn.bmp" );
BitmapStoneNewWhite = new( Graphics::TBitmap );
BitmapStoneNewWhite->LoadFromFile( "nwwhtstn.bmp" );
WeiqiBoard->Order = ImageListStones->Add( BitmapNormalCross, NULL );
ImageListStonesLived->Add( BitmapNormalCross, NULL );
}
//---------------------------------------------------------------------------
void __fastcall TMainFormWeiqi::MenuConnectionExitClick(TObject *Sender)
{
Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TMainFormWeiqi::BitBtnExitClick(TObject *Sender)
{
Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TMainFormWeiqi::FormCreate(TObject *Sender)
{
RectFrontier = ImageFrontier->ClientRect;
AnsiString asStartTime;
asStartTime = AnsiString( "Start Time: " )
+ AnsiString( WeiqiBoard->StartTime.wHour ) + AnsiString( ":" )
+ AnsiString( WeiqiBoard->StartTime.wMinute ) + AnsiString( "'" )
+ AnsiString( WeiqiBoard->StartTime.wSecond ) + AnsiString( "''" );
StatusBarWeiqi->Panels->Items[1]->Text = asStartTime;
StatusBarWeiqi->Panels->Items[3]->Text = "Dead Stones: Black 0, White 0";
StatusBarWeiqi->Panels->Items[4]->Text = "New game...";
#if defined( __DEBUG__ )
// ShowMessage(CurrRect.Left);
// ShowMessage(CurrRect.Right);
// ShowMessage(CurrRect.Top);
// ShowMessage(CurrRect.Bottom);
#endif
if( EditGo->Focused() )
EditGo->SelectAll();
}
//---------------------------------------------------------------------------
bool __fastcall TMainFormWeiqi::GetPlaceToGoTo()
{
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 )
{
StonePlaceToGoTo.nX = nDiv1.quot;
StonePlaceToGoTo.bX = true;
}
else if( nDiv1.rem >= 20 )
{
StonePlaceToGoTo.nX = nDiv1.quot + 1;
StonePlaceToGoTo.bX = true;
}
nDiv2 = div( MousePoint.y, 25 );
if( nDiv2.rem <= 5 )
{
StonePlaceToGoTo.nY = nDiv2.quot;
StonePlaceToGoTo.bY = true;
}
else if( nDiv2.rem >= 20 )
{
StonePlaceToGoTo.nY = nDiv2.quot + 1;
StonePlaceToGoTo.bY = true;
}
}
}
//---------------------------------------------------------------------------
bool __fastcall TMainFormWeiqi::ReceivePlaceToGoTo()
{
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 )
{
StonePlaceToGoTo.nX = nDiv1.quot;
StonePlaceToGoTo.bX = true;
}
else if( nDiv1.rem >= 20 )
{
StonePlaceToGoTo.nX = nDiv1.quot + 1;
StonePlaceToGoTo.bX = true;
}
nDiv2 = div( MousePoint.y, 25 );
if( nDiv2.rem <= 5 )
{
StonePlaceToGoTo.nY = nDiv2.quot;
StonePlaceToGoTo.bY = true;
}
else if( nDiv2.rem >= 20 )
{
StonePlaceToGoTo.nY = nDiv2.quot + 1;
StonePlaceToGoTo.bY = true;
}
}
}
//---------------------------------------------------------------------------
bool __fastcall TMainFormWeiqi::DrawStone( TWhichSide WhichSide, int X, int Y )
{
POINT t;
t.x = 25 * X - 12;
t.y = 25 * Y - 12;
int nIndex = WeiqiBoard->Order;
ImageListStones->Draw( MainFormWeiqi->Canvas, t.x, t.y, nIndex );
/* if( GameType == gtPlay )
{
if( bTurn )
{
if( WhichSide == wqSideBlack )
{
ImageListStones->Draw( MainFormWeiqi->Canvas, t.x, t.y, nIndex );
}
else if( WhichSide = wqSideWhite )
{
ImageListStones->Draw( ImageFrontier->Canvas, t.x, t.y, nIndex );
}
}
else // The oppenent has just done.
{
if( WhichSide == wqSideBlack )
{
ImageListStones->Draw( MainFormWeiqi->Canvas, t.x, t.y, nIndex );
}
else if( WhichSide = wqSideWhite )
{
ImageListStones->Draw( ImageFrontier->Canvas, t.x, t.y, nIndex );
}
}
return( true );
}
else if( GameType == gtLearn )
{
if( WhichSide == wqSideBlack )
{
ImageListStones->Draw( MainFormWeiqi->Canvas, t.x, t.y, nIndex );
}
else if( WhichSide = wqSideWhite )
{
ImageListStones->Draw( ImageFrontier->Canvas, t.x, t.y, nIndex );
}
return( true );
}
else
{
// Application->MessageBox("观棋不语!", "严正警告", MB_OK );
return( false );
}
*/
}
//---------------------------------------------------------------------------
bool __fastcall TMainFormWeiqi::SetStoneCoordination( TWhichSide WhichSide, int X, int Y )
{
AnsiString as;
switch( Y )
{
case 1: as = AnsiString("A"); break;
case 2: as = AnsiString("B"); break;
case 3: as = AnsiString("C"); break;
case 4: as = AnsiString("D"); break;
case 5: as = AnsiString("E"); break;
case 6: as = AnsiString("F"); break;
case 7: as = AnsiString("G"); break;
case 8: as = AnsiString("H"); break;
case 9: as = AnsiString("I"); break;
case 10: as = AnsiString("J"); break;
case 11: as = AnsiString("K"); break;
case 12: as = AnsiString("L"); break;
case 13: as = AnsiString("M"); break;
case 14: as = AnsiString("N"); break;
case 15: as = AnsiString("O"); break;
case 16: as = AnsiString("P"); break;
case 17: as = AnsiString("Q"); break;
case 18: as = AnsiString("R"); break;
case 19: as = AnsiString("S"); break;
default: as = AnsiString("");
}
as += AnsiString( X );
EditGo->Text =