Einzelnen Beitrag anzeigen

just.cause

Registriert seit: 28. Apr 2009
8 Beiträge
 
#16

Re: Problem mit "Programm" für die Schule

  Alt 3. Mai 2009, 13:51
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, jpeg;

type
  TForm1 = class(TForm)
    Shape1: TShape;
    Shape2: TShape;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Image1: TImage;
    procedure keypress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }

  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}



procedure TForm1.keypress(Sender: TObject; var Key: Char);
var d:real;
begin
d:=sqrt((shape1.Left - shape2.Left)*(shape1.Left - shape2.Left)+(shape1.Top - shape2.top)*(shape1.Top - shape2.top));
if (key ='s') and (d>=shape1.width) then shape1.top:=shape1.top +10;
if (key ='w') and (d>=shape1.Width) then shape1.top:=shape1.top -10;
if (key ='d') and (d>=shape1.Height) then shape1.Left:=shape1.Left +10;
if (key ='a') and (d>=shape1.Height) then shape1.left:=shape1.left -10;

label1.Caption:=inttostr(shape1.top);
label2.Caption:=inttostr(shape1.Left);

if (key ='k') and (d>=shape1.width)then shape2.top:=shape2.top +10;
if (key ='i') and (d>=shape1.width)then shape2.top:=shape2.top -10;
if (key ='l') and (d>=shape1.Height)then shape2.Left:=shape2.Left +10;
if (key ='j') and (d>=shape1.Height)then shape2.left:=shape2.left -10;

label3.Caption:=inttostr(shape2.top);
label4.Caption:=inttostr(shape2.Left);

end;



procedure TForm1.FormCreate(Sender: TObject);
var d:real;
begin
d:=sqrt((shape1.Left - shape2.Left)*(shape1.Left - shape2.Left)+(shape1.Top - shape2.top)*(shape1.Top - shape2.top));
if (d>=shape1.width) or (d>=shape1.height) then showmessage ('tagged!');
end;

end.
[edit=mkinzler]Delphi-Tag ergänzt. das nächste Mal bitte selber machen. Mfg, mkinzler[/edit]
  Mit Zitat antworten Zitat