unit DartBoard;
interface
uses
Classes, SysUtils, Dialogs, Windows, Contnrs;
type TPArray =
Array [0..3]
of TPoint;
TField =
packed record
x1,y1,x2,y2,x3,y3,x4,y4 : integer;
Name :
String[4];
end;
type TDartField =
class(TObject)
private
FRegion: HRGN;
// was auch immer das für ein Typ ist?
FName:
String;
public
property Region: HRGN
read FRegion
write FRegion;
property Name:
String read FName
write FName;
end;
type TDartBoard =
class(TList)
private
procedure initBoard;
function GetPArray( x1,y1,x2,y2,x3,y3,x4,y4: integer) : TPArray;
function GetDartField(
Index: Integer): TDartField;
public
constructor Create;
destructor Destroy;
override;
procedure Add(Item: TDartField);
function Next(AktField : Integer): TDartField;
function IndexOf(Item: TDartField): Integer;
property DartField[
Index: Integer]: TDartField
read GetDartField;
end;
implementation
{ TDartBoard }
procedure TDartBoard.Add(Item: TDartField);
begin
inherited Add(Item);
end;
constructor TDartBoard.Create;
begin
inherited;
initBoard;
end;
destructor TDartBoard.Destroy;
var
i: Integer;
begin
for i := 0
to self.Count - 1
do
self.DartField[i].Free;
inherited;
end;
function TDartBoard.GetDartField(
Index: Integer): TDartField;
begin
result :=
inherited Get(
Index);
end;
function TDartBoard.GetPArray(x1, y1, x2, y2, x3, y3, x4,
y4: integer): TPArray;
begin
result[0] := Point(x1,y1);
result[1] := Point(x2,y2);
result[2] := Point(x3,y3);
result[3] := Point(x4,y4);
end;
function TDartBoard.IndexOf(Item: TDartField): Integer;
begin
result :=
inherited IndexOf(Item);
end;
procedure TDartBoard.initBoard;
var DField : TDartField;
Points : TPArray;
datei :
file of TField;
field : TField;
i, Anz : integer;
begin
AssignFile(datei,'
Fields.dat');
if FileExists('
Fields.dat')
then
ReSet(datei)
else ShowMessage('
Datei für Dartboard nicht gefunden');
For i := 0
to (FileSize(datei)-1)
do
begin
seek(datei, i);
Read(datei, field);
Points := getPArray(field.x1, field.y1, field.x2, field.y2, field.x3,
field.y3, field.x4, field.y4);
DField.Region := CreatePolygonRgn(Points,4,winding);
//hier springt er in den Destruktor;
DField.
Name := field.
Name;
self.Add(DField);
end;
showmessage( inttostr(self.Count));
CloseFile(datei);
end;
function TDartBoard.Next(AktField: Integer): TDartField;
begin
if AktField = self.Count - 1
then
result := self.Get(0)
else
result := self.Get(AktField + 1);
end;
end.