Starts building more structure into the chess game

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1323 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat
2010-09-21 06:33:18 +00:00
parent ee1b5a0ce4
commit 2bd91fb276
8 changed files with 524 additions and 207 deletions

View File

@ -0,0 +1,46 @@
unit chessconfig;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
type
{ TChessConfig }
TChessConfig = class
public
function GetResourcesDir: string;
function GetCurrentSkinDir: string;
end;
var
vChessConfig: TChessConfig;
implementation
{ TChessConfig }
function TChessConfig.GetResourcesDir: string;
begin
end;
function TChessConfig.GetCurrentSkinDir: string;
begin
Result := GetResourcesDir() + 'skins' + PathDelim + 'classic' + PathDelim;
end;
initialization
vChessConfig := TChessConfig.Create;
finalization
vChessConfig.Free;
end.

View File

@ -0,0 +1,144 @@
unit chessdrawer;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Controls, Graphics, LCLType,
//
chessgame, chessconfig;
type
{ TChessDrawer }
TChessDrawer = class(TCustomControl)
private
imgBoard,
imgWPawn, imgWKnight, imgWBishop, imgWRook, imgWQueen, imgWKing,
imgBPawn, imgBKnight, imgBBishop, imgBRook, imgBQueen, imgBKing:
TPortableNetworkGraphic;
public
constructor Create(AOwner: TComponent); override;
procedure EraseBackground(DC: HDC); override;
procedure Paint; override;
procedure DrawToCanvas(ACanvas: TCanvas);
procedure DrawChessTile(ACanvas: TCanvas; ACol, ARow: Integer;
ATile: TChessTile);
procedure LoadImages();
end;
var
vChessDrawer: TChessDrawer;
implementation
constructor TChessDrawer.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
imgBoard := TPortableNetworkGraphic.Create;
imgWPawn := TPortableNetworkGraphic.Create;
imgWKnight := TPortableNetworkGraphic.Create;
imgWBishop := TPortableNetworkGraphic.Create;
imgWRook := TPortableNetworkGraphic.Create;
imgWQueen := TPortableNetworkGraphic.Create;
imgWKing := TPortableNetworkGraphic.Create;
imgBPawn := TPortableNetworkGraphic.Create;
imgBKnight := TPortableNetworkGraphic.Create;
imgBBishop := TPortableNetworkGraphic.Create;
imgBRook := TPortableNetworkGraphic.Create;
imgBQueen := TPortableNetworkGraphic.Create;
imgBKing := TPortableNetworkGraphic.Create;
end;
procedure TChessDrawer.EraseBackground(DC: HDC);
begin
// Uncomment this to enable default background erasing
//inherited EraseBackground(DC);
end;
procedure TChessDrawer.Paint;
var
x, y: Integer;
Bitmap: TBitmap;
begin
Bitmap := TBitmap.Create;
try
// Initializes the Bitmap Size
Bitmap.Height := Height;
Bitmap.Width := Width;
DrawToCanvas(Bitmap.Canvas);
Canvas.Draw(0, 0, Bitmap);
finally
Bitmap.Free;
end;
// inherited Paint;
end;
procedure TChessDrawer.DrawToCanvas(ACanvas: TCanvas);
var
col, row: Integer;
begin
// First draw the board
ACanvas.Draw(0, 0, imgBoard);
// Now all pieces
for col := 1 to 8 do
for row := 1 to 8 do
DrawChessTile(ACanvas, col, row, vChessGame.Board[col][row]);
end;
procedure TChessDrawer.DrawChessTile(ACanvas: TCanvas; ACol, ARow: Integer;
ATile: TChessTile);
var
X, Y: Integer;
begin
if ATile = ctEmpty then Exit;
X := (ACol - 1) * INT_CHESSTILE_SIZE;
Y := (8 - ARow) * INT_CHESSTILE_SIZE;
case ATile of
ctWPawn: ACanvas.Draw(X, Y, imgWPawn);
ctWKnight: ACanvas.Draw(X, Y, imgWKnight);
ctWBishop: ACanvas.Draw(X, Y, imgWBishop);
ctWRook: ACanvas.Draw(X, Y, imgWRook);
ctWQueen: ACanvas.Draw(X, Y, imgWQueen);
ctWKing: ACanvas.Draw(X, Y, imgWKing);
ctBPawn: ACanvas.Draw(X, Y, imgBPawn);
ctBKnight: ACanvas.Draw(X, Y, imgBKnight);
ctBBishop: ACanvas.Draw(X, Y, imgBBishop);
ctBRook: ACanvas.Draw(X, Y, imgBRook);
ctBQueen: ACanvas.Draw(X, Y, imgBQueen);
ctBKing: ACanvas.Draw(X, Y, imgBKing);
end;
end;
procedure TChessDrawer.LoadImages();
var
lDir: string;
begin
lDir := vChessConfig.GetCurrentSkinDir();
imgBoard.LoadFromFile(lDir + 'board.png');
imgWPawn.LoadFromFile(lDir + 'wpawn.png');
imgWKnight.LoadFromFile(lDir + 'wknight.png');
imgWBishop.LoadFromFile(lDir + 'wbishop.png');
imgWRook.LoadFromFile(lDir + 'wrook.png');
imgWQueen.LoadFromFile(lDir + 'wqueen.png');
imgWKing.LoadFromFile(lDir + 'wking.png');
imgBPawn.LoadFromFile(lDir + 'bpawn.png');
imgBKnight.LoadFromFile(lDir + 'bknight.png');
imgBBishop.LoadFromFile(lDir + 'bbishop.png');
imgBRook.LoadFromFile(lDir + 'brook.png');
imgBQueen.LoadFromFile(lDir + 'bqueen.png');
imgBKing.LoadFromFile(lDir + 'bking.png');
end;
end.

View File

@ -0,0 +1,124 @@
unit chessgame;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
const
colA = 1;
colB = 2;
colC = 3;
colD = 4;
colE = 5;
colF = 6;
colG = 7;
colH = 8;
INT_CHESSTILE_SIZE = 20;
INT_CHESSBOARD_SIZE = 200;
type
TChessTile = (ctEmpty,
ctWPawn, ctWKnight, ctWBishop, ctWRook, ctWQueen, ctWKing,
ctBPawn, ctBKnight, ctBBishop, ctBRook, ctBQueen, ctBKing
);
{@@
The index [1][1] refers to the left-bottom corner of the table,
also known as A1.
The first index is the column, to follow the same standard used to
say coordinates, for example: C7 = [3][7]
}
TChessBoard = array[1..8] of array[1..8] of TChessTile;
{ TChessGame }
TChessGame = class
public
Board: TChessBoard;
procedure StartNewGame(APlayAsWhite: Boolean); overload;
procedure StartNewGame(APlayAsWhite: Integer); overload;
end;
var
vChessGame: TChessGame;
implementation
{ TChessGame }
procedure TChessGame.StartNewGame(APlayAsWhite: Boolean);
var
lWPawnRow, lWMainRow, lBPawnRow, lBMainRow: Byte;
i: Integer;
j: Integer;
begin
//
if APlayAsWhite then
begin
lWPawnRow := 2;
lWMainRow := 1;
lBPawnRow := 7;
lBMainRow := 8;
end
else
begin
lWPawnRow := 7;
lWMainRow := 8;
lBPawnRow := 2;
lBMainRow := 1;
end;
// First, clear the board
for i := 1 to 8 do
for j := 1 to 8 do
Board[i][j] := ctEmpty;
// White pawns
for i := 1 to 8 do
Board[i][lWPawnRow] := ctWPawn;
// White main row
Board[1][lWMainRow] := ctWRook;
Board[2][lWMainRow] := ctWKnight;
Board[3][lWMainRow] := ctWBishop;
Board[4][lWMainRow] := ctWQueen;
Board[5][lWMainRow] := ctWKing;
Board[6][lWMainRow] := ctWBishop;
Board[7][lWMainRow] := ctWKnight;
Board[8][lWMainRow] := ctWRook;
// White pawns
for i := 1 to 8 do
Board[i][lBPawnRow] := ctBPawn;
// Black main row
Board[1][lBMainRow] := ctBRook;
Board[2][lBMainRow] := ctBKnight;
Board[3][lBMainRow] := ctBBishop;
Board[4][lBMainRow] := ctBQueen;
Board[5][lBMainRow] := ctBKing;
Board[6][lBMainRow] := ctBBishop;
Board[7][lBMainRow] := ctBKnight;
Board[8][lBMainRow] := ctBRook;
end;
procedure TChessGame.StartNewGame(APlayAsWhite: Integer);
begin
StartNewGame(APlayAsWhite = 0);
end;
initialization
vChessGame := TChessGame.Create;
finalization
vChessGame.Free;
end.

