rectactionunit.pas 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. unit rectactionunit;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, mapactionunit, mapchangeunit;
  6. type
  7. { TRectAction }
  8. TRectAction = class(TMapAction)
  9. private
  10. StartX, StartY: Integer;
  11. MapChange: TMapChange;
  12. function GetMapChange: TMapChange; override;
  13. public
  14. constructor Create;
  15. procedure Start(X, Y); virtual; override;
  16. procedure Continue(X, Y); virtual; override;
  17. destructor Destroy; override;
  18. end;
  19. implementation
  20. uses
  21. Math;
  22. { TRectAction }
  23. function TRectAction.GetMapChange: TMapChange;
  24. begin
  25. GetMapChange := MapChange;
  26. end;
  27. constructor TRectAction.Create;
  28. begin
  29. MapChange := TMapChange.Create;
  30. end;
  31. procedure TRectAction.Start(X, Y);
  32. begin
  33. StartX := X;
  34. StartY := Y;
  35. end;
  36. procedure TRectAction.Continue(X, Y);
  37. begin
  38. MapChange.Left := Max(0, StartX - 1);
  39. MapChange.Top := Max(0, StartY - 1);
  40. MapChange.Right := Min(X + 1, Map.Integers['width'] - 1);
  41. MapChange.Bottom := Min(Y + 1, Map.Integers['height'] - 1);
  42. end;
  43. destructor TRectAction.Destroy;
  44. begin
  45. MapChange.Free;
  46. inherited Destroy;
  47. end;
  48. end.