unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls;
type
{ TForm1 }
TForm1 =
class(TForm)
Button1: TButton;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
Image5: TImage;
Image6: TImage;
Image7: TImage;
Image8: TImage;
Image9: TImage;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Image1Click(Sender: TObject);
procedure Image2Click(Sender: TObject);
procedure Image3Click(Sender: TObject);
procedure Image4Click(Sender: TObject);
procedure Image5Click(Sender: TObject);
procedure Image6Click(Sender: TObject);
procedure Image7Click(Sender: TObject);
procedure Image8Click(Sender: TObject);
procedure Image9Click(Sender: TObject);
private
{ private declarations }
FSpielerX: Boolean;
Feld:
Array[0..2,0..2]
of Variant;
procedure UpdateFeld(AX,AY: Integer; AImage: TImage);
function CheckVictory(AX,AY: Integer; ASpieler: Boolean): Boolean;
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
I,J: Integer;
begin
Image1.Enabled := true;
Image2.Enabled := true;
Image3.Enabled := true;
Image4.Enabled := true;
Image5.Enabled := true;
Image6.Enabled := true;
Image7.Enabled := true;
Image8.Enabled := true;
Image9.Enabled := true;
FSpielerX := true;
for I:= 0
to 2
do begin
for j:= 0
to 2
do begin
Feld[I,J] :=
nil;
end;
end;
end;
procedure TForm1.Image1Click(Sender: TObject);
begin
UpdateFeld(0,0,Image1);
end;
procedure TForm1.Image2Click(Sender: TObject);
begin
UpdateFeld(1,0,Image2);
end;
procedure TForm1.Image3Click(Sender: TObject);
begin
UpdateFeld(2,0,Image3);
end;
procedure TForm1.Image4Click(Sender: TObject);
begin
UpdateFeld(0,1,Image4);
end;
procedure TForm1.Image5Click(Sender: TObject);
begin
UpdateFeld(1,1,Image5);
end;
procedure TForm1.Image6Click(Sender: TObject);
begin
UpdateFeld(2,1,Image6);
end;
procedure TForm1.Image7Click(Sender: TObject);
begin
UpdateFeld(0,2,Image7);
end;
procedure TForm1.Image8Click(Sender: TObject);
begin
UpdateFeld(1,2,Image8);
end;
procedure TForm1.Image9Click(Sender: TObject);
begin
UpdateFeld(2,2,Image9);
end;
procedure TForm1.UpdateFeld(AX,AY: Integer; AImage: TImage);
begin
if (Feld[AX,AY] =
nil)
then
begin
Feld[AX,AY] := FSpielerX;
if (FSpielerX)
then
begin
AImage.Picture.Loadfromfile('
Unbenannt1.png');
end
else
begin
AImage.Picture.Loadfromfile('
Unbenannt111.png');
end;
if (CheckVictory(AX,AY,FSpielerX))
then
begin
Label1.Caption := '
Gewonnen';
//Victory();
end;
FSpielerX :=
not FSpielerX;
end;
end;
function TForm1.CheckVictory(AX,AY: Integer; ASpieler: Boolean): Boolean;
begin
Result := false;
if ( ((Feld[AX,0] = ASpieler)
and (Feld[AX,1] = ASpieler)
and (Feld[AX,2] = ASpieler))
or ((Feld[0,AY] = ASpieler)
and (Feld[1,AY] = ASpieler)
and (Feld[2,AY] = ASpieler))
)
then
begin
Result := true;
end;
if ( (
not Result)
and ( ((AX = 0)
and (AY = 0))
or ((AX = 1)
and (AY = 1))
or ((AX = 2)
and (AY = 2))
)
)
then
begin
if ((Feld[0,0] = ASpieler)
and (Feld[1,1] = ASpieler)
and (Feld[2,2] = ASpieler))
then
begin
Result := true;
end;
end;
if ( (
not Result)
and ( ((AX = 2)
and (AY = 0))
or ((AX = 1)
and (AY = 1))
or ((AX = 0)
and (AY = 2))
)
)
then
begin
if ((Feld[2,0] = ASpieler)
and (Feld[1,1] = ASpieler)
and (Feld[0,2] = ASpieler))
then
begin
Result := true;
end;
end;
end;
end.