View File

@ -31,102 +31,86 @@
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
<Units Count="23">
<Units Count="25">
<Unit0>
<Filename Value="fpchess.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="fpchess"/>
<UsageCount Value="29"/>
<UsageCount Value="32"/>
</Unit0>
<Unit1>
<Filename Value="mainform.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<ComponentName Value="formChess"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="mainform"/>
<EditorIndex Value="0"/>
<WindowIndex Value="0"/>
<TopLine Value="15"/>
<CursorPos X="40" Y="19"/>
<UsageCount Value="29"/>
<TopLine Value="56"/>
<CursorPos X="45" Y="72"/>
<UsageCount Value="32"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
<Unit2>
<Filename Value="..\..\..\lazarussvn\lcl\extctrls.pp"/>
<UnitName Value="ExtCtrls"/>
<EditorIndex Value="2"/>
<WindowIndex Value="0"/>
<TopLine Value="309"/>
<CursorPos X="15" Y="326"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit2>
<Unit3>
<Filename Value="..\..\..\lazarussvn\ideintf\componenteditors.pas"/>
<UnitName Value="ComponentEditors"/>
<EditorIndex Value="19"/>
<WindowIndex Value="0"/>
<TopLine Value="864"/>
<CursorPos X="15" Y="877"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit3>
<Unit4>
<Filename Value="..\..\..\lazarussvn\lcl\include\custompage.inc"/>
<EditorIndex Value="18"/>
<WindowIndex Value="0"/>
<TopLine Value="136"/>
<CursorPos X="1" Y="136"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit4>
<Unit5>
<Filename Value="..\..\..\lazarussvn\lcl\include\customnotebook.inc"/>
<EditorIndex Value="16"/>
<WindowIndex Value="0"/>
<TopLine Value="195"/>
<CursorPos X="21" Y="207"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit5>
<Unit6>
<Filename Value="..\..\..\lazarussvn\lcl\include\untabbednotebook.inc"/>
<EditorIndex Value="14"/>
<WindowIndex Value="0"/>
<TopLine Value="155"/>
<CursorPos X="36" Y="181"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit6>
<Unit7>
<Filename Value="..\..\..\lazarussvn\ideintf\propedits.pp"/>
<UnitName Value="PropEdits"/>
<EditorIndex Value="20"/>
<WindowIndex Value="0"/>
<TopLine Value="5323"/>
<CursorPos X="3" Y="5329"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit7>
<Unit8>
<Filename Value="..\..\..\lazarussvn\lcl\include\page.inc"/>
<EditorIndex Value="4"/>
<WindowIndex Value="0"/>
<TopLine Value="24"/>
<CursorPos X="26" Y="50"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit8>
<Unit9>
<Filename Value="..\..\..\lazarussvn\lcl\lconvencoding.pas"/>
<UnitName Value="LConvEncoding"/>
<EditorIndex Value="7"/>
<WindowIndex Value="0"/>
<TopLine Value="10"/>
<CursorPos X="19" Y="15"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit9>
<Unit10>
<Filename Value="F:\JIL\AndroidJuliana\Widget\PIM\addCalendarItem\auto_001.js"/>
@ -139,242 +123,242 @@
<Unit11>
<Filename Value="..\..\..\lazarussvn\lcl\controls.pp"/>
<UnitName Value="Controls"/>
<EditorIndex Value="6"/>
<WindowIndex Value="0"/>
<TopLine Value="193"/>
<CursorPos X="3" Y="225"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit11>
<Unit12>
<Filename Value="..\..\..\lazarussvn\lcl\include\notebook.inc"/>
<EditorIndex Value="3"/>
<WindowIndex Value="0"/>
<TopLine Value="9"/>
<CursorPos X="3" Y="40"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit12>
<Unit13>
<Filename Value="..\..\..\lazarussvn\lcl\lcltype.pp"/>
<UnitName Value="LCLType"/>
<EditorIndex Value="17"/>
<WindowIndex Value="0"/>
<TopLine Value="2728"/>
<CursorPos X="3" Y="2700"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit13>
<Unit14>
<Filename Value="..\..\..\fpcsvn\rtl\arm\mathu.inc"/>
<EditorIndex Value="15"/>
<WindowIndex Value="0"/>
<TopLine Value="148"/>
<CursorPos X="15" Y="163"/>
<UsageCount Value="15"/>
<Loaded Value="True"/>
</Unit14>
<Unit15>
<Filename Value="..\..\..\lazarus29\fpc\2.4.3\source\rtl\objpas\classes\classesh.inc"/>
<EditorIndex Value="5"/>
<WindowIndex Value="0"/>
<TopLine Value="595"/>
<CursorPos X="27" Y="612"/>
<UsageCount Value="14"/>
<Loaded Value="True"/>
</Unit15>
<Unit16>
<Filename Value="fpchessdrawer.pas"/>
<Filename Value="chessdrawer.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="fpchessdrawer"/>
<EditorIndex Value="1"/>
<UnitName Value="chessdrawer"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="3"/>
<WindowIndex Value="0"/>
<TopLine Value="10"/>
<CursorPos X="16" Y="23"/>
<UsageCount Value="27"/>
<TopLine Value="74"/>
<CursorPos X="3" Y="80"/>
<UsageCount Value="30"/>
<Loaded Value="True"/>
</Unit16>
<Unit17>
<Filename Value="..\..\..\lazarussvn\lcl\lconvasiapage.pas"/>
<UnitName Value="LConvAsiaPage"/>
<EditorIndex Value="13"/>
<WindowIndex Value="0"/>
<TopLine Value="2"/>
<CursorPos X="26" Y="18"/>
<UsageCount Value="13"/>
<Loaded Value="True"/>
</Unit17>
<Unit18>
<Filename Value="..\..\..\lazarussvn\lcl\include\asiancodepagefunctions.inc"/>
<EditorIndex Value="12"/>
<WindowIndex Value="0"/>
<TopLine Value="18"/>
<CursorPos X="1" Y="37"/>
<UsageCount Value="13"/>
<Loaded Value="True"/>
</Unit18>
<Unit19>
<Filename Value="..\..\..\lazarussvn\lcl\translations.pas"/>
<UnitName Value="Translations"/>
<EditorIndex Value="8"/>
<WindowIndex Value="0"/>
<TopLine Value="43"/>
<CursorPos X="24" Y="66"/>
<UsageCount Value="13"/>
<Loaded Value="True"/>
</Unit19>
<Unit20>
<Filename Value="..\..\..\fpcsvn\packages\fpvectorial\src\pdfvrsemantico.pas"/>
<UnitName Value="pdfvrsemantico"/>
<EditorIndex Value="9"/>
<WindowIndex Value="0"/>
<TopLine Value="210"/>
<CursorPos X="19" Y="230"/>
<UsageCount Value="13"/>
<Loaded Value="True"/>
</Unit20>
<Unit21>
<Filename Value="..\..\..\openssl-1.0.0a\crypto\pem\pem_pkey.c"/>
<EditorIndex Value="10"/>
<WindowIndex Value="0"/>
<TopLine Value="55"/>
<CursorPos X="1" Y="76"/>
<UsageCount Value="13"/>
<Loaded Value="True"/>
<DefaultSyntaxHighlighter Value="C++"/>
</Unit21>
<Unit22>
<Filename Value="..\..\..\fpcsvn\packages\openssl\src\openssl.pas"/>
<UnitName Value="OpenSSL"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="11"/>
<WindowIndex Value="0"/>
<TopLine Value="634"/>
<CursorPos X="20" Y="656"/>
<UsageCount Value="13"/>
<Loaded Value="True"/>
</Unit22>
<Unit23>
<Filename Value="chessgame.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="chessgame"/>
<EditorIndex Value="1"/>
<WindowIndex Value="0"/>
<TopLine Value="13"/>
<CursorPos X="22" Y="21"/>
<UsageCount Value="22"/>
<Loaded Value="True"/>
</Unit23>
<Unit24>
<Filename Value="chessconfig.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="chessconfig"/>
<EditorIndex Value="2"/>
<WindowIndex Value="0"/>
<TopLine Value="22"/>
<CursorPos X="13" Y="39"/>
<UsageCount Value="22"/>
<Loaded Value="True"/>
</Unit24>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="..\..\..\lazarussvn\lcl\include\untabbednotebook.inc"/>
<Caret Line="171" Column="61" TopLine="154"/>
<Filename Value="chessconfig.pas"/>
<Caret Line="16" Column="38" TopLine="1"/>
</Position1>
<Position2>
<Filename Value="..\..\..\lazarussvn\lcl\include\untabbednotebook.inc"/>
<Caret Line="186" Column="4" TopLine="154"/>
<Filename Value="chessdrawer.pas"/>
<Caret Line="19" Column="28" TopLine="4"/>
</Position2>
<Position3>
<Filename Value="..\..\..\lazarussvn\lcl\include\untabbednotebook.inc"/>
<Caret Line="171" Column="33" TopLine="154"/>
<Filename Value="chessgame.pas"/>
<Caret Line="21" Column="28" TopLine="12"/>
</Position3>
<Position4>
<Filename Value="..\..\..\lazarussvn\lcl\controls.pp"/>
<Caret Line="1386" Column="33" TopLine="1369"/>
<Filename Value="chessgame.pas"/>
<Caret Line="24" Column="28" TopLine="7"/>
</Position4>
<Position5>
<Filename Value="..\..\..\lazarussvn\lcl\lconvencoding.pas"/>
<Caret Line="19" Column="2" TopLine="2"/>
<Filename Value="chessgame.pas"/>
<Caret Line="82" Column="11" TopLine="61"/>
</Position5>
<Position6>
<Filename Value="..\..\..\lazarussvn\lcl\include\untabbednotebook.inc"/>
<Caret Line="171" Column="68" TopLine="154"/>
<Filename Value="chessgame.pas"/>
<Caret Line="24" Column="62" TopLine="13"/>
</Position6>
<Position7>
<Filename Value="..\..\..\fpcsvn\rtl\arm\mathu.inc"/>
<Caret Line="1" Column="1" TopLine="1"/>
<Filename Value="chessgame.pas"/>
<Caret Line="71" Column="8" TopLine="59"/>
</Position7>
<Position8>
<Filename Value="..\..\..\fpcsvn\rtl\arm\mathu.inc"/>
<Caret Line="36" Column="26" TopLine="19"/>
<Filename Value="mainform.pas"/>
<Caret Line="70" Column="28" TopLine="49"/>
</Position8>
<Position9>
<Filename Value="..\..\..\lazarussvn\lcl\include\untabbednotebook.inc"/>
<Caret Line="171" Column="68" TopLine="154"/>
<Filename Value="mainform.pas"/>
<Caret Line="71" Column="28" TopLine="50"/>
</Position9>
<Position10>
<Filename Value="..\..\..\lazarussvn\lcl\include\page.inc"/>
<Caret Line="36" Column="12" TopLine="7"/>
<Filename Value="mainform.pas"/>
<Caret Line="70" Column="28" TopLine="49"/>
</Position10>
<Position11>
<Filename Value="..\..\..\lazarussvn\lcl\include\page.inc"/>
<Caret Line="38" Column="28" TopLine="24"/>
<Filename Value="mainform.pas"/>
<Caret Line="71" Column="28" TopLine="50"/>
</Position11>
<Position12>
<Filename Value="mainform.pas"/>
<Caret Line="9" Column="10" TopLine="1"/>
<Caret Line="72" Column="28" TopLine="51"/>
</Position12>
<Position13>
<Filename Value="mainform.pas"/>
<Caret Line="19" Column="40" TopLine="15"/>
<Caret Line="71" Column="28" TopLine="50"/>
</Position13>
<Position14>
<Filename Value="..\..\..\lazarussvn\lcl\lconvencoding.pas"/>
<Caret Line="6181" Column="32" TopLine="6170"/>
<Filename Value="mainform.pas"/>
<Caret Line="70" Column="28" TopLine="49"/>
</Position14>
<Position15>
<Filename Value="..\..\..\lazarussvn\lcl\lconvencoding.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
<Filename Value="mainform.pas"/>
<Caret Line="71" Column="28" TopLine="50"/>
</Position15>
<Position16>
<Filename Value="..\..\..\lazarussvn\lcl\lconvencoding.pas"/>
<Caret Line="6" Column="51" TopLine="1"/>
<Filename Value="mainform.pas"/>
<Caret Line="72" Column="28" TopLine="51"/>
</Position16>
<Position17>
<Filename Value="..\..\..\lazarussvn\lcl\lconvencoding.pas"/>
<Caret Line="5853" Column="29" TopLine="5836"/>
<Filename Value="mainform.pas"/>
<Caret Line="73" Column="28" TopLine="52"/>
</Position17>
<Position18>
<Filename Value="..\..\..\lazarussvn\lcl\lconvencoding.pas"/>
<Caret Line="101" Column="44" TopLine="95"/>
<Filename Value="chessgame.pas"/>
<Caret Line="41" Column="20" TopLine="28"/>
</Position18>
<Position19>
<Filename Value="..\..\..\lazarussvn\lcl\lconvencoding.pas"/>
<Caret Line="104" Column="32" TopLine="94"/>
<Filename Value="mainform.pas"/>
<Caret Line="60" Column="53" TopLine="52"/>
</Position19>
<Position20>
<Filename Value="..\..\..\lazarussvn\lcl\lconvencoding.pas"/>
<Caret Line="6188" Column="28" TopLine="6170"/>
<Filename Value="chessgame.pas"/>
<Caret Line="108" Column="34" TopLine="96"/>
</Position20>
<Position21>
<Filename Value="..\..\..\lazarussvn\lcl\lconvencoding.pas"/>
<Caret Line="133" Column="20" TopLine="116"/>
<Filename Value="chessgame.pas"/>
<Caret Line="75" Column="9" TopLine="63"/>
</Position21>
<Position22>
<Filename Value="fpchessdrawer.pas"/>
<Caret Line="18" Column="34" TopLine="4"/>
<Filename Value="chessdrawer.pas"/>
<Caret Line="20" Column="42" TopLine="13"/>
</Position22>
<Position23>
<Filename Value="..\..\..\lazarussvn\lcl\lconvasiapage.pas"/>
<Caret Line="240" Column="1" TopLine="207"/>
<Filename Value="chessdrawer.pas"/>
<Caret Line="19" Column="20" TopLine="7"/>
</Position23>
<Position24>
<Filename Value="..\..\..\lazarussvn\lcl\lconvencoding.pas"/>
<Caret Line="114" Column="38" TopLine="108"/>
<Filename Value="chessconfig.pas"/>
<Caret Line="17" Column="28" TopLine="4"/>
</Position24>
<Position25>
<Filename Value="..\..\..\lazarussvn\lcl\lconvencoding.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
<Filename Value="chessdrawer.pas"/>
<Caret Line="25" Column="22" TopLine="12"/>
</Position25>
<Position26>
<Filename Value="..\..\..\lazarussvn\lcl\include\asiancodepagefunctions.inc"/>
<Caret Line="34" Column="3" TopLine="23"/>
<Filename Value="chessdrawer.pas"/>
<Caret Line="131" Column="1" TopLine="117"/>
</Position26>
<Position27>
<Filename Value="..\..\..\lazarussvn\lcl\translations.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
<Filename Value="chessdrawer.pas"/>
<Caret Line="9" Column="5" TopLine="1"/>
</Position27>
<Position28>
<Filename Value="..\..\..\fpcsvn\packages\fpvectorial\src\pdfvrsemantico.pas"/>
<Caret Line="48" Column="1" TopLine="27"/>
<Filename Value="chessdrawer.pas"/>
<Caret Line="103" Column="39" TopLine="91"/>
</Position28>
<Position29>
<Filename Value="..\..\..\openssl-1.0.0a\crypto\pem\pem_pkey.c"/>
<Caret Line="1" Column="1" TopLine="1"/>
<Filename Value="chessdrawer.pas"/>
<Caret Line="124" Column="6" TopLine="112"/>
</Position29>
<Position30>
<Filename Value="..\..\..\fpcsvn\packages\openssl\src\openssl.pas"/>
<Caret Line="1" Column="1" TopLine="1"/>
<Filename Value="chessdrawer.pas"/>
<Caret Line="136" Column="31" TopLine="120"/>
</Position30>
</JumpHistory>
</ProjectOptions>
@ -385,7 +369,7 @@
<Filename Value="fpchess"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)\"/>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>

