⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rook.pas

📁 用于开发税务票据管理的软件
💻 PAS
字号:
unit Rook;

interface

uses
  SysUtils, WinTypes, Classes, Graphics, Piece;

type
 // TRookPtr = ^TRook;
  TRook = 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 TRook.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  if FileExists(FStartDir + 'Pictures\RookW.bmp') then
  begin
    Picture.LoadFromFile(FStartDir + 'Pictures\RookW.bmp');
    Picture.Graphic.Transparent := True;
  end;

  Hint := 'Rook';
  FPrefix := 'R';
  FValue := 6;
end;

function TRook.ValidMove(Where: TPoint): Boolean;
begin
  Result := False;
  if (Where.X in [1..8]) and (Where.Y in [1..8]) then
    { Check for same square move - invalid of course }
    if ((Where.X - FX) or (Where.Y - FY)) <> 0 then
      Result := (Where.X = FX) xor (Where.Y = FY);
end;

function TRook.GetStartingLocation(NumItems: Byte): TPoint;
begin
  if Colour = cWhite then
  begin
    if NumItems = 1 then Result.X := 1 else Result.X := 8;
    Result.Y := 1;
  end
  else
  begin
    if NumItems = 3 then Result.X := 1 else Result.X := 8;
    Result.Y := 8;
  end;
end;

procedure TRook.ChangeColour(NewVal: TColour);
var
  FileName: String;
begin
  inherited ChangeColour(NewVal);
  FileName := FStartDir + 'Pictures\Rook';
  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 + -