unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;
type
TfrmPong =
class(TForm)
tmBall: TTimer;
pnlLeft: TPanel;
pnlBall: TPanel;
pnlLine: TPanel;
lblLeftPoint: TLabel;
lblRightPoint: TLabel;
pnlRight: TPanel;
procedure FormKeyPress(Sender: TObject;
var Key: Char);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormClick(Sender: TObject);
procedure tmBallTimer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmPong: TfrmPong;
var VERS_DROITE,UPPART,LOWPART:Boolean;
implementation
{$R *.DFM}
procedure TfrmPong.FormKeyPress(Sender: TObject;
var Key: Char);
begin
if (Key = '
w')
and (pnlLeft.Top-15 >= 0)
then
pnlLeft.Top := pnlLeft.Top - 15;
if (Key = '
s')
and (pnlLeft.Top+15 <= 512 )
then
pnlLeft.Top := pnlLeft.Top + 15;
end;
procedure TfrmPong.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if (pnlRight.Top >= 5)
and (pnlRight.Top+190 <= frmPong.ClientHeight)
then
pnlRight.Top:=Y-10;
end;
procedure TfrmPong.FormCreate(Sender: TObject);
begin
VERS_DROITE:=true;
pnlBall.left := 500;
pnlBall.Top := 349;
LOWPART := False;
UPPART := True;
frmPong.AutoSize := True;
end;
procedure TfrmPong.FormClick(Sender: TObject);
begin
tmBall.Enabled := True;
frmPong.ClientHeight := 650;
frmpong.ClientWidth := 1000;
pnlLine.Left := 500;
pnlLine.Height := 650;
pnlLeft.Left := 0;
pnlright.Left := 1000;
end;
procedure TfrmPong.tmBallTimer(Sender: TObject);
begin
if VERS_DROITE
then
begin
if (pnlBall.Left+pnlBall.Width+5 < pnlRight.Left)
then
pnlBall.left := pnlBall.left + 5
else
if (pnlBall.Top >= pnlRight.Top)
and (pnlBall.Top <= pnlRight.Top+185)
then
VERS_DROITE:=false
else
begin
pnlBall.left := 500;
pnlBall.Top := 349;
tmBall.Enabled := false;
lblLeftPoint.Caption := inttostr(strtoint(lblLeftPoint.Caption)+1);
end
else
if (pnlBall.Left-5 > pnlLeft.Left+25)
then
pnlBall.Left:=pnlBall.Left-5
else
if (pnlBall.Top >= pnlLeft.Top)
and (pnlBall.Top <= pnlLeft.Top+185)
then
VERS_DROITE:=true
else
begin
pnlBall.Left := 500;
pnlBall.Top := 349;
tmBall.Enabled := False;
lblRightPoint.Caption := inttostr(strtoint(lblRightPoint.Caption)+1);
end;
end;
if lblLeftPoint.Caption = '
10'
then
begin
showmessage('
Player 1 hat gewonnen');
lblLeftPoint.caption := '
0';
end
else
if lblRightPoint.Caption = '
10'
then
begin
showmessage('
Player 2 hat gewonnen');
lblLeftPoint.caption := '
0';
end;
end;
end.