View File

@ -7,14 +7,14 @@ uses
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, mainform, fpchessdrawer
Forms, mainform, chessdrawer, chessgame, chessconfig
{ you can add units after this };
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TformChess, formChess);
Application.Run;
end.

View File

@ -1,59 +0,0 @@
unit fpchessdrawer;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Controls, Graphics, LCLType;
type
{ TFPChessDrawer }
TFPChessDrawer = class(TCustomControl)
public
procedure EraseBackground(DC: HDC); override;
procedure Paint; override;
procedure DrawToCanvas(ACanvas: TCanvas);
end;
var
vFPChessDrawer: TFPChessDrawer;
implementation
procedure TFPChessDrawer.EraseBackground(DC: HDC);
begin
// Uncomment this to enable default background erasing
//inherited EraseBackground(DC);
end;
procedure TFPChessDrawer.Paint;
var
x, y: Integer;
Bitmap: TBitmap;
begin
Bitmap := TBitmap.Create;
try
// Initializes the Bitmap Size
Bitmap.Height := Height;
Bitmap.Width := Width;
DrawToCanvas(Bitmap.Canvas);
Canvas.Draw(0, 0, Bitmap);
finally
Bitmap.Free;
end;
inherited Paint;
end;
procedure TFPChessDrawer.DrawToCanvas(ACanvas: TCanvas);
begin
end;
end.

View File

@ -1,4 +1,4 @@
object Form1: TForm1
object formChess: TformChess
Left = 181
Height = 300
Top = 209
@ -6,13 +6,14 @@ object Form1: TForm1
Caption = 'FP Chess 0.1'
ClientHeight = 300
ClientWidth = 240
OnCreate = FormCreate
LCLVersion = '0.9.29'
object notebookMain: TUntabbedNotebook
Left = 0
Height = 300
Top = 0
Width = 240
PageIndex = 2
PageIndex = 0
Align = alClient
TabOrder = 0
TabStop = True
@ -46,29 +47,70 @@ object Form1: TForm1
object btnSinglePlayer: TBitBtn
Left = 8
Height = 30
Top = 112
Top = 152
Width = 224
Caption = 'Play Against the Computer'
OnClick = HandleMainScreenButton
TabOrder = 0
end
object buttonDirectComm: TBitBtn
object btnDirectComm: TBitBtn
Left = 8
Height = 30
Top = 144
Top = 184
Width = 226
Caption = 'Play with a friend through a direct connection'
OnClick = buttonDirectCommClick
OnClick = HandleMainScreenButton
TabOrder = 1
end
object BitBtn3: TBitBtn
Left = 8
Height = 30
Top = 264
Top = 232
Width = 224
Caption = 'Quit'
TabOrder = 2
end
object editPlayerName: TLabeledEdit
Left = 104
Height = 22
Top = 80
Width = 120
EditLabel.AnchorSideLeft.Control = editPlayerName
EditLabel.AnchorSideTop.Control = editPlayerName
EditLabel.AnchorSideTop.Side = asrCenter
EditLabel.AnchorSideRight.Control = editPlayerName
EditLabel.AnchorSideBottom.Control = editPlayerName
EditLabel.Left = 22
EditLabel.Height = 17
EditLabel.Top = 83
EditLabel.Width = 79
EditLabel.Caption = 'Player Name'
EditLabel.ParentColor = False
LabelPosition = lpLeft
TabOrder = 3
end
object Label6: TLabel
Left = 21
Height = 17
Top = 112
Width = 52
Caption = 'Start as:'
ParentColor = False
end
object comboStartColor: TComboBox
Left = 104
Height = 21
Top = 111
Width = 120
ItemHeight = 0
ItemIndex = 0
Items.Strings = (
'White'
'Black'
)
TabOrder = 4
Text = 'White'
end
end
object pageConfigConnection: TUNBPage
Left = 0
@ -88,8 +130,8 @@ object Form1: TForm1
ParentFont = False
end
object LabeledEdit1: TLabeledEdit
Left = 104
Height = 21
Left = 112
Height = 22
Top = 72
Width = 120
EditLabel.AnchorSideLeft.Control = LabeledEdit1
@ -97,10 +139,10 @@ object Form1: TForm1
EditLabel.AnchorSideTop.Side = asrCenter
EditLabel.AnchorSideRight.Control = LabeledEdit1
EditLabel.AnchorSideBottom.Control = LabeledEdit1
EditLabel.Left = 23
EditLabel.Height = 14
EditLabel.Left = 8
EditLabel.Height = 17
EditLabel.Top = 75
EditLabel.Width = 78
EditLabel.Width = 101
EditLabel.Caption = 'Your friend''s IP:'
EditLabel.ParentColor = False
LabelPosition = lpLeft
@ -108,8 +150,8 @@ object Form1: TForm1
Text = 'LabeledEdit1'
end
object LabeledEdit2: TLabeledEdit
Left = 104
Height = 21
Left = 112
Height = 22
Top = 104
Width = 120
EditLabel.AnchorSideLeft.Control = LabeledEdit2
@ -117,10 +159,10 @@ object Form1: TForm1
EditLabel.AnchorSideTop.Side = asrCenter
EditLabel.AnchorSideRight.Control = LabeledEdit2
EditLabel.AnchorSideBottom.Control = LabeledEdit2
EditLabel.Left = 19
EditLabel.Height = 14
EditLabel.Left = 4
EditLabel.Height = 17
EditLabel.Top = 107
EditLabel.Width = 82
EditLabel.Width = 105
EditLabel.Caption = 'Your IP Address:'
EditLabel.ParentColor = False
LabelPosition = lpLeft
@ -129,11 +171,11 @@ object Form1: TForm1
Text = 'LabeledEdit2'
end
object BitBtn1: TBitBtn
Left = 16
Left = 8
Height = 30
Top = 144
Width = 208
Caption = 'BitBtn1'
Top = 184
Width = 224
Caption = 'Connect'
TabOrder = 2
end
end
@ -162,5 +204,23 @@ object Form1: TForm1
TabOrder = 0
end
end
object pageGame: TUNBPage
Left = 0
Height = 300
Top = 0
Width = 240
object Label5: TLabel
Left = 0
Height = 32
Top = 8
Width = 240
Alignment = taCenter
AutoSize = False
Caption = 'Playing'
Font.Height = -19
ParentColor = False
ParentFont = False
end
end
end
end

