Advertisement
Guest User

Untitled

a guest
Feb 12th, 2015
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.36 KB | None | 0 0
  1. unit mFeld;
  2.  
  3. interface
  4.  
  5. uses Graphics,ExtCtrls,Forms,Controls,Types,mEinheit;
  6.  
  7. type TFeld=class(TPanel)
  8.   protected
  9.     procedure Paint;override;
  10.   private
  11.     zSichtbar : Boolean;
  12.     zPosHor,zPosVer : Integer; // Position im Array
  13.     zEinheit  : TEinheit;
  14.   public
  15.  
  16. //    hImage    : TImage;
  17.  
  18.     constructor Create(pX,pPosHor,pY,pPosVer,pHoehe,pBreite:integer;pImgPath:String;pForm:Tform); virtual;
  19.     procedure setSichtbar; virtual;
  20.     procedure setUnsichtbar; virtual;
  21.     procedure setEinheit(pEinheit:TEinheit);
  22.     procedure removeEinheit;
  23.     function hasEinheit:Boolean;
  24.     function getEinheit:TEinheit;
  25.     function istSichtbar:boolean;
  26.     function getPosHor : Integer;
  27.     function getPosVer : Integer;
  28.     procedure SetImageEventHandler;
  29.     procedure drawImg;
  30.  
  31.   end;
  32.  
  33.  
  34.  
  35.  
  36. implementation
  37.  
  38. constructor TFeld.Create(pX,pPosHor,pY,pPosVer,pHoehe,pBreite:integer;pImgPath:String;pForm:Tform);
  39. begin
  40.   inherited create(pForm);
  41. //  self.BevelInner := bvNone;  //Hides Borders, off for dev/debugging
  42. //  self.BevelOuter := bvNone;
  43.   self.Parent:=pForm;
  44.   self.Top:=pY;
  45.   self.Left:=pX;
  46.   self.Width:=pBreite;
  47.   self.Height:=pHoehe;
  48.  
  49.  
  50. {  hImage := TImage.Create(pForm);
  51.   hImage.parent:=Self;
  52.   hImage.Picture.LoadFromFile(pImgPath);
  53.   hImage.Stretch:=false;
  54.   hImage.Width:=pBreite;
  55.   hImage.Height:=pHoehe;
  56.   hImage.Visible:=false;}
  57.  
  58.   zPosHor := pPosHor;
  59.   zPosVer := pPosVer;
  60.  
  61.   setUnsichtbar;
  62.  
  63.   zEinheit := nil;
  64. end;
  65.  
  66.  
  67. procedure TFeld.Paint;
  68. var bmp : TBitmap;
  69. begin
  70.   inherited;
  71.   bmp := TBitmap.Create;
  72.   try
  73.     bmp.LoadFromFile('textures\ground.bmp');
  74.     self.Canvas.Draw(0,0,bmp);
  75.   finally
  76.     bmp.Free;
  77.   end;
  78. end;
  79.  
  80.  
  81. procedure TFeld.SetImageEventHandler;
  82. begin
  83. //  hImage.OnClick := self.OnClick;
  84. end;
  85.  
  86. procedure TFeld.drawImg;
  87. var bmp : TBitmap;
  88. begin
  89.   bmp := TBitmap.Create;
  90.   try
  91.     bmp.LoadFromFile('textures\ground.bmp');
  92.     Canvas.Draw(0,0,bmp);
  93.   finally
  94.     bmp.Free;
  95.   end;
  96.   Canvas.Refresh;
  97. end;
  98.  
  99.  
  100. procedure TFeld.setSichtbar;
  101. begin
  102.   zSichtbar:=true;
  103.   self.Color := clWhite;
  104. //  hImage.Visible := True;
  105. //  self.Caption:='X';
  106. end;
  107.  
  108. procedure TFeld.setUnsichtbar;
  109. var bmp : TBitmap;
  110. begin
  111.   bmp := TBitmap.Create;
  112.   try
  113.     bmp.LoadFromFile('textures\invisible.bmp');
  114.     self.Canvas.Draw(0,0,bmp);
  115.   finally
  116.     bmp.Free;
  117.   end;
  118.  
  119.   zSichtbar:=false;
  120.   self.Color := clGray;
  121.   self.Caption:='';
  122. //  hImage.Visible := False;
  123. end;
  124.  
  125. function TFeld.istSichtbar:Boolean;
  126. begin
  127.   Result := zSichtbar;
  128. end;
  129.  
  130. function TFeld.hasEinheit:Boolean;
  131. begin
  132.   if zEinheit <> nil then begin
  133.     Result := True;
  134.   end else begin
  135.     Result := False;
  136.   end;
  137. end;
  138.  
  139. function TFeld.getEinheit:TEinheit;
  140. begin
  141.   Result := zEinheit
  142. end;
  143.  
  144. procedure TFeld.setEinheit(pEinheit:TEinheit);
  145. var typ : String;
  146. begin
  147.  
  148.   zEinheit:=pEinheit;
  149.  
  150.   typ := zEinheit.getType;
  151.  
  152.   if typ = 'tank' then begin
  153.     self.Caption := 'T';
  154.   end else if typ = 'melee' then begin
  155.     self.Caption := 'M';
  156.   end else if typ = 'ranged' then begin
  157.     self.Caption := 'R';
  158.   end else if typ = 'scout' then begin
  159.     self.Caption := 'S';
  160.   end;
  161.  
  162. end;
  163.  
  164. procedure TFeld.removeEinheit;
  165. begin
  166.   zEinheit := nil;
  167.   self.Caption := '';
  168. end;
  169.  
  170. function TFeld.getPosHor:Integer;
  171. begin
  172.   Result := zPosHor
  173. end;
  174.  
  175. function TFeld.getPosVer:Integer;
  176. begin
  177.   Result := zPosVer
  178. end;
  179.  
  180.  
  181.  
  182.  
  183. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement