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

📄 bishop.pas

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

interface

uses
  SysUtils, WinTypes, Classes, Graphics, Piece;

type
//  TBishopPtr = ^TBishop;
  TBishop = 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 TBishop.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  if FileExists(FStartDir + 'Pictures\bishopW.bmp') then
  begin
    Picture.LoadFromFile(FStartDir + 'Pictures\bishopW.bmp');
    Picture.Graphic.Transparent := True;
  end;

  Hint := 'Bishop';
  FPrefix := 'B';
  FValue := 3;
end;

function TBishop.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
      { Move must be in equal amounts for X and Y... i.e. diagonal }
      DiffX := abs(Where.X - FX);
      DiffY := abs(Where.Y - FY);

      Result := (DiffX = DiffY);
    end;
  end;
end;

{ I realise that this could be done with slightly less code, but this is
  more clear I reckon. }
function TBishop.GetStartingLocation(NumItems: Byte): TPoint;
begin
  if Colour = cWhite then
  begin
    if NumItems = 1 then Result.X := 3 else Result.X := 6;
    Result.Y := 1;
  end
  else
  begin
    if NumItems = 3 then Result.X := 3 else Result.X := 6;
    Result.Y := 8;
  end;
end;

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