View File

@ -6,29 +6,36 @@ interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
ComCtrls, StdCtrls, Buttons;
ComCtrls, StdCtrls, Buttons,
//
chessdrawer, chessgame, chessconfig;
type
{ TForm1 }
{ TformChess }
TForm1 = class(TForm)
TformChess = class(TForm)
BitBtn1: TBitBtn;
btnSinglePlayer: TBitBtn;
buttonDirectComm: TBitBtn;
btnDirectComm: TBitBtn;
BitBtn3: TBitBtn;
comboStartColor: TComboBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
editPlayerName: TLabeledEdit;
pageStart: TUNBPage;
pageConfigConnection: TUNBPage;
notebookMain: TUntabbedNotebook;
pageConnecting: TUNBPage;
ProgressBar1: TProgressBar;
procedure buttonDirectCommClick(Sender: TObject);
pageGame: TUNBPage;
procedure FormCreate(Sender: TObject);
procedure HandleMainScreenButton(Sender: TObject);
private
{ private declarations }
@ -37,25 +44,36 @@ type
end;
var
Form1: TForm1;
formChess: TformChess;
implementation
{$R *.lfm}
{ TForm1 }
{ TformChess }
procedure TForm1.buttonDirectCommClick(Sender: TObject);
begin
notebookMain.PageIndex := 1;
end;
procedure TForm1.HandleMainScreenButton(Sender: TObject);
procedure TformChess.HandleMainScreenButton(Sender: TObject);
begin
if Sender = btnSinglePlayer then
begin
notebookMain.PageIndex := 2;
vChessGame.StartNewGame(comboStartColor.ItemIndex);
end
else if Sender = btnDirectComm then notebookMain.PageIndex := 1;
end;
procedure TformChess.FormCreate(Sender: TObject);
begin
// Creation of internal components
vChessDrawer := TChessDrawer.Create(Self);
vChessDrawer.Parent := pageGame;
vChessDrawer.Top := 20;
vChessDrawer.Left := 20;
vChessDrawer.Height := INT_CHESSBOARD_SIZE;
vChessDrawer.Width := INT_CHESSBOARD_SIZE;
// Loading of resources
vChessDrawer.LoadImages();
end;
end.