unit UFeld;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ExtCtrls,StdCtrls;
type
TValue=0..4;
Tfield =
class(Tshape)
protected
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
override;
private
{ Private-Deklarationen }
anzeige:TLabel;
FStones:TValue;
procedure writeStones(value:TValue);
public
{ Public-Deklarationen }
constructor Create(AOwner: TComponent; Parent:Twincontrol; pos:Trect; number:TValue=0);
property Stones: TValue
read FStones
write writeStones;
end;
TSpielfeld=class
private
{ Private-Deklarationen }
Fields:
array of array of Tfield;
public
{ Public-Deklarationen }
anzclicks:byte;
constructor Create(AOwner: TComponent; Parent:Twincontrol; Size:word=60; Number:byte=6);
function NextSpep : boolean;
end;
const maxclicks=3;
var Spielfeld:TSpielfeld;
implementation
{-----------------------------------------------------------------------------
Description: Ok hier werden die einzelnen Felder creiert
Procedure: Create
Arguments: AOwner: TComponent; Parent:Twincontrol; pos:Trect; number:TValue=0
Result: None
Detailed description:
-----------------------------------------------------------------------------}
constructor Tfield.Create(AOwner: TComponent; Parent:Twincontrol; pos:Trect; number:TValue=0);
begin
inherited create(AOwner);
anzeige:=Tlabel.Create(self);
anzeige.Parent:=Parent;
stones:=number;
top:=pos.Top;
left:=pos.Left;
width:=pos.Right-pos.Left;
height:=pos.Bottom-pos.Top;
shape:=stCircle;
pen.Style:=psclear;
with anzeige
do
begin
top:=pos.Top+(pos.Bottom-pos.Top)
div 2;
left:=pos.Left+(pos.Right-pos.Left)
div 2;
width:=pos.Right-pos.Left;
height:=pos.Bottom-pos.Top;
transparent:=true;
end;
end;
{-----------------------------------------------------------------------------
Description: Falls die Steinzahl geändert wird
Procedure: writeStones
Arguments: value:TValue
Result: None
Detailed description:
-----------------------------------------------------------------------------}
procedure Tfield.writeStones(value:TValue);
begin
FStones:=value;
anzeige.Caption:=inttostr(value);
case value
of
0: brush.Color :=clgray;
1: brush.Color :=cllime;
2: brush.Color :=clgreen;
3: brush.Color :=clblue;
4: brush.Color :=clred;
end;
end;
{-----------------------------------------------------------------------------
Description:
Procedure: MouseDown
Arguments: Button: TMouseButton; Shift: TShiftState; X, Y: Integer
Result: None
Detailed description:
-----------------------------------------------------------------------------}
procedure Tfield.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
stones:=stones+1;
//hier soll noch was hinkommen
end;
{-----------------------------------------------------------------------------
Description: Das komplette feld wird erstellt
Procedure: Create
Arguments: AOwner: TComponent; Parent:Twincontrol; Size:word=60; Number:byte=6
Result: None
Detailed description:
-----------------------------------------------------------------------------}
constructor TSpielfeld.Create(AOwner: TComponent; Parent:Twincontrol; Size:word=60; Number:byte=6);
var i,j:byte;
begin
setlength(fields,number,number);
for i:=0
to number-1
do
for j:=0
to number-1
do
begin
fields[i,j]:=Tfield.Create(AOwner,parent,rect(i*(size+5),j*(size+5),i*(size+5)+size,j*(size+5)+size) );
fields[i,j].Parent:=Parent;
end;
end;
{-----------------------------------------------------------------------------
Description: Macht den nächten Schritt
Procedure: NextSpep
Arguments: None
Result: boolean
Detailed description: Wenn nichts mehr zu machen dann false
-----------------------------------------------------------------------------}
function TSpielfeld.NextSpep : boolean;
var anz4:byte;
//weil viel steine da liegen
f:
array[0..schritte-1]
of Tpoint;
i,j,number:byte;
begin
anzclicks:=0;
//damit wieder hochgezählt werden kann
number:=length(fields);
//kommt 6 raus
anz4:=0;
for i:=0
to number-1
do
for j:=0
to number-1
do
if fields[i,j].Stones=4
then
begin
f[anz4].X:=i;
f[anz4].y:=j;
inc(anz4);
end;
result:= anz4>0;
if not result
then exit;
//brauch ja nicht mehr weiter zu machen
//hier soll noch was hinkommen
end;
end.