📄 knight.pas
字号:
unit Knight;
interface
uses
SysUtils, WinTypes, Classes, Graphics, Piece;
type
// TKnightPtr = ^TKnight;
TKnight = class(TPiece)
private
{ Private declarations }
protected
{ Protected declarations }
procedure ChangeColour(NewVal: TColour); override;
function GetStartingLocation(NumItems: Byte): TPoint; override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
function ValidMove(Where: TPoint): Boolean; override;
published
{ Published declarations }
end;
implementation
constructor TKnight.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
if FileExists(FStartDir + 'Pictures\KnightW.bmp') then
begin
Picture.LoadFromFile(FStartDir + 'Pictures\KnightW.bmp');
Picture.Graphic.Transparent := True;
end;
Hint := 'Knight';
FPrefix := 'N';
FValue := 3;
end;
function TKnight.ValidMove(Where: TPoint): Boolean;
var
DiffX: Integer;
DiffY: Integer;
begin
Result := False;
if (Where.X in [1..8]) and (Where.Y in [1..8]) then
begin
{ Check for same square move }
if ((Where.X - FX) or (Where.Y - FY)) <> 0 then
begin
DiffX := abs(Where.X - FX);
DiffY := abs(Where.Y - FY);
{ For legal move, horsey should move 1 square X and 2 Y, or vice versa }
Result := ((DiffX = 1) and (DiffY = 2)) or ((DiffY = 1) and (DiffX = 2));
end;
end;
end;
function TKnight.GetStartingLocation(NumItems: Byte): TPoint;
begin
if Colour = cWhite then
begin
if NumItems = 1 then Result.X := 2 else Result.X := 7;
Result.Y := 1;
end
else
begin
if NumItems = 3 then Result.X := 2 else Result.X := 7;
Result.Y := 8;
end;
end;
procedure TKnight.ChangeColour(NewVal: TColour);
var
FileName: String;
begin
inherited ChangeColour(NewVal);
FileName := FStartDir + 'Pictures\Knight';
if FPlayer = cBlack then
FileName := FileName + 'B.bmp'
else
FileName := FileName + 'W.bmp';
if FileExists(FileName) then
begin
Picture.LoadFromFile(FileName);
Picture.Graphic.Transparent := True;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -