Einzelnen Beitrag anzeigen

Fazer

Registriert seit: 29. Okt 2012
8 Beiträge
 
#11

AW: dringende Frage zur : Tic Tac Toe Programmierung ! - Bitte um schnelle Antwort

  Alt 29. Okt 2012, 17:07
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.

Geändert von Fazer (29. Okt 2012 um 17:50 Uhr)
  Mit Zitat antworten Zitat