Delphi-PRAXiS
Seite 8 von 18   « Erste     678 910     Letzte »    

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz (https://www.delphipraxis.net/162412-tic-tac-toe-mal-wieder-versteh-aufgabestellung-nicht-ganz.html)

DeddyH 23. Aug 2011 14:16

AW: tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz
 
Wie sieht die Funktion aus und was genau übergibst Du ihr?

biby90 23. Aug 2011 14:18

AW: tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz
 
Delphi-Quellcode:
if CheckForWin(Label9, Label8, Label7) then
    begin
      Label9.Caption := '';
      ShowMessage(IntToStr(GPlayer)+' hat gewonnen!');
      GPlayer := 1;
    end else



Delphi-Quellcode:
function TForm1.CheckForWin(Labels: MyStringArray): Boolean;
begin
   Result := (Labels[0] = Labels[1]) and (Labels[0] = Labels[2]);
end;

DeddyH 23. Aug 2011 14:19

AW: tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz
 
Delphi-Quellcode:
if CheckForWin([Label9.Caption, Label8.Caption, Label7.Caption]) then

biby90 23. Aug 2011 14:21

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

[Pascal Fehler] Unit1.pas(287): E2010 Inkompatible Typen: 'MyStringArray' und 'TCaption'
Zitat:

[Pascal Fehler] Unit1.pas(287): E2034 Zu viele Parameter
Das will er auch nicht

DeddyH 23. Aug 2011 14:24

AW: tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz
 
Achja, das ist ja kein Open Array mehr. Dann eben so:
Delphi-Quellcode:
var
  Kombination: TMyStringArray;
begin
  Kombination[0] := Label1.Caption;
  Kombination[1] := Label2.Caption;
  Kombination[2] := Label3.Caption;
  if CheckForWin(Kombination) then

himitsu 23. Aug 2011 14:40

AW: tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz
 
Jupp, wenn man als Parameter-Typ einen Array-Typen angibt, dann muß auch eine Variable/Konstante mit genau diesem Typen übergeben werden.
Den sogenannten Open-Arrays ist sowas aber egal.

Delphi-Quellcode:
function CheckForWin(Labels: array of String): Boolean;
begin
  if Length(Labels) < 3 then // oder besser noch if Length(Labels) <> 3 then
    raise Exception.Create('Es müssen (mindestens) 3 Strings an CheckForWin übergeben werden.');
  ...
Oder man nimmt eben kein Array.
Delphi-Quellcode:
function CheckForWin(Label1, Label2, Label3: String): Boolean;
begin
  ...

biby90 23. Aug 2011 14:51

AW: tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz
 
ja das war es schon eher. Jetzt muss ich es nur noch mit einbauen mit den diagonalen und so weiter.... das kann ich doch auch in eine extra procedure machen wei es ja für jedes Label gilt? obwohl...hmmm.... haben ja immer andere Label namen....

naja und jetzt wenn ich auf das eine label drücke ohne dass ich vorher was anderes geklickt habe wird mir der Gewinner angezeigt?! Also gewinnt der jenige, der als erstes klickt, weil das feld leer ist xD:lol:

DeddyH 23. Aug 2011 14:57

AW: tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz
 
Wahrscheinlich prüfst Du eben nicht, ob das Feld leer ist, bevor Du die Funktion aufrufst.

biby90 23. Aug 2011 15:08

AW: tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz
 
Delphi-Quellcode:
function TForm1.CheckForWin(AIndex: array of string): Boolean;
begin
  AIndex[1]:= Label1.Caption;
  AIndex[2]:= Label2.Caption;
  AIndex[3]:= Label3.Caption;
  AIndex[4]:= Label4.Caption;
  AIndex[5]:= Label5.Caption;
  AIndex[6]:= Label6.Caption;
  AIndex[7]:= Label7.Caption;
  AIndex[8]:= Label8.Caption;
  AIndex[9]:= Label9.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;
aber wieso geht der denn nicht?

DeddyH 23. Aug 2011 15:09

AW: tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz
 
Jetzt hast Du ja alles wieder über den Haufen geworfen :wall:


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:24 Uhr.
Seite 8 von 18   « Erste     678 910     Letzte »    

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz