AW: tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz
Wie sieht die Funktion aus und was genau übergibst Du ihr?
|
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; |
AW: tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz
Delphi-Quellcode:
if CheckForWin([Label9.Caption, Label8.Caption, Label7.Caption]) then
|
AW: tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz
Zitat:
Zitat:
|
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 |
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:
Oder man nimmt eben kein Array.
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.'); ...
Delphi-Quellcode:
function CheckForWin(Label1, Label2, Label3: String): Boolean;
begin ... |
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: |
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.
|
AW: tic tac toe.... mal wieder:) versteh aufgabestellung nicht ganz
Delphi-Quellcode:
aber wieso geht der denn nicht?
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; |
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. |
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