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:
| unit puzzel; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,ExtCtrls, StdCtrls, Buttons; type Tklotz=class(Timage) private FRelPosX,Fzug: Integer; FRelPosY: Integer; protected public procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);override; procedure MouseMove(Shift: TShiftState; X, Y: Integer);override; procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);override; end; TForm1 = class(TForm) Button1: TButton; BitBtn1: TBitBtn; Label1: TLabel; procedure FormCreate(Sender: TObject); procedure BitBtn1Click(Sender: TObject); private klotz,grund,klotz3:tklotz;eck:array[1..9]of Tklotz;SetTag:byte; public end; const lage:array[1..7,1..2]of byte=((105,200),(0,50),(100,50),(50,100),(150,100),(100,150),(0,0));
var Form1: TForm1;_Tag:byte;
implementation
{$R *.dfm}
procedure Tklotz.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin inherited MouseMove(Shift, X, Y); FRelPosX := X; FRelPosY := Y; end; procedure Tklotz.MouseMove(Shift: TShiftState;X, Y: Integer); begin inherited MouseMove(Shift, X, Y); if (ssLeft in Shift)then SetBounds(Left+X-FRelPosX, Top+Y-FRelPosY,Width, Height); end; procedure Tklotz.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin inherited MouseUp(Button, Shift, X, Y); if tag<>0 then begin SetBounds(round(left/50)*50 ,round(top/50)*50,Width, Height); bringtofront;inc(fzug);end; form1.label1.caption:=inttostr(tag); end;
procedure TForm1.FormCreate(Sender: TObject); var i,h:byte; begin Form1.DoubleBuffered := true;randomize;SetTag:=0; grund:=Tklotz.create(self);grund.Parent:=self;grund.Tag:=0; grund.Transparent:=false; grund.Stretch:=true;grund.SetBounds(0,0,250,250); grund.Picture.LoadFromFile('Hintergrund.bmp');
klotz:=Tklotz.Create(self); klotz.parent:=self;klotz.transparent:=true; klotz.Left:=150;klotz.top:=0;klotz.Tag:=1; klotz.Canvas.font.color:=clwhite; klotz.Canvas.Brush.Color:=clred; klotz.Canvas.polygon([point(0,0),point(100,0),point(100,100),point(50,100),point(50,50),point(0,50)]); klotz.canvas.TextOut(60,60,'1');
klotz3:=Tklotz.Create(self); klotz3.Parent:=self;klotz3.Tag:=2; klotz3.Left:=0;klotz3.top:=100; klotz3.Canvas.Brush.Color:=clblue; klotz3.Canvas.polygon([point(0,0),point(50,0),point(50,50),point(100,50),point(100,100),point(0,100)]); klotz3.Canvas.font.color:=clwhite; klotz3.canvas.TextOut(60,60,'2'); klotz3.Transparent:=true;
for i:=1 to 7 do begin eck[i]:=tklotz.create(self); eck[i].Parent:=self;eck[i].height:=50;eck[i].tag:=i+2; eck[i].width:=50;h:=50;eck[i]. Transparent:=false; if i>1 then begin eck[i].width:=100;h:=100;end; if i>5 then begin eck[i].width:=150;h:=150;end; eck[i].Canvas.Brush.Color:=random($FFFFFF); eck[i].Canvas.rectangle(0,0,h,50); eck[i].Canvas.textout(30,20,inttostr(i+2)); eck[i].Left:=lage[i,1]; eck[i].top:=lage[i,2]; end;
end; procedure TForm1.BitBtn1Click(Sender: TObject); var i:byte; begin for i:=1 to 7 do eck[i].Free; klotz.Free;grund.Free;klotz3.Free; end;
end.
|