Einzelnen Beitrag anzeigen

biby90
(Gast)

n/a Beiträge
 
#41

AW: tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz

  Alt 23. Aug 2011, 11:40
Delphi-Quellcode:
procedure TForm1.Label8Click(Sender: TObject);
begin
  if IsFieldEmpty(Label8.Caption) then
  begin
    Label8.Caption := WriteToField(GPlayer);
    if CheckForWin(GBuffer) then //kann wegen optimierung nicht zugegriffen werden?
    begin
      Label8.Caption := '';
      ShowMessage(IntToStr(GPlayer)+' hat gewonnen!');
      GPlayer := 1;
    end else
    begin
      ChangePlayer;
    end;
  end;
end;
also naja ich gebe euch nochal die Funktion dazu.....
Delphi-Quellcode:
function TForm1.CheckForWin(AIndex: array of string): Boolean;
begin
  AIndex[1]:= Label1.Caption;
  AIndex[2]:= Label1.Caption;
  AIndex[3]:= Label1.Caption;
  AIndex[4]:= Label1.Caption;
  AIndex[5]:= Label1.Caption;
  AIndex[6]:= Label1.Caption;
  AIndex[7]:= Label1.Caption;
  AIndex[8]:= Label1.Caption;
  AIndex[9]:= Label1.Caption;

  result := false;
  begin
    if (AIndex[1] = AIndex[2]) and (AIndex[2] = AIndex[3]) and
      (IsFieldEmpty(AIndex[1]) = false) then
    begin
      result := true;
    end;
    if (AIndex[4] = AIndex[5]) and (AIndex[5] = AIndex[6]) and
      (IsFieldEmpty(AIndex[4]) = false) then
    begin
      result := true;
    end;
    if (AIndex[7] = AIndex[8]) and (AIndex[8] = AIndex[9]) and
      (IsFieldEmpty(AIndex[7]) = false) then
    begin
      result := true;
    end;
    if (AIndex[1] = AIndex[4]) and (AIndex[4] = AIndex[7]) and
      (IsFieldEmpty(AIndex[1]) = false) then
    begin
      result := true;
    end;
    if (AIndex[2] = AIndex[5]) and (AIndex[5] = AIndex[8]) and
      (IsFieldEmpty(AIndex[2]) = false) then
    begin
      result := true;
    end;
    if (AIndex[3] = AIndex[6]) and (AIndex[6] = AIndex[9]) and
      (IsFieldEmpty(AIndex[3]) = false) then
    begin
      result := true;
    end;
    if (AIndex[1] = AIndex[5]) and (AIndex[5] = AIndex[9]) and
      (IsFieldEmpty(AIndex[1]) = false) then
    begin
      result := true;
    end;
    if (AIndex[3] = AIndex[5]) and (AIndex[5] = AIndex[7]) and
      (IsFieldEmpty(AIndex[3]) = false) then
    begin
      result := true;
    end;
  end;
end;
also als ich es gerade durchgesteppt habe stand an der Seite
Zitat:
//kann wegen optimierung nicht zugegriffen werden

bin eben Mittag essen also.... ich seh ja was ihr schreibt^^