![]() |
AW: dringende Frage zur : Tic Tac Toe Programmierung ! - Bitte um schnelle Antwort
Ja das weiß ich ^^
aber irgendwie will das nicht funktionieren. if (lblGewinner.Caption = 'Spieler 1 hat gewonnen !') then begin xscore := xscore + 1; lblXScore.Caption := IntToStr(xscore); end; also die lblXScore.Caption verändert sich nicht :S neuer code:
Delphi-Quellcode:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Menus; type TForm1 = class(TForm) btnNewGame: TButton; btnResetScore: TButton; rgPlayFirst: TRadioGroup; gbScoreBoard: TGroupBox; lblX: TLabel; lblMinus: TLabel; lblO: TLabel; lblXScore: TLabel; lblColon: TLabel; lblOScore: TLabel; Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Button5: TButton; Button6: TButton; Button7: TButton; Button8: TButton; Button9: TButton; RadioButton1: TRadioButton; RadioButton2: TRadioButton; ButtonClose: TButton; MainMenu1: TMainMenu; Hilfe1: TMenuItem; Anleitung1: TMenuItem; Informationen1: TMenuItem; lblGewinner: TLabel; procedure btnNewGameClick(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure Button7Click(Sender: TObject); procedure Button8Click(Sender: TObject); procedure Button9Click(Sender: TObject); procedure Gewinner; procedure zaehler; procedure ButtonCloseClick(Sender: TObject); procedure Anleitung1Click(Sender: TObject); procedure Informationen1Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; xscore: Integer; oscore: Integer; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin if RadioButton1.Checked then begin Button1.Caption:='X'; Button1.Enabled:=False; RadioButton2.SetFocus; end else if RadioButton2.Checked then begin Button1.Caption:='O'; Button1.Enabled:=False; RadioButton1.SetFocus; end; Gewinner; end; procedure TForm1.Button2Click(Sender: TObject); begin if RadioButton1.Checked then begin Button2.Caption:='X'; Button2.Enabled:=False; RadioButton2.SetFocus; end else if RadioButton2.Checked then begin Button2.Caption:='O'; Button2.Enabled:=False; RadioButton1.SetFocus; end; Gewinner; end; procedure TForm1.Button3Click(Sender: TObject); begin if RadioButton1.Checked then begin Button3.Caption:='X'; Button3.Enabled:=False; RadioButton2.SetFocus; end else if RadioButton2.Checked then begin Button3.Caption:='O'; Button3.Enabled:=False; RadioButton1.SetFocus; end; Gewinner; end; procedure TForm1.Button4Click(Sender: TObject); begin if RadioButton1.Checked then begin Button4.Caption:='X'; Button4.Enabled:=False; RadioButton2.SetFocus; end else if RadioButton2.Checked then begin Button4.Caption:='O'; Button4.Enabled:=False; RadioButton1.SetFocus; end; Gewinner; end; procedure TForm1.Button5Click(Sender: TObject); begin if RadioButton1.Checked then begin Button5.Caption:='X'; Button5.Enabled:=False; RadioButton2.SetFocus; end else if RadioButton2.Checked then begin Button5.Caption:='O'; Button5.Enabled:=False; RadioButton1.SetFocus; end; Gewinner; end; procedure TForm1.Button6Click(Sender: TObject); begin if RadioButton1.Checked then begin Button6.Caption:='X'; Button6.Enabled:=False; RadioButton2.SetFocus; end else if RadioButton2.Checked then begin Button6.Caption:='O'; Button6.Enabled:=False; RadioButton1.SetFocus; end; Gewinner; end; procedure TForm1.Button7Click(Sender: TObject); begin if RadioButton1.Checked then begin Button7.Caption:='X'; Button7.Enabled:=False; RadioButton2.SetFocus; end else if RadioButton2.Checked then begin Button7.Caption:='O'; Button7.Enabled:=False; RadioButton1.SetFocus; end; Gewinner; end; procedure TForm1.Button8Click(Sender: TObject); begin if RadioButton1.Checked then begin Button8.Caption:='X'; Button8.Enabled:=False; RadioButton2.SetFocus; end else if RadioButton2.Checked then begin Button8.Caption:='O'; Button8.Enabled:=False; RadioButton1.SetFocus; end; Gewinner; end; procedure TForm1.Button9Click(Sender: TObject); begin if RadioButton1.Checked then begin Button9.Caption:='X'; Button9.Enabled:=False; RadioButton2.SetFocus; end else if RadioButton2.Checked then begin Button9.Caption:='O'; Button9.Enabled:=False; RadioButton1.SetFocus; end; Gewinner; end; //Gewinner festlegen procedure TForm1.Gewinner; begin //Kombination 1 if (Button1.Caption='X') and (Button2.Caption='X') and (Button3.Caption='X') then begin lblGewinner.Caption :='Spieler 1 hat gewonnen !'; end; if (Button1.Caption='O') and (Button2.Caption='O') and (Button3.Caption='O') then begin lblGewinner.Caption :='Spieler 2 hat gewonnen !'; end; //Kombination 2 if (Button4.Caption='X') and (Button5.Caption='X') and (Button6.Caption='X') then begin lblGewinner.Caption :='Spieler 1 hat gewonnen !'; end; if (Button4.Caption='O') and (Button5.Caption='O') and (Button6.Caption='O') then begin lblGewinner.Caption :='Spieler 2 hat gewonnen !'; end; //Kombination 3 if (Button7.Caption='X') and (Button8.Caption='X') and (Button9.Caption='X') then begin lblGewinner.Caption :='Spieler 1 hat gewonnen !'; end; if (Button7.Caption='O') and (Button8.Caption='O') and (Button9.Caption='O') then begin lblGewinner.Caption :='Spieler 2 hat gewonnen !'; end; //Kombination 4 if (Button1.Caption='X') and (Button4.Caption='X') and (Button7.Caption='X') then begin lblGewinner.Caption :='Spieler 1 hat gewonnen !'; end; if (Button1.Caption='O') and (Button4.Caption='O') and (Button7.Caption='O') then begin lblGewinner.Caption :='Spieler 2 hat gewonnen !'; end; //Kombination 5 if (Button2.Caption='X') and (Button5.Caption='X') and (Button8.Caption='X') then begin lblGewinner.Caption :='Spieler 1 hat gewonnen !'; end; if (Button2.Caption='O') and (Button5.Caption='O') and (Button8.Caption='O') then begin lblGewinner.Caption :='Spieler 2 hat gewonnen !'; end; //Kombination 6 if (Button3.Caption='X') and (Button6.Caption='X') and (Button9.Caption='X') then begin lblGewinner.Caption :='Spieler 1 hat gewonnen !'; end; if (Button3.Caption='O') and (Button6.Caption='O') and (Button9.Caption='O') then begin lblGewinner.Caption :='Spieler 2 hat gewonnen !'; end; //Kombination 7 if (Button1.Caption='X') and (Button5.Caption='X') and (Button9.Caption='X') then begin lblGewinner.Caption :='Spieler 1 hat gewonnen !'; end; if (Button1.Caption='O') and (Button5.Caption='O') and (Button9.Caption='O') then begin lblGewinner.Caption :='Spieler 2 hat gewonnen !'; end; //Kombination 8 if (Button3.Caption='X') and (Button5.Caption='X') and (Button7.Caption='X') then begin lblGewinner.Caption :='Spieler 1 hat gewonnen !'; end; if (Button3.Caption='O') and (Button5.Caption='O') and (Button7.Caption='O') then begin lblGewinner.Caption :='Spieler 2 hat gewonnen !'; end; end; procedure TForm1.zaehler; begin xscore := 0; oscore := 0; if (lblGewinner.Caption = 'Spieler 1 hat gewonnen !') then begin xscore := xscore + 1; lblXScore.Caption := IntToStr(xscore); end; if (lblGewinner.Caption = 'Spieler 2 hat gewonnen !') then begin oscore := oscore + 1; lblOScore.Caption := IntToStr(oscore); end; end; procedure TForm1.btnNewGameClick(Sender: TObject); begin Button1.Caption:=''; Button2.Caption:=''; Button3.Caption:=''; Button4.Caption:=''; Button5.Caption:=''; Button6.Caption:=''; Button7.Caption:=''; Button8.Caption:=''; Button9.Caption:=''; Button1.Enabled:=True; Button2.Enabled:=True; Button3.Enabled:=True; Button4.Enabled:=True; Button5.Enabled:=True; Button6.Enabled:=True; Button7.Enabled:=True; Button8.Enabled:=True; Button9.Enabled:=True; lblGewinner.Caption:=''; end; procedure TForm1.ButtonCloseClick(Sender: TObject); begin Form1.Close end; procedure TForm1.Anleitung1Click(Sender: TObject); begin showmessage('Funktionsweise:' +#10#13+ '1)Kreuze an welcher Spieler anfängt!' +#10#13+ '2)Und Leg los!'); end; procedure TForm1.Informationen1Click(Sender: TObject); begin ShowMessage(' © '); end; end. |
AW: dringende Frage zur : Tic Tac Toe Programmierung ! - Bitte um schnelle Antwort
Zitat:
Zitat:
Edit: ![]() |
AW: dringende Frage zur : Tic Tac Toe Programmierung ! - Bitte um schnelle Antwort
Sry, Ich bedanke mich bei allen die mir Geholfen :D
Ich bin ziemlich neu hier im Forum und muss mich erst mal anpassen. Hoffe es ist ok :) |
AW: dringende Frage zur : Tic Tac Toe Programmierung ! - Bitte um schnelle Antwort
das mit den buttons mache ich ganz am ende aber danke für die erinnerung :)
Wie meinst du das wo ist deine function? ich hab doch die prozedur zaehler :S |
AW: dringende Frage zur : Tic Tac Toe Programmierung ! - Bitte um schnelle Antwort
Zitat:
|
AW: dringende Frage zur : Tic Tac Toe Programmierung ! - Bitte um schnelle Antwort
Das ist wie bei deinem "Gewinner" ... rufst du es nicht auf, wird es auch nicht ausgeführt.
Am Besten du fragst deinen Lehrer, daß er euch mal bitte das Debuggen (zumindestens die grundlegensten Dinge) beibringen möchte. - Haltepunkte (F5) - schrittweise Codeausführung (F7 und F8) - Und wie man sich den Werte von Variablen ansehn kann. Damit kannst du z.B. prüfen ob dein Code überhaupt ausgeführt wird, bzw. wie er ausgeführt wird und was genau passiert (z.B. ob ins IF oder ins ELSE gesprungen wird). Wobei man sich das auch über die Markierungen der aktiven Codezeilen ansehn könnte ... zumindestens bei deinem "zaehler" wäre es sofort aufgefallen, da dort die Pünktchen fehlten. |
AW: dringende Frage zur : Tic Tac Toe Programmierung ! - Bitte um schnelle Antwort
Ok erstmal danke :)
Das Problem ist, dass ich die Schule gewechselt habe. Hatte damals Java und jetzt Delphi komme mit dem Syntax nicht so richtig klar. Und der Zaehler funktioniert jetzt, jedoch zaehlt er nur bis 1 ^^ ka wieso |
AW: dringende Frage zur : Tic Tac Toe Programmierung ! - Bitte um schnelle Antwort
Wenn man eine Zahl auf 0 setzt und anschließend um 1 erhöht, wird eben 1 draus :mrgreen:
|
AW: dringende Frage zur : Tic Tac Toe Programmierung ! - Bitte um schnelle Antwort
Es klappt jetzt irgendwie doch alles wunderbar !
Danke nochmal :-D |
AW: dringende Frage zur : Tic Tac Toe Programmierung ! - Bitte um schnelle Antwort
Zitat:
Frank |
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:20 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz