www.pudn.com > 200589952618.rar > Diamonds.pas


unit diamonds; 
 
interface 
type 
  TDiamonds = class 
  public 
    FStatus: Byte; 
    FX, FY: Integer; 
  public 
    constructor Create; 
    procedure Rotate; 
    procedure Move(DX: Integer); 
    function Drop: Boolean; 
    procedure Draw; 
    function IsOver: Boolean; 
  end; 
implementation 
uses 
  Main; 
 
constructor TDiamonds.Create; 
begin 
  FX := 4; 
  FY := 0; 
  FStatus := 0; 
  if not IsOver then 
    Draw; 
end; 
 
function TDiamonds.IsOver: Boolean; 
begin 
  if (BG[FX, FY] <> 0) or (BG[FX + 1, FY] <> 0) or 
    (BG[FX + 1, FY] <> 0) or (BG[FX + 1, FY + 1] <> 0) then 
    Result := True 
  else 
    Result := False; 
end; 
 
function TDiamonds.Drop: Boolean; 
begin 
  if FY >= 18 then 
  begin 
    Result := False; 
  end 
  else if (BG[FX, FY + 2] = 0) and (BG[FX + 1, FY + 2] = 0) then 
  begin 
    FY := FY + 1; 
    Draw; 
    Result := True; 
  end 
  else 
    Result := False; 
  if not Result then 
  begin 
    BG[FX, FY] := 2; 
    BG[FX, FY + 1] := 2; 
    BG[FX + 1, FY] := 2; 
    BG[FX + 1, FY + 1] := 2; 
  end; 
end; 
 
procedure TDiamonds.Move(DX: Integer); 
begin 
  if (FX + DX >= 0) and (FX + DX <= 8) then 
  begin 
    if (BG[FX + DX, FY] = 0) and 
      (BG[FX + DX, FY + 1] = 0) and 
      (BG[FX + DX + 1, FY] = 0) and 
      (BG[FX + DX + 1, FY + 1] = 0) then 
      FX := FX + DX; 
  end; 
  Draw; 
end; 
 
procedure TDiamonds.Draw; 
begin 
  FillChar(FG, 200, #0); 
  FG[Fx, 0 + Fy] := 2; 
  FG[Fx, 1 + Fy] := 2; 
  FG[Fx + 1, Fy] := 2; 
  FG[Fx + 1, 1 + Fy] := 2; 
end; 
 
procedure TDiamonds.Rotate; 
begin 
{} 
end; 
 
 
end.