unit Pong;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 =
class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure FormKeyPress(Sender: TObject;
var Key: Char);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
dicke, x, y: integer;
implementation
{$R *.dfm}
procedure TForm1.FormKeyPress(Sender: TObject;
var Key: Char);
begin
dicke := 20;
if key = '
s'
then begin // Bewegung nach unten
form1.Refresh;
y := y+10;
end;
if key = '
d'
then begin // Bewegung nach rechts
form1.Refresh;
x := x+10;
end;
if key = '
a'
then begin // Bewegung nach links
form1.Refresh;
x := x-10;
end;
if key = '
w'
then begin // Bewegung nach oben
form1.Refresh;
y := y-10;
end;
If x < 0
Then x := 0;
// Spielfeldbegrenzungen
If x > clientwidth - dicke
Then x := clientwidth - dicke;
If y < 0
Then y := 0;
If y > clientheight - dicke
Then y := clientheight- dicke;
if (x = 40)
and ((y < 350)
or (y > 380))
then x := 30;
// Stoppen des Balles an Barikaden
if (x = 90)
and ((y < 50)
or (y > 80))
then x := 80;
if (x = 140)
and ((y < 200)
or (y > 230))
then x := 130;
if (x = 190)
and ((y < 400)
or (y > 430))
then x := 180;
if ((x > 380)
and (x < 450))
and ((y > 180)
and (y < 250))
then Label3.Caption := '
sieger';
// Betreten des Zielfeldes
canvas.MoveTo(50,0);
// Barrikaden
canvas.lineto(50,350);
canvas.MoveTo(50,400);
canvas.lineto(50,clientheight);
canvas.moveto(100,0);
canvas.LineTo(100,50);
canvas.moveto(100,100);
canvas.Lineto(100,clientheight);
canvas.moveto(150,0);
canvas.LineTo(150,200);
canvas.moveto(150,250);
canvas.Lineto(150,clientheight);
canvas.moveto(200,0);
canvas.LineTo(200,400);
canvas.moveto(200,450);
canvas.Lineto(200,clientheight);
canvas.Brush.Color := clgreen;
// Zielfeld
canvas.Rectangle(400,200,450,250);
label1.Caption := inttostr(x);
// Punktkoordinaten
label2.caption := inttostr(y);
canvas.brush.color := clnavy;
// Kugel
canvas.ellipse (x,y,x+dicke,y+dicke)
end;
end.