fpchess is now playable in hotseat mode

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1327 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat
2010-09-23 15:40:21 +00:00
parent 5898609891
commit 7fad6b83aa
4 changed files with 192 additions and 97 deletions

View File

@ -5,7 +5,7 @@ unit chessgame;
interface interface
uses uses
Classes, SysUtils, fpimage; Classes, SysUtils, fpimage, dateutils;
const const
colA = 1; colA = 1;
@ -50,11 +50,17 @@ type
CurrentPlayerIsWhite: Boolean; CurrentPlayerIsWhite: Boolean;
Dragging: Boolean; Dragging: Boolean;
DragStart, MouseMovePos: TPoint; DragStart, MouseMovePos: TPoint;
procedure StartNewGame(APlayAsWhite: Boolean); overload; UseTimer: Boolean;
procedure StartNewGame(APlayAsWhite: Integer); overload; WhitePlayerTime: Integer; // milisseconds
BlackPlayerTime: Integer; // milisseconds
MoveStartTime: TDateTime;
constructor Create;
procedure StartNewGame(APlayAsWhite: Boolean; AUseTimer: Boolean; APlayerTime: Integer); overload;
procedure StartNewGame(APlayAsWhite: Integer; AUseTimer: Boolean; APlayerTime: Integer); overload;
function ClientToBoardCoords(AClientCoords: TPoint): TPoint; function ClientToBoardCoords(AClientCoords: TPoint): TPoint;
function CheckStartMove(AFrom: TPoint): Boolean; function CheckStartMove(AFrom: TPoint): Boolean;
function MovePiece(AFrom, ATo: TPoint): Boolean; function MovePiece(AFrom, ATo: TPoint): Boolean;
procedure UpdateTimes();
end; end;
var var
@ -64,13 +70,24 @@ implementation
{ TChessGame } { TChessGame }
procedure TChessGame.StartNewGame(APlayAsWhite: Boolean); constructor TChessGame.Create;
begin
inherited Create;
end;
procedure TChessGame.StartNewGame(APlayAsWhite: Boolean; AUseTimer: Boolean; APlayerTime: Integer);
var var
lWPawnRow, lWMainRow, lBPawnRow, lBMainRow: Byte; lWPawnRow, lWMainRow, lBPawnRow, lBMainRow: Byte;
i: Integer; i: Integer;
j: Integer; j: Integer;
begin begin
UseTimer := AUseTimer;
CurrentPlayerIsWhite := True; CurrentPlayerIsWhite := True;
WhitePlayerTime := APlayerTime * 60 * 1000; // minutes to milisseconds
BlackPlayerTime := APlayerTime * 60 * 1000; // minutes to milisseconds
MoveStartTime := Now;
// //
if APlayAsWhite then if APlayAsWhite then
@ -122,9 +139,9 @@ begin
Board[8][lBMainRow] := ctBRook; Board[8][lBMainRow] := ctBRook;
end; end;
procedure TChessGame.StartNewGame(APlayAsWhite: Integer); procedure TChessGame.StartNewGame(APlayAsWhite: Integer; AUseTimer: Boolean; APlayerTime: Integer);
begin begin
StartNewGame(APlayAsWhite = 0); StartNewGame(APlayAsWhite = 0, AUseTimer, APlayerTime);
end; end;
{ {
@ -144,11 +161,26 @@ begin
Board[ATo.X][ATo.Y] := Board[AFrom.X][AFrom.Y]; Board[ATo.X][ATo.Y] := Board[AFrom.X][AFrom.Y];
Board[AFrom.X][AFrom.Y] := ctEmpty; Board[AFrom.X][AFrom.Y] := ctEmpty;
UpdateTimes();
CurrentPlayerIsWhite := not CurrentPlayerIsWhite; CurrentPlayerIsWhite := not CurrentPlayerIsWhite;
Result := True; Result := True;
end; end;
procedure TChessGame.UpdateTimes();
var
lNow: TDateTime;
lTimeDelta: Integer;
begin
lNow := Now;
lTimeDelta := MilliSecondsBetween(lNow, MoveStartTime);
MoveStartTime := lNow;
if CurrentPlayerIsWhite then WhitePlayerTime := WhitePlayerTime - lTimeDelta
else BlackPlayerTime := BlackPlayerTime - lTimeDelta;
end;
function TChessGame.ClientToBoardCoords(AClientCoords: TPoint): TPoint; function TChessGame.ClientToBoardCoords(AClientCoords: TPoint): TPoint;
begin begin
Result.X := 1 + AClientCoords.X div INT_CHESSTILE_SIZE; Result.X := 1 + AClientCoords.X div INT_CHESSTILE_SIZE;

View File

@ -36,7 +36,7 @@
<Filename Value="fpchess.lpr"/> <Filename Value="fpchess.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="fpchess"/> <UnitName Value="fpchess"/>
<UsageCount Value="37"/> <UsageCount Value="38"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
@ -44,11 +44,12 @@
<ComponentName Value="formChess"/> <ComponentName Value="formChess"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="mainform"/> <UnitName Value="mainform"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="0"/> <EditorIndex Value="0"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="108"/> <TopLine Value="92"/>
<CursorPos X="26" Y="122"/> <CursorPos X="61" Y="104"/>
<UsageCount Value="37"/> <UsageCount Value="38"/>
<Loaded Value="True"/> <Loaded Value="True"/>
<LoadedDesigner Value="True"/> <LoadedDesigner Value="True"/>
</Unit1> </Unit1>
@ -127,7 +128,7 @@
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="305"/> <TopLine Value="305"/>
<CursorPos X="61" Y="320"/> <CursorPos X="61" Y="320"/>
<UsageCount Value="18"/> <UsageCount Value="19"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit11> </Unit11>
<Unit12> <Unit12>
@ -165,9 +166,9 @@
<UnitName Value="chessdrawer"/> <UnitName Value="chessdrawer"/>
<EditorIndex Value="3"/> <EditorIndex Value="3"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="17"/> <TopLine Value="1"/>
<CursorPos X="3" Y="25"/> <CursorPos X="3" Y="25"/>
<UsageCount Value="35"/> <UsageCount Value="36"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit16> </Unit16>
<Unit17> <Unit17>
@ -221,12 +222,11 @@
<Filename Value="chessgame.pas"/> <Filename Value="chessgame.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="chessgame"/> <UnitName Value="chessgame"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="1"/> <EditorIndex Value="1"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="130"/> <TopLine Value="1"/>
<CursorPos X="42" Y="137"/> <CursorPos X="40" Y="8"/>
<UsageCount Value="27"/> <UsageCount Value="28"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit23> </Unit23>
<Unit24> <Unit24>
@ -237,7 +237,7 @@
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="18"/> <TopLine Value="18"/>
<CursorPos X="13" Y="39"/> <CursorPos X="13" Y="39"/>
<UsageCount Value="27"/> <UsageCount Value="28"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit24> </Unit24>
<Unit25> <Unit25>
@ -290,124 +290,124 @@
</Units> </Units>
<JumpHistory Count="30" HistoryIndex="29"> <JumpHistory Count="30" HistoryIndex="29">
<Position1> <Position1>
<Filename Value="chessdrawer.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="237" Column="8" TopLine="212"/> <Caret Line="112" Column="1" TopLine="103"/>
</Position1> </Position1>
<Position2> <Position2>
<Filename Value="..\..\..\lazarussvn\lcl\controls.pp"/> <Filename Value="mainform.pas"/>
<Caret Line="1232" Column="30" TopLine="1218"/> <Caret Line="122" Column="1" TopLine="103"/>
</Position2> </Position2>
<Position3> <Position3>
<Filename Value="chessdrawer.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="238" Column="44" TopLine="212"/> <Caret Line="123" Column="1" TopLine="103"/>
</Position3> </Position3>
<Position4> <Position4>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="21" Column="71" TopLine="5"/> <Caret Line="121" Column="43" TopLine="104"/>
</Position4> </Position4>
<Position5> <Position5>
<Filename Value="chessgame.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="49" Column="40" TopLine="34"/> <Caret Line="123" Column="1" TopLine="104"/>
</Position5> </Position5>
<Position6> <Position6>
<Filename Value="chessgame.pas"/> <Filename Value="chessgame.pas"/>
<Caret Line="151" Column="1" TopLine="135"/> <Caret Line="157" Column="15" TopLine="143"/>
</Position6> </Position6>
<Position7> <Position7>
<Filename Value="chessgame.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="54" Column="15" TopLine="39"/> <Caret Line="56" Column="29" TopLine="33"/>
</Position7> </Position7>
<Position8> <Position8>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="127" Column="1" TopLine="111"/> <Caret Line="85" Column="1" TopLine="82"/>
</Position8> </Position8>
<Position9> <Position9>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="109" Column="14" TopLine="95"/> <Caret Line="87" Column="57" TopLine="72"/>
</Position9> </Position9>
<Position10> <Position10>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="114" Column="14" TopLine="100"/> <Caret Line="56" Column="29" TopLine="47"/>
</Position10> </Position10>
<Position11> <Position11>
<Filename Value="chessdrawer.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="47" Column="21" TopLine="33"/> <Caret Line="79" Column="36" TopLine="79"/>
</Position11> </Position11>
<Position12> <Position12>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="114" Column="14" TopLine="100"/> <Caret Line="111" Column="3" TopLine="97"/>
</Position12> </Position12>
<Position13> <Position13>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="117" Column="43" TopLine="100"/> <Caret Line="122" Column="26" TopLine="108"/>
</Position13> </Position13>
<Position14> <Position14>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="111" Column="1" TopLine="100"/> <Caret Line="123" Column="26" TopLine="109"/>
</Position14> </Position14>
<Position15> <Position15>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="112" Column="1" TopLine="100"/> <Caret Line="124" Column="26" TopLine="110"/>
</Position15> </Position15>
<Position16> <Position16>
<Filename Value="chessgame.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="133" Column="1" TopLine="119"/> <Caret Line="122" Column="29" TopLine="111"/>
</Position16> </Position16>
<Position17> <Position17>
<Filename Value="chessgame.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="136" Column="1" TopLine="119"/> <Caret Line="77" Column="24" TopLine="72"/>
</Position17> </Position17>
<Position18> <Position18>
<Filename Value="mainform.pas"/> <Filename Value="chessgame.pas"/>
<Caret Line="112" Column="1" TopLine="103"/> <Caret Line="53" Column="16" TopLine="41"/>
</Position18> </Position18>
<Position19> <Position19>
<Filename Value="mainform.pas"/> <Filename Value="chessgame.pas"/>
<Caret Line="122" Column="1" TopLine="103"/> <Caret Line="125" Column="49" TopLine="125"/>
</Position19> </Position19>
<Position20> <Position20>
<Filename Value="mainform.pas"/> <Filename Value="chessgame.pas"/>
<Caret Line="123" Column="1" TopLine="103"/> <Caret Line="54" Column="15" TopLine="53"/>
</Position20> </Position20>
<Position21> <Position21>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="121" Column="43" TopLine="104"/> <Caret Line="77" Column="24" TopLine="72"/>
</Position21> </Position21>
<Position22> <Position22>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="123" Column="1" TopLine="104"/> <Caret Line="78" Column="22" TopLine="73"/>
</Position22> </Position22>
<Position23> <Position23>
<Filename Value="chessgame.pas"/> <Filename Value="chessgame.pas"/>
<Caret Line="157" Column="15" TopLine="143"/> <Caret Line="56" Column="24" TopLine="42"/>
</Position23> </Position23>
<Position24> <Position24>
<Filename Value="mainform.pas"/> <Filename Value="chessgame.pas"/>
<Caret Line="56" Column="29" TopLine="33"/> <Caret Line="63" Column="14" TopLine="43"/>
</Position24> </Position24>
<Position25> <Position25>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="85" Column="1" TopLine="82"/> <Caret Line="78" Column="22" TopLine="73"/>
</Position25> </Position25>
<Position26> <Position26>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="87" Column="57" TopLine="72"/> <Caret Line="80" Column="22" TopLine="75"/>
</Position26> </Position26>
<Position27> <Position27>
<Filename Value="mainform.pas"/> <Filename Value="chessgame.pas"/>
<Caret Line="56" Column="29" TopLine="47"/> <Caret Line="175" Column="3" TopLine="32"/>
</Position27> </Position27>
<Position28> <Position28>
<Filename Value="mainform.pas"/> <Filename Value="chessgame.pas"/>
<Caret Line="79" Column="36" TopLine="79"/> <Caret Line="172" Column="14" TopLine="158"/>
</Position28> </Position28>
<Position29> <Position29>
<Filename Value="mainform.pas"/> <Filename Value="chessgame.pas"/>
<Caret Line="111" Column="3" TopLine="97"/> <Caret Line="178" Column="14" TopLine="163"/>
</Position29> </Position29>
<Position30> <Position30>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
<Caret Line="122" Column="26" TopLine="108"/> <Caret Line="107" Column="60" TopLine="90"/>
</Position30> </Position30>
</JumpHistory> </JumpHistory>
</ProjectOptions> </ProjectOptions>

View File

@ -2,29 +2,29 @@ object formChess: TformChess
Left = 181 Left = 181
Height = 433 Height = 433
Top = 209 Top = 209
Width = 240 Width = 360
Caption = 'FP Chess 0.1' Caption = 'FP Chess 0.1'
ClientHeight = 433 ClientHeight = 433
ClientWidth = 240 ClientWidth = 360
OnCreate = FormCreate OnCreate = FormCreate
LCLVersion = '0.9.29' LCLVersion = '0.9.29'
object notebookMain: TUntabbedNotebook object notebookMain: TUntabbedNotebook
Left = 0 Left = 0
Height = 433 Height = 433
Top = 0 Top = 0
Width = 240 Width = 360
PageIndex = 3 PageIndex = 0
Align = alClient Align = alClient
TabOrder = 0 TabOrder = 0
TabStop = True TabStop = True
object pageStart: TUNBPage object pageStart: TUNBPage
ClientWidth = 240 ClientWidth = 360
ClientHeight = 300 ClientHeight = 433
object Label1: TLabel object Label1: TLabel
Left = 0 Left = 0
Height = 32 Height = 32
Top = 8 Top = 8
Width = 240 Width = 360
Alignment = taCenter Alignment = taCenter
AutoSize = False AutoSize = False
Caption = 'Welcome to FP Chess 0.1' Caption = 'Welcome to FP Chess 0.1'
@ -36,51 +36,52 @@ object formChess: TformChess
Left = 8 Left = 8
Height = 30 Height = 30
Top = 40 Top = 40
Width = 224 Width = 352
AutoSize = False AutoSize = False
Caption = 'Please choose what kind of game you would like to play:' Caption = 'Please choose what kind of game you would like to play:'
ParentColor = False ParentColor = False
WordWrap = True WordWrap = True
end end
object btnSinglePlayer: TBitBtn object btnSinglePlayer: TBitBtn
Left = 8 Left = 64
Height = 30 Height = 30
Top = 152 Top = 200
Width = 224 Width = 224
Caption = 'Play Against the Computer' Caption = 'Play Against the Computer'
Enabled = False
OnClick = HandleMainScreenButton OnClick = HandleMainScreenButton
TabOrder = 0 TabOrder = 0
end end
object btnDirectComm: TBitBtn object btnDirectComm: TBitBtn
Left = 8 Left = 62
Height = 30 Height = 30
Top = 184 Top = 288
Width = 226 Width = 226
Caption = 'Play with a friend through a direct connection' Caption = 'Play with a friend through a direct connection'
OnClick = HandleMainScreenButton OnClick = HandleMainScreenButton
TabOrder = 1 TabOrder = 1
end end
object BitBtn3: TBitBtn object BitBtn3: TBitBtn
Left = 8 Left = 64
Height = 30 Height = 30
Top = 232 Top = 336
Width = 224 Width = 224
Caption = 'Quit' Caption = 'Quit'
TabOrder = 2 TabOrder = 2
end end
object editPlayerName: TLabeledEdit object editPlayerName: TLabeledEdit
Left = 104 Left = 88
Height = 21 Height = 21
Top = 80 Top = 72
Width = 120 Width = 120
EditLabel.AnchorSideLeft.Control = editPlayerName EditLabel.AnchorSideLeft.Control = editPlayerName
EditLabel.AnchorSideTop.Control = editPlayerName EditLabel.AnchorSideTop.Control = editPlayerName
EditLabel.AnchorSideTop.Side = asrCenter EditLabel.AnchorSideTop.Side = asrCenter
EditLabel.AnchorSideRight.Control = editPlayerName EditLabel.AnchorSideRight.Control = editPlayerName
EditLabel.AnchorSideBottom.Control = editPlayerName EditLabel.AnchorSideBottom.Control = editPlayerName
EditLabel.Left = 40 EditLabel.Left = 24
EditLabel.Height = 14 EditLabel.Height = 14
EditLabel.Top = 83 EditLabel.Top = 75
EditLabel.Width = 61 EditLabel.Width = 61
EditLabel.Caption = 'Player Name' EditLabel.Caption = 'Player Name'
EditLabel.ParentColor = False EditLabel.ParentColor = False
@ -88,17 +89,17 @@ object formChess: TformChess
TabOrder = 3 TabOrder = 3
end end
object Label6: TLabel object Label6: TLabel
Left = 21 Left = 28
Height = 14 Height = 14
Top = 112 Top = 104
Width = 43 Width = 43
Caption = 'Start as:' Caption = 'Start as:'
ParentColor = False ParentColor = False
end end
object comboStartColor: TComboBox object comboStartColor: TComboBox
Left = 104 Left = 88
Height = 21 Height = 21
Top = 111 Top = 104
Width = 120 Width = 120
ItemHeight = 13 ItemHeight = 13
ItemIndex = 0 ItemIndex = 0
@ -109,10 +110,45 @@ object formChess: TformChess
TabOrder = 4 TabOrder = 4
Text = 'White' Text = 'White'
end end
object checkTimer: TCheckBox
Left = 24
Height = 17
Top = 136
Width = 163
Caption = 'Set a time limit for each Player'
Checked = True
State = cbChecked
TabOrder = 5
end
object spinPlayerTime: TSpinEdit
Left = 21
Height = 21
Top = 160
Width = 50
TabOrder = 6
Value = 30
end
object Label7: TLabel
Left = 80
Height = 14
Top = 163
Width = 114
Caption = 'minutes for each player'
ParentColor = False
end
object btnHotSeat: TBitBtn
Left = 64
Height = 30
Top = 240
Width = 224
Caption = 'Play with a friend in the same Computer'
OnClick = HandleMainScreenButton
TabOrder = 7
end
end end
object pageConfigConnection: TUNBPage object pageConfigConnection: TUNBPage
ClientWidth = 480 ClientWidth = 960
ClientHeight = 600 ClientHeight = 1200
object Label3: TLabel object Label3: TLabel
Left = 0 Left = 0
Height = 32 Height = 32
@ -176,8 +212,8 @@ object formChess: TformChess
end end
end end
object pageConnecting: TUNBPage object pageConnecting: TUNBPage
ClientWidth = 480 ClientWidth = 960
ClientHeight = 600 ClientHeight = 1200
object Label4: TLabel object Label4: TLabel
Left = 0 Left = 0
Height = 32 Height = 32
@ -199,8 +235,8 @@ object formChess: TformChess
end end
end end
object pageGame: TUNBPage object pageGame: TUNBPage
ClientWidth = 240 ClientWidth = 480
ClientHeight = 433 ClientHeight = 866
object Label5: TLabel object Label5: TLabel
Left = 0 Left = 0
Height = 32 Height = 32
@ -223,4 +259,9 @@ object formChess: TformChess
end end
end end
end end
object timerChessTimer: TTimer
OnTimer = timerChessTimerTimer
left = 296
top = 152
end
end end

View File

@ -6,7 +6,7 @@ interface
uses uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
ExtCtrls, ComCtrls, StdCtrls, Buttons, ExtCtrls, ComCtrls, StdCtrls, Buttons, Spin,
// //
chessdrawer, chessgame, chessconfig; chessdrawer, chessgame, chessconfig;
@ -30,6 +30,8 @@ type
btnSinglePlayer: TBitBtn; btnSinglePlayer: TBitBtn;
btnDirectComm: TBitBtn; btnDirectComm: TBitBtn;
BitBtn3: TBitBtn; BitBtn3: TBitBtn;
btnHotSeat: TBitBtn;
checkTimer: TCheckBox;
comboStartColor: TComboBox; comboStartColor: TComboBox;
Label1: TLabel; Label1: TLabel;
Label2: TLabel; Label2: TLabel;
@ -37,6 +39,7 @@ type
Label4: TLabel; Label4: TLabel;
Label5: TLabel; Label5: TLabel;
Label6: TLabel; Label6: TLabel;
Label7: TLabel;
labelPos: TLabel; labelPos: TLabel;
LabeledEdit1: TLabeledEdit; LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit; LabeledEdit2: TLabeledEdit;
@ -47,8 +50,11 @@ type
pageConnecting: TUNBPage; pageConnecting: TUNBPage;
ProgressBar1: TProgressBar; ProgressBar1: TProgressBar;
pageGame: TUNBPage; pageGame: TUNBPage;
spinPlayerTime: TSpinEdit;
timerChessTimer: TTimer;
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure HandleMainScreenButton(Sender: TObject); procedure HandleMainScreenButton(Sender: TObject);
procedure timerChessTimerTimer(Sender: TObject);
private private
{ private declarations } { private declarations }
public public
@ -71,20 +77,36 @@ begin
if Sender = btnSinglePlayer then if Sender = btnSinglePlayer then
begin begin
notebookMain.PageIndex := 3; notebookMain.PageIndex := 3;
vChessGame.StartNewGame(comboStartColor.ItemIndex); vChessGame.StartNewGame(comboStartColor.ItemIndex, checkTimer.Checked, spinPlayerTime.Value);
end
else if Sender = btnHotSeat then
begin
notebookMain.PageIndex := 3;
vChessGame.StartNewGame(comboStartColor.ItemIndex, checkTimer.Checked, spinPlayerTime.Value);
end end
else if Sender = btnDirectComm then notebookMain.PageIndex := 1; else if Sender = btnDirectComm then notebookMain.PageIndex := 1;
end; end;
procedure TformChess.timerChessTimerTimer(Sender: TObject);
begin
vChessGame.UpdateTimes();
UpdateCaptions();
end;
procedure TformChess.UpdateCaptions; procedure TformChess.UpdateCaptions;
var var
CurPlayerStr: string; lStr: string;
begin begin
if vChessGame.CurrentPlayerIsWhite then CurPlayerStr := 'White playing' if vChessGame.CurrentPlayerIsWhite then lStr := 'White playing'
else CurPlayerStr := 'Black playing'; else lStr := 'Black playing';
formChess.labelPos.Caption := Format(CurPlayerStr + ' X: %d Y: %d', lStr := lStr + Format(' X: %d Y: %d',
[vChessGame.MouseMovePos.X, vChessGame.MouseMovePos.Y]); [vChessGame.MouseMovePos.X, vChessGame.MouseMovePos.Y]);
lStr := lStr + Format(' White time: %d Black time: %d',
[vChessGame.WhitePlayerTime, vChessGame.BlackPlayerTime]);
formChess.labelPos.Caption := lStr;
end; end;
procedure TformChess.FormCreate(Sender: TObject); procedure TformChess.FormCreate(Sender: TObject);