2010-09-21 06:33:18 +00:00
|
|
|
unit mainform;
|
2010-09-16 11:52:47 +00:00
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2010-09-23 10:43:52 +00:00
|
|
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
|
2010-09-23 15:40:21 +00:00
|
|
|
ExtCtrls, ComCtrls, StdCtrls, Buttons, Spin,
|
2010-09-21 06:33:18 +00:00
|
|
|
//
|
2010-10-06 13:34:34 +00:00
|
|
|
chessdrawer, chessgame, chessconfig, chesstcputils;
|
2010-09-16 11:52:47 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
|
2010-09-23 10:43:52 +00:00
|
|
|
{ TFormDrawerDelegate }
|
|
|
|
|
|
|
|
TFormDrawerDelegate = class(TChessDrawerDelegate)
|
|
|
|
public
|
|
|
|
procedure HandleMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); override;
|
|
|
|
procedure HandleMouseUp(Sender: TObject; Button: TMouseButton;
|
|
|
|
Shift: TShiftState; X, Y: Integer); override;
|
|
|
|
procedure HandleMouseDown(Sender: TObject; Button: TMouseButton;
|
|
|
|
Shift: TShiftState; X, Y: Integer); override;
|
|
|
|
end;
|
|
|
|
|
2010-09-21 06:33:18 +00:00
|
|
|
{ TformChess }
|
2010-09-16 11:52:47 +00:00
|
|
|
|
2010-09-21 06:33:18 +00:00
|
|
|
TformChess = class(TForm)
|
2010-09-16 11:52:47 +00:00
|
|
|
BitBtn1: TBitBtn;
|
|
|
|
btnSinglePlayer: TBitBtn;
|
2010-09-21 06:33:18 +00:00
|
|
|
btnDirectComm: TBitBtn;
|
2010-09-16 11:52:47 +00:00
|
|
|
BitBtn3: TBitBtn;
|
2010-09-23 15:40:21 +00:00
|
|
|
btnHotSeat: TBitBtn;
|
|
|
|
checkTimer: TCheckBox;
|
2010-09-21 06:33:18 +00:00
|
|
|
comboStartColor: TComboBox;
|
2010-09-16 11:52:47 +00:00
|
|
|
Label1: TLabel;
|
|
|
|
Label2: TLabel;
|
|
|
|
Label3: TLabel;
|
|
|
|
Label4: TLabel;
|
2010-09-21 06:33:18 +00:00
|
|
|
Label5: TLabel;
|
|
|
|
Label6: TLabel;
|
2010-09-23 15:40:21 +00:00
|
|
|
Label7: TLabel;
|
2010-09-23 10:43:52 +00:00
|
|
|
labelPos: TLabel;
|
2010-10-05 20:05:41 +00:00
|
|
|
editRemoteID: TLabeledEdit;
|
|
|
|
editLocalIP: TLabeledEdit;
|
2010-09-21 06:33:18 +00:00
|
|
|
editPlayerName: TLabeledEdit;
|
2010-09-16 11:52:47 +00:00
|
|
|
pageStart: TUNBPage;
|
|
|
|
pageConfigConnection: TUNBPage;
|
|
|
|
notebookMain: TUntabbedNotebook;
|
|
|
|
pageConnecting: TUNBPage;
|
|
|
|
ProgressBar1: TProgressBar;
|
2010-09-21 06:33:18 +00:00
|
|
|
pageGame: TUNBPage;
|
2010-09-23 15:40:21 +00:00
|
|
|
spinPlayerTime: TSpinEdit;
|
|
|
|
timerChessTimer: TTimer;
|
2010-09-21 06:33:18 +00:00
|
|
|
procedure FormCreate(Sender: TObject);
|
2010-09-16 11:52:47 +00:00
|
|
|
procedure HandleMainScreenButton(Sender: TObject);
|
2010-10-06 13:34:34 +00:00
|
|
|
procedure pageBeforeShow(Sender: TObject; ANewPage: TUNBPage; ANewIndex: Integer);
|
2010-09-23 15:40:21 +00:00
|
|
|
procedure timerChessTimerTimer(Sender: TObject);
|
2010-09-16 11:52:47 +00:00
|
|
|
private
|
|
|
|
{ private declarations }
|
|
|
|
public
|
|
|
|
{ public declarations }
|
2010-09-23 10:43:52 +00:00
|
|
|
procedure UpdateCaptions;
|
2010-09-16 11:52:47 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
2010-09-21 06:33:18 +00:00
|
|
|
formChess: TformChess;
|
2010-09-23 10:43:52 +00:00
|
|
|
vFormDrawerDelegate: TFormDrawerDelegate;
|
2010-09-16 11:52:47 +00:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{$R *.lfm}
|
|
|
|
|
2010-10-06 13:34:34 +00:00
|
|
|
const
|
|
|
|
INT_PAGE_START = 0;
|
|
|
|
INT_PAGE_CONFIGCONNECTION = 1;
|
|
|
|
INT_PAGE_CONNECTING = 2;
|
|
|
|
INT_PAGE_GAME = 3;
|
|
|
|
|
2010-09-21 06:33:18 +00:00
|
|
|
{ TformChess }
|
2010-09-16 11:52:47 +00:00
|
|
|
|
2010-09-21 06:33:18 +00:00
|
|
|
procedure TformChess.HandleMainScreenButton(Sender: TObject);
|
2010-09-16 11:52:47 +00:00
|
|
|
begin
|
|
|
|
if Sender = btnSinglePlayer then
|
|
|
|
begin
|
2010-10-06 13:34:34 +00:00
|
|
|
notebookMain.PageIndex := INT_PAGE_GAME;
|
2010-09-23 15:40:21 +00:00
|
|
|
vChessGame.StartNewGame(comboStartColor.ItemIndex, checkTimer.Checked, spinPlayerTime.Value);
|
|
|
|
end
|
|
|
|
else if Sender = btnHotSeat then
|
|
|
|
begin
|
2010-10-06 13:34:34 +00:00
|
|
|
notebookMain.PageIndex := INT_PAGE_GAME;
|
2010-09-23 15:40:21 +00:00
|
|
|
vChessGame.StartNewGame(comboStartColor.ItemIndex, checkTimer.Checked, spinPlayerTime.Value);
|
2010-09-21 06:33:18 +00:00
|
|
|
end
|
2010-10-06 13:34:34 +00:00
|
|
|
else if Sender = btnDirectComm then notebookMain.PageIndex := INT_PAGE_CONFIGCONNECTION;
|
2010-09-21 06:33:18 +00:00
|
|
|
end;
|
|
|
|
|
2010-10-06 13:34:34 +00:00
|
|
|
procedure TformChess.pageBeforeShow(Sender: TObject; ANewPage: TUNBPage; ANewIndex: Integer);
|
2010-10-05 20:05:41 +00:00
|
|
|
begin
|
2010-10-06 13:34:34 +00:00
|
|
|
if ANewIndex = INT_PAGE_CONFIGCONNECTION then
|
2010-10-05 20:05:41 +00:00
|
|
|
begin
|
2010-10-06 13:34:34 +00:00
|
|
|
editLocalIP.Text := ChessGetLocalIP();
|
2010-10-05 20:05:41 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-09-23 15:40:21 +00:00
|
|
|
procedure TformChess.timerChessTimerTimer(Sender: TObject);
|
|
|
|
begin
|
|
|
|
vChessGame.UpdateTimes();
|
|
|
|
UpdateCaptions();
|
|
|
|
end;
|
|
|
|
|
2010-09-23 10:43:52 +00:00
|
|
|
procedure TformChess.UpdateCaptions;
|
|
|
|
var
|
2010-09-23 15:40:21 +00:00
|
|
|
lStr: string;
|
2010-09-23 10:43:52 +00:00
|
|
|
begin
|
2010-09-23 15:40:21 +00:00
|
|
|
if vChessGame.CurrentPlayerIsWhite then lStr := 'White playing'
|
|
|
|
else lStr := 'Black playing';
|
2010-09-23 10:43:52 +00:00
|
|
|
|
2010-09-23 15:40:21 +00:00
|
|
|
lStr := lStr + Format(' X: %d Y: %d',
|
2010-09-23 10:43:52 +00:00
|
|
|
[vChessGame.MouseMovePos.X, vChessGame.MouseMovePos.Y]);
|
2010-09-23 15:40:21 +00:00
|
|
|
|
|
|
|
lStr := lStr + Format(' White time: %d Black time: %d',
|
|
|
|
[vChessGame.WhitePlayerTime, vChessGame.BlackPlayerTime]);
|
|
|
|
|
|
|
|
formChess.labelPos.Caption := lStr;
|
2010-09-23 10:43:52 +00:00
|
|
|
end;
|
|
|
|
|
2010-09-21 06:33:18 +00:00
|
|
|
procedure TformChess.FormCreate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
// Creation of internal components
|
|
|
|
vChessDrawer := TChessDrawer.Create(Self);
|
|
|
|
vChessDrawer.Parent := pageGame;
|
2010-09-22 15:45:23 +00:00
|
|
|
vChessDrawer.Top := 50;
|
2010-09-21 06:33:18 +00:00
|
|
|
vChessDrawer.Left := 20;
|
|
|
|
vChessDrawer.Height := INT_CHESSBOARD_SIZE;
|
|
|
|
vChessDrawer.Width := INT_CHESSBOARD_SIZE;
|
2010-09-23 10:43:52 +00:00
|
|
|
vChessDrawer.SetDelegate(vFormDrawerDelegate);
|
2010-09-21 06:33:18 +00:00
|
|
|
|
|
|
|
// Loading of resources
|
|
|
|
vChessDrawer.LoadImages();
|
2010-09-16 11:52:47 +00:00
|
|
|
end;
|
|
|
|
|
2010-09-23 10:43:52 +00:00
|
|
|
{ TFormDrawerDelegate }
|
|
|
|
|
|
|
|
procedure TFormDrawerDelegate.HandleMouseMove(Sender: TObject;
|
|
|
|
Shift: TShiftState; X, Y: Integer);
|
|
|
|
begin
|
|
|
|
vChessGame.MouseMovePos := vChessGame.ClientToBoardCoords(Point(X, Y));
|
|
|
|
formChess.UpdateCaptions;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TFormDrawerDelegate.HandleMouseUp(Sender: TObject;
|
|
|
|
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
|
|
|
var
|
|
|
|
lCoords: TPoint;
|
|
|
|
begin
|
|
|
|
vChessGame.Dragging := False;
|
|
|
|
|
|
|
|
lCoords := vChessGame.ClientToBoardCoords(Point(X, Y));
|
|
|
|
if not vChessGame.MovePiece(vChessGame.DragStart, lCoords) then Exit;
|
|
|
|
|
|
|
|
vChessDrawer.Invalidate;
|
|
|
|
formChess.UpdateCaptions;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TFormDrawerDelegate.HandleMouseDown(Sender: TObject;
|
|
|
|
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
|
|
|
var
|
|
|
|
lCoords: TPoint;
|
|
|
|
begin
|
|
|
|
lCoords := vChessGame.ClientToBoardCoords(Point(X, Y));
|
|
|
|
if not vChessGame.CheckStartMove(lCoords) then Exit;
|
|
|
|
|
|
|
|
vChessGame.Dragging := True;
|
|
|
|
vChessGame.DragStart := lCoords;
|
|
|
|
vChessDrawer.Invalidate;
|
|
|
|
formChess.UpdateCaptions;
|
|
|
|
end;
|
|
|
|
|
|
|
|
initialization
|
|
|
|
|
|
|
|
vFormDrawerDelegate := TFormDrawerDelegate.Create;
|
|
|
|
|
|
|
|
finalization
|
|
|
|
|
|
|
|
vFormDrawerDelegate.Free;
|
|
|
|
|
2010-09-16 11:52:47 +00:00
|
|
|
end.
|
|
|
|
|