1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288:
| mHaus (Main): unit mHaus;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, mGebaeude, mSonne, mZeichenfenster;
type TMain = class(TForm) BtHaus: TButton; BtLichtAnAus: TButton; BtTuerAufZu: TButton; procedure BtHausClick(Sender: TObject); procedure BtLichtAnAusClick(Sender: TObject); procedure BtTuerAufZuClick(Sender: TObject);
private ZF: TZeichenFenster; Haus : THaus; Sonne: TSonne; public
end;
var Main: TMain;
implementation
{$R *.dfm}
procedure TMain.BtHausClick(Sender: TObject); begin ZF := TZeichenFenster.Create (Main); ZF.Show;
Haus := THaus.Create(ZF,50,300,100); Haus.Zeichnen;
Sonne := TSonne.Create (ZF); Sonne.Parent := ZF; Sonne.Show;
end;
procedure TMain.BtLichtAnAusClick(Sender: TObject); begin if Haus.IstLichtAn = False then Haus.LichtAn else Haus.LichtAus; end;
procedure TMain.BtTuerAufZuClick(Sender: TObject); begin if Haus.IstTuerAuf = False then Haus.TuerAuf else Haus.TuerZu; end;
end.
mSonne:
unit mSonne;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type TSonne = class (TShape)
private
protected
public constructor Create (AOwner: TComponent); override;
end;
implementation
constructor TSonne.Create (AOwner: TComponent); begin inherited Create (AOwner); Brush.Color := clYellow; SetBounds (185,60,66,66); Shape := stCircle; end;
end.
mZeichenFenster
unit mZeichenFenster;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type TZeichenFenster = class(TForm) private
public Constructor Create (AOwner: TComponent); override; end;
var ZeichenFenster: TZeichenFenster;
implementation
{$R *.dfm}
Constructor TZeichenFenster.Create (AOwner: TComponent); begin inherited Create (Aowner); Brush.Color := clWhite; SetBounds (550, 121, 340, 340); end;
end.
mGebaeude (Haus deklariert)
unit mGebaeude;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, mZeichenFenster;
type THaus = class(TObject) private zX,zY,zBreite : Integer; zLichtAn, zTuerAuf : Boolean; kZF: TZeichenFenster;
protected procedure WandZeichnen; procedure TuerZeichnen( Farbe : TColor); procedure FensterZeichnen( Farbe : TColor); procedure DachZeichnen;
public constructor Create(ZF: TZeichenFenster; X, Y, Breite : Integer); procedure Zeichnen; procedure LichtAn; procedure LichtAus; procedure TuerAuf; procedure TuerZu; function IstTuerAuf : Boolean; function IstLichtAn : Boolean;
end;
implementation
constructor THaus.Create(ZF: TZeichenfenster; X, Y, Breite : Integer); begin zX := X; zY := Y; zBreite := Breite; zLichtAn := False; zTuerAuf := False; kZF := ZF end;
procedure THaus.Zeichnen; begin kZF.Canvas.Pen.Color := clBlack; WandZeichnen; DachZeichnen; FensterZeichnen(cl3DDkShadow); TuerZeichnen(clRed); end;
procedure THaus.WandZeichnen; begin kZF.Canvas.Brush.Color := clGray; kZF.Canvas.Rectangle(zX, round (zY - zBreite), round (zX + zBreite), zY); end;
procedure THaus.TuerZeichnen(Farbe : TColor); begin kZF.Canvas.Brush.Color := Farbe; kZF.Canvas.Rectangle(round (zX + zBreite * 0.2), round (zY - zBreite * 0.4), round(zX + zBreite * 0.4), zY); end;
procedure THaus.FensterZeichnen(Farbe : TColor); begin kZF.Canvas.Brush.Color := Farbe; kZF.Canvas.Rectangle (round (zX + zBreite * 0.6), round (zY - zBreite * 0.4), round (zX + zBreite * 0.8), round (zY - zBreite * 0.2)); kZF.Canvas.Rectangle (round (zX + zBreite * 0.2), round (zY - zBreite * 0.8), round (zX + zBreite * 0.4), round (zY - zBreite * 0.6)); kZF.Canvas.Rectangle (round (zX + zBreite * 0.6), round (zY - zBreite * 0.8), round (zX + zBreite * 0.8), round (zY - zBreite * 0.6)); end;
procedure THaus.DachZeichnen; begin kZF.Canvas.Brush.Color := clRed; kZF.Canvas.Polygon([Point (zX, round (zY - zBreite)), Point (round (zX + zBreite - 1), round (zY - zBreite)), Point (round (zX + zBreite * 0.5), round (zY - zBreite * 1.3))]); end;
procedure THaus.LichtAn; begin FensterZeichnen(clYellow); zLichtAn := True; end;
procedure THaus.LichtAus; begin FensterZeichnen(cl3DDkShadow); zLichtAn := False; end;
procedure THaus.TuerAuf; begin TuerZeichnen(cl3DDkShadow); zTuerAuf := True end;
procedure THaus.TuerZu; begin TuerZeichnen(clRed); zTuerAuf := False; end;
function THaus.IstTuerAuf : Boolean; begin IstTuerAuf := zTuerAuf; end;
function THaus.IstLichtAn : Boolean; begin IstLichtAn := zLichtAn; end;
end. |