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


unit rcrutch; 
 
interface 
type 
  TRCurtch = 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 TRCurtch.Create; 
begin 
  FX := 4; 
  FY := 0; 
  FStatus := 0; 
  if not IsOver then 
    Draw; 
end; 
 
function TRCurtch.IsOver: Boolean; 
begin 
  if (BG[FX, FY] <> 0) or (BG[FX + 1, FY] <> 0) or 
    (BG[FX + 2, FY] <> 0) or (BG[FX + 2, FY + 1] <> 0) then 
    Result := True 
  else 
    Result := False; 
end; 
 
function TRCurtch.Drop: Boolean; 
begin 
  case FStatus of 
    0: begin 
        if FY >= 18 then 
        begin 
          Result := False; 
        end 
        else if (BG[FX, FY + 1] = 0) and (BG[FX + 1, FY + 1] = 0) and (BG[FX + 2, FY + 2] = 0) then 
        begin 
          FY := FY + 1; 
          Draw; 
          Result := True; 
        end 
        else 
          Result := False; 
        if not Result then 
        begin 
          BG[FX, FY] := 5; 
          BG[FX + 1, FY] := 5; 
          BG[FX + 2, FY] := 5; 
          BG[FX + 2, FY + 1] := 5; 
        end; 
      end; 
    1: begin 
        if FY >= 17 then 
        begin 
          Result := False; 
        end 
        else if (BG[FX, FY + 3] = 0) and (BG[FX + 1, FY + 1] = 0) then 
        begin 
          FY := FY + 1; 
          Draw; 
          Result := True; 
        end 
        else 
          Result := False; 
        if not Result then 
        begin 
          BG[FX, FY] := 5; 
          BG[FX, FY + 1] := 5; 
          BG[FX, FY + 2] := 5; 
          BG[FX + 1, FY] := 5; 
        end; 
      end; 
    2: begin 
        if FY >= 17 then 
        begin 
          Result := False; 
        end 
        else if (BG[FX, FY + 3] = 0) and (BG[FX + 1, FY + 3] = 0) and (BG[FX + 2, FY + 3] = 0) then 
        begin 
          FY := FY + 1; 
          Draw; 
          Result := True; 
        end 
        else 
          Result := False; 
        if not Result then 
        begin 
          BG[FX, FY + 2] := 5; 
          BG[FX + 1, FY + 2] := 5; 
          BG[FX + 2, FY + 2] := 5; 
          BG[FX, FY + 1] := 5; 
        end; 
      end; 
    3: begin 
        if FY >= 17 then 
        begin 
          Result := False; 
        end 
        else if (BG[FX + 1, FY + 3] = 0) and (BG[FX + 2, FY + 3] = 0) then 
        begin 
          FY := FY + 1; 
          Draw; 
          Result := True; 
        end 
        else 
          Result := False; 
        if not Result then 
        begin 
          BG[FX + 2, FY] := 5; 
          BG[FX + 2, FY + 1] := 5; 
          BG[FX + 2, FY + 2] := 5; 
          BG[FX + 1, FY + 2] := 5; 
        end; 
      end; 
  else 
    Result := False; 
  end; 
end; 
 
procedure TRCurtch.Move(DX: Integer); 
begin 
  case FStatus of 
    0: begin 
        if (FX + DX >= 0) and (FX + DX <= 7) 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 + 2, FY + 1] = 0) then 
            FX := FX + DX; 
        end; 
      end; 
    1: 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, FY + 2] = 0) and 
            (BG[FX + DX + 1, FY] = 0) then 
            FX := FX + DX; 
        end; 
      end; 
    2: begin 
        if (FX + DX >= 0) and (FX + DX <= 7) then 
        begin 
          if (BG[FX + DX, FY + 2] = 0) and (BG[FX + DX + 1, FY + 2] = 0) and 
            (BG[FX + DX + 2, FY + 2] = 0) and (BG[FX + DX, FY + 1] = 0) then 
            FX := FX + DX; 
        end; 
      end; 
    3: begin 
        if (FX + DX + 1 >= 0) and (FX + DX <= 7) then 
        begin 
          if (BG[FX + DX + 2, FY] = 0) and 
            (BG[FX + DX + 2, FY + 1] = 0) and 
            (BG[FX + DX + 2, FY + 2] = 0) and 
            (BG[FX + DX + 1, FY + 2] = 0) then 
            FX := FX + DX; 
        end; 
      end; 
  end; 
  Draw; 
end; 
 
procedure TRCurtch.Draw; 
begin 
  FillChar(FG, 200, #0); 
  case FStatus of 
    0: begin 
        FG[FX, FY] := 5; 
        FG[FX + 1, FY] := 5; 
        FG[FX + 2, FY] := 5; 
        FG[FX + 2, FY + 1] := 5; 
      end; 
    1: begin 
        FG[FX, FY] := 5; 
        FG[FX, FY + 1] := 5; 
        FG[FX, FY + 2] := 5; 
        FG[FX + 1, FY] := 5; 
      end; 
    2: begin 
        FG[FX, FY + 2] := 5; 
        FG[FX + 1, FY + 2] := 5; 
        FG[FX + 2, FY + 2] := 5; 
        FG[FX, FY + 1] := 5; 
      end; 
    3: begin 
        FG[FX + 2, FY] := 5; 
        FG[FX + 2, FY + 1] := 5; 
        FG[FX + 2, FY + 2] := 5; 
        FG[FX + 1, FY + 2] := 5; 
      end; 
  end; 
end; 
 
procedure TRCurtch.Rotate; 
begin 
  case FStatus of 
    0: if (FY <= 17) then 
      begin 
        if (BG[FX, FY + 2] = 0) and (BG[FX, FY + 1] = 0) then 
          FStatus := 1; 
      end; 
    1: if (FX <= 7) then 
      begin 
        if (BG[FX + 1, FY + 2] = 0) and (BG[FX + 2, FY + 2] = 0) then 
          FStatus := 2; 
      end; 
    2: if (FY > 0) then 
      begin 
        if (BG[FX + 2, FY] = 0) and (BG[FX + 2, FY + 1] = 0) then 
          FStatus := 3; 
      end; 
    3: if (FX >= 0) then 
      begin 
        if (BG[FX, FY] = 0) and (BG[FX + 1, FY] = 0) then 
          FStatus := 0; 
      end; 
  end; 
  Draw; 
end; 
end.