Einzelnen Beitrag anzeigen

Patrick L.

Registriert seit: 22. Mär 2009
10 Beiträge
 
FreePascal / Lazarus
 
#23

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

  Alt 4. Mai 2009, 16:35
Ich hab mal was geschrieben.

Delphi-Quellcode:
...
var
  akSp: integer=1;
  pkSp: array [1..2] of integer;
  run: boolean=true;

implementation

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
VAR Select:integer;
begin
if Run=true then
begin
  case Key of
  's': shape1.top:=shape1.top+10;
  'w': shape1.top:=shape1.top-10;
  'd': shape1.Left:=shape1.Left+10;
  'a': shape1.left:=shape1.left-10;
  'k': shape2.top:=shape2.top+10;
  'i': shape2.top:=shape2.top-10;
  'l': shape2.Left:=shape2.Left+10;
  'j': shape2.left:=shape2.left-10;
  end;

rungame;
end
Else
begin
Select:=MessageDlg('Sie wurden gefangen! Möchten Sie weiter spielen?',mtConfirmation,[mbYes,mbNo],0);
  case Select of
  mrYes: begin
          Shape1.Top:=128;
          Shape1.Left:=144;
          Shape2.Top:=128;
          Shape2.Left:=416;
          Run:=true;
          end;
  mrNo: close;
  end;
end;
end;

procedure TForm1.RunGame;
var abstand:real;
x1,y1,x2,y2:real;
begin
x1:=Shape1.Left+Shape1.Width/2;
x2:=Shape2.Left+Shape2.Width/2;
y1:=Shape1.Top+Shape1.Height/2;
y2:=Shape2.Top+Shape2.Height/2;
abstand:=sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))-105;
 if abstand<0 then
  begin
  pkSp[akSp]:=pkSp[akSp]+1;
  Label4.Caption:=inttostr(pkSp[1])+':'+inttostr(PkSp[2]);
  run:=false;
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
akSP:=setGegner(akSp);
end;

function TForm1.setGegner(aksp:integer):integer;
begin
if aksp=1 then result:=2
else result:=1;
Label3.Caption:='Spieler '+inttostr(result)+' du bist dran!';
end;
Leider weiß ich noch nicht, wie man die Kreise zur gleichen Zeit steuern kann. Vielleicht mit GetAsyncKeystate() und einer Procedure die immer wieder aufgerufen wird.
Angehängte Dateien
Dateityp: exe project_157.exe (648,0 KB, 7x aufgerufen)
Patrick
  Mit Zitat antworten Zitat