Einzelnen Beitrag anzeigen

len123

Registriert seit: 3. Aug 2012
6 Beiträge
 
#1

Programm vereinfachen

  Alt 3. Aug 2012, 20:03
Hey
Ich hab bastel grad an einem kleinen Tic Tac Toe-Spiel,
es besteht aus 9 labels, die ihre "caption" ändern, wen man auf sie klickt.
Ich muss noch anmerken das ich newbe in sachen Programmierung bin!
Das Programm guckt, nach jedem klick ob ein Spieler gewonnen hat,
dazu hab ich die Bedingungen bei jedem labelclick methode eingefügt.
Jetz ist meine Frage, da der Skript dadurch sehr lang wird, ob man das nicht irgend wie anders machen könnt
z.B. das man Bedingungen nur in eine methode packt die dann die nachguckt ob die Bedingung erfüllt ist.

Bedingung:
Code:
if (Label1.Caption='X') and (Label2.Caption='X') and (Label3.Caption='X') or
  (Label4.Caption='X') and (Label5.Caption='X')and (Label6.Caption='X') or
  (Label7.Caption='X') and (Label8.Caption='X')and (Label9.Caption='X') or
  (Label1.Caption='X') and (Label4.Caption='X')and (Label7.Caption='X') or
  (Label2.Caption='X') and (Label5.Caption='X')and (Label8.Caption='X') or
  (Label3.Caption='X') and (Label6.Caption='X')and (Label9.Caption='X') or
  (Label1.Caption='X') and (Label5.Caption='X')and (Label9.Caption='X') or
  (Label3.Caption='X') and (Label5.Caption='X')and (Label7.Caption='X')
  then
   begin
            Label11.Caption:= 'Spieler X hat gewonnen!';
   end;
   if (Label1.Caption='O') and (Label2.Caption='O') and (Label3.Caption='O') or
  (Label4.Caption='O') and (Label5.Caption='O')and (Label6.Caption='O') or
  (Label7.Caption='O') and (Label8.Caption='O')and (Label9.Caption='O') or
  (Label1.Caption='O') and (Label4.Caption='O')and (Label7.Caption='O') or
  (Label2.Caption='O') and (Label5.Caption='O')and (Label8.Caption='O') or
  (Label3.Caption='O') and (Label6.Caption='O')and (Label9.Caption='O') or
  (Label1.Caption='O') and (Label5.Caption='O')and (Label9.Caption='O') or
  (Label3.Caption='O') and (Label5.Caption='O')and (Label7.Caption='O')
  then
   begin
            Label11.Caption:= 'Spieler O hat gewonnen!';
   end;

Ich hoffe ihr versteht meine frage

gruß lenn
  Mit Zitat antworten Zitat