unit mBall1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls, mOptions1;
type
TMain =
class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
Start1: TMenuItem;
Pause1: TMenuItem;
Continue1: TMenuItem;
Exit1: TMenuItem;
N2: TMenuItem;
Help1: TMenuItem;
Timer1: TTimer;
Options: TMenuItem;
procedure Start1Click(Sender: TObject);
procedure Pause1Click(Sender: TObject);
procedure Continue1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure OptionsClick(Sender: TObject);
private
public
end;
(*---------------------------Klassendefinition-Ball--------------------------*)
type
TBall =
class
r,x,y,vx,vy : integer;
cRand, cInnen : TColor;
constructor BallInit (Ir,Ix,Iy,Ivx,Ivy:integer;IcInnen,IcRand:TColor);
constructor BallErstellen;
procedure BallZeichnen;
procedure BallLoeschen;
procedure BallBewegen;
end;
(*-----------------------------------ENDE------------------------------------*)
var
Main: TMain;
Ball:
array of TBall;
implementation
{$R *.dfm}
(*-------------------------------TBall-Abläufe-------------------------------*)
constructor TBall.BallInit (Ir,Ix,Iy,Ivx,Ivy:integer;IcInnen,IcRand:TColor);
begin
r := Ir;
x := Ix;
y := Iy;
vx := Ivx;
vy := Ivy;
cInnen := IcInnen;
cRand := IcRand
end;
constructor TBall.BallErstellen;
var i : integer;
begin
i := StrToInt(Options1.Edit1.Text);
SetLength (Ball,i);
for i := 0
to (Length(Ball)-1)
do
Ball[i].BallInit(Random(20),Random(Main.ClientHeight-r),Random(Main.ClientWidth-r),Random(Main.ClientHeight+r),Random(Main.ClientWidth+r),clBlack,clBlack);
end;
procedure TBall.BallZeichnen;
var i : integer;
begin
for i := 0
to (Length(Ball)-1)
do
begin
Main.Canvas.Brush.Color := Ball[i].cInnen;
Main.Canvas.Pen.Mode := pmCopy;
Main.Canvas.Pen.Color := Ball[i].cRand;
Main.Canvas.Ellipse (Ball[i].x-Ball[i].r,Ball[i].y-Ball[i].r,Ball[i].x+Ball[i].r,Ball[i].y+Ball[i].r);
end;
end;
procedure TBall.BallLoeschen;
var i : integer;
begin
Main.Canvas.Brush.Color := Main.Color;
// Main.Canvas.Pen.Mode := pmCopy;
Main.Canvas.Pen.Color := Main.Color;
for i := 0
to (Length(Ball)-1)
do
Main.Canvas.Ellipse (Ball[i].x-Ball[i].r,Ball[i].y-Ball[i].r,Ball[i].x+Ball[i].r,Ball[i].y+Ball[i].r);
end;
procedure TBall.BallBewegen;
var i : integer;
begin
for i := 0
to (Length(Ball)-1)
do begin
Ball[i].x := Ball[i].x + Ball[i].vx;
Ball[i].y := Ball[i].y + Ball[i].vy;
end;
end;
(*-------------------------------TMain-Abläufe-------------------------------*)
procedure TMain.FormCreate(Sender: TObject);
var i : integer;
begin
SetLength(Ball,5);
for i := 0
to (Length(Ball)-1)
do
Ball[i] := TBall.BallInit (10,Random(Main.ClientWidth)-10,Random(Main.ClientHeight)-10,1,1,clWhite,clBlack);
end;
procedure TMain.Start1Click(Sender: TObject);
var i : integer;
begin
Main.Canvas.Pen.Color := Main.Color;
Main.Canvas.Brush.Color := Main.Color;
for i := 0
to (Length(Ball)-1)
do
begin
Main.Canvas.Ellipse ((Ball[i].x-Ball[i].r),(Ball[i].y-Ball[i].r),(Ball[i].x+Ball[i].r),(Ball[i].x+Ball[i].r));
Ball[i] := TBall.BallInit (10,Random(Main.ClientWidth)-10,Random(Main.ClientHeight)-10,1,1,clWhite,clBlack);
end;
Timer1.Enabled := True;
end;
procedure TMain.Pause1Click(Sender: TObject);
begin
Timer1.Enabled := False;
end;
procedure TMain.Continue1Click(Sender: TObject);
begin
Timer1.Enabled := True
end;
procedure TMain.Timer1Timer(Sender: TObject);
var i : integer;
begin
for i := 0
to (Length(Ball)-1)
do
begin
if (Ball[i].x >= (Main.ClientWidth-Ball[i].r))
or (Ball[i].y >= (Main.ClientHeight-Ball[i].r))
then
begin
Ball[i].vx := 0;
Ball[i].vy := 0;
end else
begin
Ball[i].BallLoeschen;
Ball[i].BallBewegen;
Ball[i].BallZeichnen;
end;
end;
end;
procedure TMain.Exit1Click(Sender: TObject);
begin
Application.Terminate;
end;
(*-----------------------------------ENDE------------------------------------*)
procedure TMain.OptionsClick(Sender: TObject);
begin
Options1 := TOptions1.Create(Self);
Options1.Show;
Timer1.Enabled := False;
end;
end.