www.pudn.com > 200589952618.rar > STICK.PAS


unit stick; 
 
interface 
type 
  TStick = 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 TStick.Create; 
begin 
  FX := 3; 
  FY := 1; 
  FStatus := 1; 
  if not IsOver then 
    Draw; 
end; 
 
function TStick.IsOver: Boolean; 
begin 
  if (BG[FX, FY] <> 0) or (BG[FX + 1, FY] <> 0) or 
    (BG[FX + 2, FY] <> 0) or (BG[FX + 3, FY] <> 0) then 
    Result := True 
  else 
    Result := False; 
end; 
 
function TStick.Drop: Boolean; 
begin 
  if (FStatus = 0) then 
  begin 
    if FY >= 16 then 
    begin 
      Result := False; 
    end 
    else if (BG[FX, FY + 4] = 0) then 
    begin 
      FY := FY + 1; 
      Draw; 
      Result := True; 
    end 
    else 
      Result := False; 
    if not Result then 
    begin 
      BG[FX, FY] := 1; 
      BG[FX, FY + 1] := 1; 
      BG[FX, FY + 2] := 1; 
      BG[FX, FY + 3] := 1; 
    end; 
  end 
  else 
  begin 
    if FY >= 19 then 
    begin 
      Result := False; 
    end 
    else if (BG[FX, FY + 1] = 0) and (BG[FX + 1, FY + 1] = 0) and 
      (BG[FX + 2, FY + 1] = 0) and (BG[FX + 3, FY + 1] = 0) then 
    begin 
      FY := FY + 1; 
      Draw; 
      Result := True; 
    end 
    else 
      Result := False; 
    if not Result then 
    begin 
      BG[FX, FY] := 1; 
      BG[FX + 1, FY] := 1; 
      BG[FX + 2, FY] := 1; 
      BG[FX + 3, FY] := 1; 
    end; 
  end; 
end; 
 
procedure TStick.Move(DX: Integer); 
begin 
  if (FStatus = 0) then 
  begin 
    if (FX + DX >= 0) and (FX + DX <= 9) then 
    begin 
      if (BG[FX + DX, FY] = 0) and 
        (BG[FX + DX, FY + 1] = 0) and 
        (BG[FX + DX, FY + 2] = 0) and 
        (BG[FX + DX, FY + 3] = 0) then 
        FX := FX + DX; 
    end; 
  end 
  else 
  begin 
    if (FX + DX >= 0) and (FX + DX <= 6) then 
    begin 
      if (BG[FX + DX, FY] = 0) and 
        (BG[FX + DX + 1, FY] = 0) and 
        (BG[FX + DX + 2, FY] = 0) and 
        (BG[FX + DX + 3, FY] = 0) then 
        FX := FX + DX; 
    end; 
  end; 
  Draw; 
end; 
 
procedure TStick.Draw; 
begin 
  FillChar(FG, 200, #0); 
  if (FStatus = 0) then 
  begin 
    FG[Fx, 0 + Fy] := 1; 
    FG[Fx, 1 + Fy] := 1; 
    FG[Fx, 2 + Fy] := 1; 
    FG[Fx, 3 + Fy] := 1; 
  end 
  else 
  begin 
    FG[Fx, Fy] := 1; 
    FG[Fx + 1, Fy] := 1; 
    FG[Fx + 2, Fy] := 1; 
    FG[Fx + 3, Fy] := 1; 
  end; 
end; 
 
procedure TStick.Rotate; 
var 
  X, Y: Integer; 
begin 
  case FStatus of 
    0: if (FX > 0) and (FX < 8) then 
      begin 
        X := FX - 1; 
        Y := FY + 1; 
        if (BG[X, Y] = 0) and (BG[X + 1, Y] = 0) and (BG[X + 2, Y] = 0) and (BG[X + 3, Y] = 0) then 
        begin 
          FX := X; 
          FY := Y; 
          FStatus := 1; 
        end; 
      end; 
    1: if (FY > 0) and (FY < 18) then 
      begin 
        X := FX + 1; 
        Y := FY - 1; 
        if (BG[X, Y] = 0) and (BG[X, Y + 1] = 0) and (BG[X, Y + 2] = 0) and (BG[X, Y + 3] = 0) then 
        begin 
          FX := X; 
          FY := Y; 
          FStatus := 0; 
        end; 
      end; 
  end; 
  Draw; 
end; 
 
end.