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);
function Ausnahme:Boolean;
procedure FormCreate(Sender: TObject);
procedure OptionsClick(Sender: TObject);
private
Options1: TOptions1;
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);
procedure BallZeichnen;
procedure BallLoeschen;
procedure BallBewegen;
constructor BallErstellen;
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)
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)
do
begin
Main.Canvas.Brush.Color := Ball[i].cInnen;
Main.Canvas.Pen.Mode := pmCopy;
Main.Canvas.Pen.Color := Ball[i].cRand;
Main.Canvas.Ellipse (x-r,y-r,x+r,y+r);
end;
end;
procedure TBall.BallLoeschen;
begin
Main.Canvas.Brush.Color := Main.Color;
Main.Canvas.Pen.Mode := pmCopy;
Main.Canvas.Pen.Color := Main.Color;
Main.Canvas.Ellipse (x-r,y-r,x+r,y+r);
end;
procedure TBall.BallBewegen;
begin
x := x + vx;
y := y + vy;
end;
(*-------------------------------TMain-Abläufe-------------------------------*)
procedure TMain.FormCreate(Sender: TObject);
var i : integer;
begin
TBall.BallErstellen;
for i := 0
to Length (Ball)
do
Ball[i] := TBall.BallInit (Random(20),Random(Main.ClientHeight-Ball[i].r),Random(Main.ClientWidth-Ball[i].r),Random(Main.ClientHeight+Ball[i].r),Random(Main.ClientWidth+Ball[i].r),clBlack,clBlack);
end;
procedure TMain.Start1Click(Sender: TObject);
var i : integer;
begin
for i := 0
to Length (Ball)
do
begin
if Ball[i].x <> 10
then
begin
Main.Canvas.Pen.Color := Main.Color;
Main.Canvas.Brush.Color := Main.Color;
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 (Random(20),Random(Main.ClientHeight-Ball[i].r),Random(Main.ClientWidth-Ball[i].r),Random(Main.ClientHeight+Ball[i].r),Random(Main.ClientWidth+Ball[i].r),clBlack,clBlack);
end;
Timer1.Enabled := True;
Ball[i].BallZeichnen;
end;
end;
procedure TMain.Pause1Click(Sender: TObject);
begin
if Timer1.Enabled = True
then
Timer1.Enabled := False;
end;
procedure TMain.Continue1Click(Sender: TObject);
begin
if Main.Ausnahme = True
then
Main.Timer1.Enabled := False;
if Main.Ausnahme = False
then
Main.Timer1.Enabled := False
end;
procedure TMain.Timer1Timer(Sender: TObject);
var i : integer;
begin
if Main.Ausnahme = True
then Main.Timer1.Enabled := False;
for i := 0
to Length (Ball)
do
begin
Ball[i].BallLoeschen;
Ball[i].BallBewegen;
Ball[i].BallZeichnen;
end;
end;
procedure TMain.Exit1Click(Sender: TObject);
begin
Application.Terminate;
end;
function TMain.Ausnahme:Boolean;
var i, BallAnzahl: integer;
begin
BallAnzahl := Length (Ball);
for i:=0
to (BallAnzahl-1)
do
begin
if (Ball[i].x = Main.ClientWidth-Ball[i].r)
or (Ball[i].y = Main.ClientHeight-Ball[i].r)
then
result := true
else
result := false;
end;
end;
(*-----------------------------------ENDE------------------------------------*)
procedure TMain.OptionsClick(Sender: TObject);
begin
// Options1 := TOptions1.Create(Main);
Options1.Show;
Timer1.Enabled := False;
end;
end.