AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein dringende Frage zur : Tic Tac Toe Programmierung ! - Bitte um schnelle Antwort
Thema durchsuchen
Ansicht
Themen-Optionen

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

Ein Thema von Fazer · begonnen am 29. Okt 2012 · letzter Beitrag vom 29. Okt 2012
 
Fazer

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

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

  Alt 29. Okt 2012, 14:49
Muss morgen ein Projekt abgehen in Informatik.
Habe Tic Tac Toe programmiert, jedoch habe ich eine Frage und bitte deshalb um schnelle Antwort.

Quellcode:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Menus;


type
  TXOPosArray = array [1..3, 1..3] of Integer;

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;
    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 ButtonCloseClick(Sender: TObject);
    procedure Anleitung1Click(Sender: TObject);
    procedure Informationen1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;


implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if RadioButton1.Checked=True then
    begin
     Button1.Caption:='X';
     Button1.Enabled:=False;
     RadioButton2.SetFocus;
    end
  else
   if RadioButton2.Checked=True then
    begin
     Button1.Caption:='O';
     Button1.Enabled:=False;
     RadioButton1.SetFocus;
    end;
Gewinner;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 if RadioButton1.Checked=True then
     begin
      Button2.Caption:='X';
      Button2.Enabled:=False;
      RadioButton2.SetFocus;
     end
 else
  if RadioButton2.Checked=True then
    begin
     Button2.Caption:='O';
     Button2.Enabled:=False;
     RadioButton1.SetFocus;
    end;
Gewinner;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
 if RadioButton1.Checked=True then
    begin
     Button3.Caption:='X';
     Button3.Enabled:=False;
     RadioButton2.SetFocus;
    end
 else
  if RadioButton2.Checked=True then
    begin
     Button3.Caption:='O';
     Button3.Enabled:=False;
     RadioButton1.SetFocus;
    end;
Gewinner;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
 if RadioButton1.Checked=True then
    begin
     Button4.Caption:='X';
     Button4.Enabled:=False;
     RadioButton2.SetFocus;
    end
 else
  if RadioButton2.Checked=True then
    begin
     Button4.Caption:='O';
     Button4.Enabled:=False;
     RadioButton1.SetFocus;
    end;
Gewinner;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
 if RadioButton1.Checked=True then
    begin
     Button5.Caption:='X';
     Button5.Enabled:=False;
     RadioButton2.SetFocus;
    end
 else
  if RadioButton2.Checked=True then
    begin
     Button5.Caption:='O';
     Button5.Enabled:=False;
     RadioButton1.SetFocus;
    end;
Gewinner;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
 if RadioButton1.Checked=True then
    begin
     Button6.Caption:='X';
     Button6.Enabled:=False;
     RadioButton2.SetFocus;
    end
 else
  if RadioButton2.Checked=True then
    begin
     Button6.Caption:='O';
     Button6.Enabled:=False;
     RadioButton1.SetFocus;
    end;
Gewinner;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
 if RadioButton1.Checked=True then
    begin
     Button7.Caption:='X';
     Button7.Enabled:=False;
     RadioButton2.SetFocus;
    end
 else
  if RadioButton2.Checked=True then
    begin
     Button7.Caption:='O';
     Button7.Enabled:=False;
     RadioButton1.SetFocus;
    end;
Gewinner;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
 if RadioButton1.Checked=True then
    begin
     Button8.Caption:='X';
     Button8.Enabled:=False;
     RadioButton2.SetFocus;
    end
 else
  if RadioButton2.Checked=True then
    begin
     Button8.Caption:='O';
     Button8.Enabled:=False;
     RadioButton1.SetFocus;
    end;
Gewinner;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
 if RadioButton1.Checked=True then
    begin
     Button9.Caption:='X';
     Button9.Enabled:=False;
     RadioButton2.SetFocus;
    end
 else
  if RadioButton2.Checked=True 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
     ShowMessage('Spieler 1 hat gewonnen !');
   end;
  if (Button1.Caption='O') and (Button2.Caption='O') and (Button3.Caption='O') then
   begin
     ShowMessage('Spieler 2 hat gewonnen !');
   end;
//Kombination 2
 if (Button4.Caption='X') and (Button5.Caption='X') and (Button6.Caption='X') then
   begin
     ShowMessage('Spieler 1 hat gewonnen !');
   end;
 if (Button4.Caption='O') and (Button5.Caption='O') and (Button6.Caption='O') then
   begin
     ShowMessage('Spieler 2 hat gewonnen !');
   end;
//Kombination 3
 if (Button7.Caption='X') and (Button8.Caption='X') and (Button9.Caption='X') then
   begin
     ShowMessage('Spieler 1 hat gewonnen !');
   end;
 if (Button7.Caption='O') and (Button8.Caption='O') and (Button9.Caption='O') then
   begin
     ShowMessage('Spieler 2 hat gewonnen !');
   end;
//Kombination 4
 if (Button1.Caption='X') and (Button4.Caption='X') and (Button7.Caption='X') then
   begin
     ShowMessage('Spieler 1 hat gewonnen !');
   end;
 if (Button1.Caption='O') and (Button4.Caption='O') and (Button7.Caption='O') then
   begin
     ShowMessage('Spieler 2 hat gewonnen !');
   end;
//Kombination 5
 if (Button2.Caption='X') and (Button5.Caption='X') and (Button8.Caption='X') then
   begin
     ShowMessage('Spieler 1 hat gewonnen !');
   end;
 if (Button2.Caption='O') and (Button5.Caption='O') and (Button8.Caption='O') then
  begin
    ShowMessage('Spieler 2 hat gewonnen !');
  end;
//Kombination 6
 if (Button3.Caption='X') and (Button6.Caption='X') and (Button9.Caption='X') then
   begin
     ShowMessage('Spieler 1 hat gewonnen !');
   end;
 if (Button3.Caption='O') and (Button6.Caption='O') and (Button9.Caption='O') then
   begin
    ShowMessage('Spieler 2 hat gewonnen !');;
   end;
//Kombination 7
 if (Button1.Caption='X') and (Button5.Caption='X') and (Button9.Caption='X') then
   begin
     ShowMessage('Spieler 1 hat gewonnen !');
   end;
 if (Button1.Caption='O') and (Button5.Caption='O') and (Button9.Caption='O') then
   begin
     ShowMessage('Spieler 2 hat gewonnen !');
   end;
//Kombination 8
 if (Button3.Caption='X') and (Button5.Caption='X') and (Button7.Caption='X') then
   begin
     ShowMessage('Spieler 1 hat gewonnen !');
   end;
 if (Button3.Caption='O') and (Button5.Caption='O') and (Button7.Caption='O') then
   begin
    ShowMessage('Spieler 2 hat gewonnen !');
   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;

 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.



Die Prozedur: //Gewinner festlegen
procedure TForm1.Gewinner; funktioniert nur wen ich bei jedem Tform1.Buttonclick oben ein Gewinner ganz am Ende stehen habe. Wie kann könnte ich das ändern ?

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


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:08 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