unit b;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, LMDCustomControl, LMDCustomPanel,
LMDCustomBevelPanel, LMDBaseEdit, LMDCustomEdit, LMDEdit,
LMDCustomComponent, lmdcont, LMDCustomMemo, LMDMemo, MPlayer;
type
TForm1 =
class(TForm)
Panel1: TPanel;
t: TTimer;
enemy: TPanel;
gol: TLabel;
start: TImage;
startl: TLabel;
ball: TShape;
credits: TImage;
Label1: TLabel;
Image1: TImage;
ende: TLabel;
Label2: TLabel;
p1: TLMDMemo;
Label3: TLabel;
p2: TLMDMemo;
mp: TMediaPlayer;
player1: TPanel;
procedure ki;
procedure Visible_false;
procedure go_p1;
procedure go_p2;
procedure mp1;
procedure tTimer(Sender: TObject);
procedure FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
procedure startClick(Sender: TObject);
procedure startlClick(Sender: TObject);
procedure Label1Click(Sender: TObject);
procedure creditsClick(Sender: TObject);
procedure Image1Click(Sender: TObject);
procedure endeClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
xspeed: Integer=2;
yspeed: Integer=2;
bdirection: byte;
implementation
uses c;
{$R *.DFM}
procedure TForm1.ki;
var schritt: integer;
begin
schritt := 2;
if ball.Top > enemy.Top
then enemy.Top := enemy.Top+schritt;
if ball.Top < enemy.Top
then enemy.Top := enemy.Top-schritt;
end;
procedure TForm1.Visible_false;
begin
t.Enabled:= true;
p1.Visible:= false;
p2.Visible:= false;
Label3.Visible:= false;
start.Visible:= false;
startl.Visible:= false;
ball.Visible:= true;
player1.visible:= true;
enemy.Visible:= true;
label1.Visible:= false;
credits.Visible:= false;
ende.Visible:= false;
Image1.Visible:= false;
Label2.Visible:= false;
end;
procedure TForm1.go_p1;
begin
showmessage(p1.text+'
'+'
gewinnt');
end;
procedure TForm1.go_p2;
begin
showmessage(p2.text+'
'+'
gewinnt');
end;
procedure TForm1.mp1;
begin
mp.play;
end;
procedure TForm1.tTimer(Sender: TObject);
var toleranz : integer;
// umgebung um den balken herum in pixeln
begin
toleranz := ball.Width
div 2;
//KI-Aktivierung
ki;
//Vereinbarungen
ball.left := ball.Left + xspeed;
ball.Top := ball.Top + yspeed;
//Ballkollision
if (Abs(ball.Left - enemy.left) <= 5)
and (Abs(ball.Top - enemy.Top) <= 5)
then xspeed:= -xspeed;
if (ball.top > player1.top -1-toleranz)
and (ball.top < player1.top + player1.height +1+toleranz)
and (ball.left = player1.left+player1.width)
then xspeed := -xspeed;
//Ballkollisions Ton
if (Abs(ball.Left - enemy.left) <= 5)
and (Abs(ball.Top - enemy.Top) <= 5)
then mp1;
if (ball.top > player1.top -1-toleranz)
and (ball.top < player1.top + player1.height +1+toleranz)
and (ball.left = player1.left+player1.width)
then mp1;
//Kollisionserkennung
if ball.Left<0
then
begin
t.Enabled:= false;
ball.Visible:= false;
go_p2;
end;
if ball.Left>445
then
begin
t.Enabled:= false;
ball.Visible:= false;
go_p1;
end;
if ball.Left<0
then xspeed := -xspeed;
if ball.Top<0
then yspeed := -yspeed;
if ball.Left>445
then xspeed := -xspeed;
if ball.Top>445
then yspeed := -yspeed;
end;
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
var s: integer;
begin
s := 3;
if key=VK_UP
then Player1.top:=player1.top-s;
if key=VK_DOWN
then Player1.top:=player1.top+s;
if key=ord('
S')
then enemy.top:=enemy.top+s;
if key=ord('
W')
then enemy.top:=enemy.top-s;
end;
procedure TForm1.startClick(Sender: TObject);
begin
Visible_false;
end;
procedure TForm1.startlClick(Sender: TObject);
begin
Visible_false;
end;
procedure TForm1.Label1Click(Sender: TObject);
begin
form1.hide;
form2.show;
form2.c.scroll:= true;
form2.ef.Enabled:= true;
end;
procedure TForm1.creditsClick(Sender: TObject);
begin
form1.hide;
form2.show;
form2.c.scroll:= true;
form2.ef.Enabled:= true;
end;
procedure TForm1.Image1Click(Sender: TObject);
begin
form1.close;
end;
procedure TForm1.endeClick(Sender: TObject);
begin
form1.close;
end;
end.