unit pong01;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Grids;
type
TForm1 =
class(TForm)
schlaeger_1: TShape;
schlaeger_2: TShape;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
ball: TShape;
Timer1: TTimer;
Timer2: TTimer;
Shape1: TShape;
Timer3: TTimer;
Label4: TLabel;
procedure FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
procedure FormShow(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer3Timer(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
uses pong02;
{$R *.dfm}
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
var
buffer_schlaeger_1, buffer_schlaeger_2 : char;
begin
//Schläger 1
//
//Abfrage, ob Taste gedrückt wurde (Schläger 1)
case Key
of
Word('
W') : buffer_schlaeger_1 := '
1';
Word('
S') : buffer_schlaeger_1 := '
2';
end;
//Bewegungen von Schläger 1
case buffer_schlaeger_1
of
'
1' : schlaeger_1.top := schlaeger_1.top - 2;
'
2' : schlaeger_1.top := schlaeger_1.top + 2;
end;
//Schläger 2
//
//Abfrage, ob Taste gedrückt wurde (Schläger 2)
case Key
of
Word(VK_UP) : buffer_schlaeger_2 := '
1';
Word(VK_DOWN) : buffer_schlaeger_2 := '
2';
end;
//Bewegungen von Schläger 2
case buffer_schlaeger_2
of
'
1' : schlaeger_2.top := schlaeger_2.top - 2;
'
2' : schlaeger_2.top := schlaeger_2.top + 2;
end;
if schlaeger_1.Top = 4
then
begin
schlaeger_1.top := 6;
end;
if schlaeger_1.Top = 264
then
begin
schlaeger_1.top := 262;
end;
if schlaeger_2.Top = 4
then
begin
schlaeger_2.top := 6;
end;
if schlaeger_2.Top = 264
then
begin
schlaeger_2.top := 262;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
//
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
ball.Left := ball.Left + 8;
ball.Top := ball.top - 8;
label1.caption := IntToStr(ball.left);
label2.Caption := IntToStr(ball.top);
if ball.Top <= 0
then
begin
timer1.enabled := false;
timer2.enabled := true;
end;
If ((ball.left) >= (Schlaeger_2.left))
and ((ball.top) >= (Schlaeger_2.top))
and ((ball.top) <= (Schlaeger_2.top+Schlaeger_2.Width))
then
begin
ball.Left := ball.Left + 8;
ball.Top := ball.top - 8;
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var
bereich : double;
v : integer;
begin
v := 6;
ball.Left := ball.left + 8;
ball.top := ball.top + 8;
label1.caption := IntToStr(ball.left);
label2.Caption := IntToStr(ball.top);
if ball.Top >= 340
then
begin
timer1.enabled := true;
timer2.enabled := false;
end;
if ball.left >= 800
then
begin
form2.show;
timer1.enabled := false;
timer2.enabled := false;
end;
if ball.left <= 50
then
begin
form2.show;
timer1.enabled := false;
timer2.enabled := false;
end;
end;
procedure TForm1.Timer3Timer(Sender: TObject);
var
x, y : double;
begin
x := schlaeger_2.top;
y := schlaeger_2.left;
label4.caption := FloatToStr(x) + '
' + FloatToStr(y);
if (ball.top >= schlaeger_2.Top)
and (ball.Top <= (schlaeger_2.Top + schlaeger_2.Height))
and (ball.Left >= schlaeger_2.Left)
and (ball.Left <= (schlaeger_2.Left + schlaeger_2.Width))
then
begin
form2.Show;
//einfach irgendwas machen
end;
end;
end.