Ничья крестики-нолики

PascalABC.Net Каждая клетка это Label, которая имеет свой номер, и при вводе значений в TextBox заменяет его (Label) на крестик либо нолик. Варианты победы прописаны, а вот как сделать ничью???


interface

uses System, System.Drawing, System.Windows.Forms;


type
  Form2 = class(Form)
    procedure Form2_Load(sender: Object; e: EventArgs);
    procedure button1_Click(sender: Object; e: EventArgs);
    procedure button2_Click(sender: Object; e: EventArgs);
    procedure textBox1_TextChanged(sender: Object; e: EventArgs);
    procedure label1_Click(sender: Object; e: EventArgs);
    procedure textBox1_KeyPress(sender: Object; e: KeyPressEventArgs);
    procedure textBox2_TextChanged(sender: Object; e: EventArgs);
    procedure textBox2_KeyPress(sender: Object; e: KeyPressEventArgs);
    procedure button1_KeyPress(sender: Object; e: KeyPressEventArgs);
  {$region FormDesigner}
  internal
    {$resource Unit2.Form2.resources}
    pictureBox1: PictureBox;
    label1: &Label;
    textBox2: TextBox;
    button2: Button;
    label2: &Label;
    label3: &Label;
    label4: &Label;
    label5: &Label;
    label6: &Label;
    label7: &Label;
    label8: &Label;
    label9: &Label;
    label10: &Label;
    label11: &Label;
    textBox1: TextBox;
    label12: &Label;
    button1: Button;
    {$include Unit2.Form2.inc}
  {$endregion FormDesigner}
  public
    constructor;
    begin
      InitializeComponent;
    end;
  end;

implementation

procedure Form2.Form2_Load(sender: Object; e: EventArgs);
begin
  
end;
procedure Form2.button1_Click(sender: Object; e: EventArgs);
begin   
      if (textBox1.Text = '1') and (Label1.Tag = 0) then
   begin
      Label1.Text:='X';
      Label1.Tag := 1;
      end;
      
      if (textBox1.Text = '2') and (Label2.Tag = 0) then
   begin
      Label2.Text:='X';
      Label2.Tag := 1;
      end; 
    
      if (textBox1.Text = '3') and (Label3.Tag = 0) then
   begin
      Label3.Text:='X';
      Label3.Tag := 1;
      end;   
      
      if (textBox1.Text = '4') and (Label4.Tag = 0) then
   begin
      Label4.Text:='X';
      Label4.Tag := 1;
      end; 
      
       if (textBox1.Text = '5') and (Label5.Tag = 0) then
   begin
      Label5.Text:='X';
      Label5.Tag := 1;
      end;  
      
       if (textBox1.Text = '6') and (Label6.Tag = 0) then
   begin
      Label6.Text:='X';
      Label6.Tag := 1;
      end;   
       
       if (textBox1.Text = '7') and (Label7.Tag = 0) then
   begin
      Label7.Text:='X';
      Label7.Tag := 1;
      end;  
      
       if (textBox1.Text = '8') and (Label8.Tag = 0) then
   begin
      Label8.Text:='X';
      Label8.Tag := 1;
      end;   
      
       if (textBox1.Text = '9') and (Label9.Tag = 0) then
   begin
      Label9.Text:='X';
      Label9.Tag := 1;
      end;   
  
  Textbox1.Clear;
  
  if (Label1.Text='X') and (Label2.Text='X') and (Label3.Text='X') then Label12.Text:='Крестики победили';//Варианты победы
  if (Label4.Text='X') and (Label5.Text='X') and (Label6.Text='X') then Label12.Text:='Крестики победили';//Варианты победы
  if (Label7.Text='X') and (Label8.Text='X') and (Label9.Text='X') then Label12.Text:='Крестики победили';//Варианты победы
  if (Label1.Text='X') and (Label5.Text='X') and (Label9.Text='X') then Label12.Text:='Крестики победили';//Варианты победы
  if (Label3.Text='X') and (Label5.Text='X') and (Label7.Text='X') then Label12.Text:='Крестики победили';//Варианты победы
  if (Label1.Text='X') and (Label4.Text='X') and (Label7.Text='X') then Label12.Text:='Крестики победили';//Варианты победы
  if (Label2.Text='X') and (Label6.Text='X') and (Label8.Text='X') then Label12.Text:='Крестики победили';//Варианты победы
  if (Label3.Text='X') and (Label6.Text='X') and (Label9.Text='X') then Label12.Text:='Крестики победили';//Варианты победы

  if button2.Enabled = true then button1.Enabled:=false; //Переход между вводами
  if button1.Enabled = true then button1.Enabled:=false; //Переход между вводами
  if button1.Enabled = false then button2.Enabled:=true; //Переход между вводами
  
  if (Label1.Text='X') and (Label2.Text='X') and (Label3.Text='X') then button2.Enabled:=false and textbox2.Enabled=false;
  if (Label4.Text='X') and (Label5.Text='X') and (Label6.Text='X') then button2.Enabled:=false and textbox2.Enabled=false;
  if (Label7.Text='X') and (Label8.Text='X') and (Label9.Text='X') then button2.Enabled:=false and textbox2.Enabled=false;
  if (Label1.Text='X') and (Label5.Text='X') and (Label9.Text='X') then button2.Enabled:=false and textbox2.Enabled=false;
  if (Label3.Text='X') and (Label5.Text='X') and (Label7.Text='X') then button2.Enabled:=false and textbox2.Enabled=false;
  if (Label1.Text='X') and (Label4.Text='X') and (Label7.Text='X') then button2.Enabled:=false and textbox2.Enabled=false;
  if (Label2.Text='X') and (Label6.Text='X') and (Label8.Text='X') then button2.Enabled:=false and textbox2.Enabled=false;
  if (Label3.Text='X') and (Label6.Text='X') and (Label9.Text='X') then button2.Enabled:=false and textbox2.Enabled=false;
  

  
  if textbox2.Enabled = true then textbox1.Enabled:=false; //Переход между TextBox
  if textbox1.Enabled = true then textbox1.Enabled:=false; //Переход между TextBox
  if textbox1.Enabled = false then textbox2.Enabled:=true; //Переход между TextBox
  
 
    
end;

procedure Form2.button2_Click(sender: Object; e: EventArgs);
begin  
   if (textBox2.Text = '1') and (Label1.Tag = 0) then
   begin
      Label1.Text:='O';
      Label1.Tag := 1;
      end;
      
      if (textBox2.Text = '2') and (Label2.Tag = 0) then
   begin
      Label2.Text:='O';
      Label2.Tag := 1;
      end; 
    
      if (textBox2.Text = '3') and (Label3.Tag = 0) then
   begin
      Label3.Text:='O';
      Label3.Tag := 1;
      end;   
      
      if (textBox2.Text = '4') and (Label4.Tag = 0) then
   begin
      Label4.Text:='O';
      Label4.Tag := 1;
      end; 
      
       if (textBox2.Text = '5') and (Label5.Tag = 0) then
   begin
      Label5.Text:='O';
      Label5.Tag := 1;
      end;  
      
       if (textBox2.Text = '6') and (Label6.Tag = 0) then
   begin
      Label6.Text:='O';
      Label6.Tag := 1;
      end;   
       
       if (textBox2.Text = '7') and (Label7.Tag = 0) then
   begin
      Label7.Text:='O';
      Label7.Tag := 1;
      end;  
      
       if (textBox2.Text = '8') and (Label8.Tag = 0) then
   begin
      Label8.Text:='O';
      Label8.Tag := 1;
      end;   
      
       if (textBox2.Text = '9') and (Label9.Tag = 0) then
   begin
      Label9.Text:='O';
      Label9.Tag := 1;
      end;   
      
  textbox2.Clear;
  
  if (Label1.Text='O') and (Label2.Text='O') and (Label3.Text='O') then Label12.Text:='Нолики победили';//Варианты победы
  if (Label4.Text='O') and (Label5.Text='O') and (Label6.Text='O') then Label12.Text:='Нолики победили';//Варианты победы
  if (Label7.Text='O') and (Label8.Text='O') and (Label9.Text='O') then Label12.Text:='Нолики победили';//Варианты победы
  if (Label1.Text='O') and (Label5.Text='O') and (Label9.Text='O') then Label12.Text:='Нолики победили';//Варианты победы
  if (Label3.Text='O') and (Label5.Text='O') and (Label7.Text='O') then Label12.Text:='Нолики победили';//Варианты победы
  if (Label1.Text='O') and (Label4.Text='O') and (Label7.Text='O') then Label12.Text:='Нолики победили';//Варианты победы
  if (Label2.Text='O') and (Label5.Text='O') and (Label8.Text='O') then Label12.Text:='Нолики победили';//Варианты победы
  if (Label3.Text='O') and (Label6.Text='O') and (Label9.Text='O') then Label12.Text:='Нолики победили';//Варианты победы

  if button2.Enabled = true then button2.Enabled :=false; //Переход между вводами
  if button2.Enabled = false then button1.Enabled :=true; //Переход между вводами
  
  if (Label1.Text='O') and (Label2.Text='O') and (Label3.Text='O') then button1.Enabled:=false and textbox1.Enabled=false;//При выполнение 
  if (Label4.Text='O') and (Label5.Text='O') and (Label6.Text='O') then button1.Enabled:=false and textbox1.Enabled=false;//
  if (Label7.Text='O') and (Label8.Text='O') and (Label9.Text='O') then button1.Enabled:=false and textbox1.Enabled=false;
  if (Label1.Text='O') and (Label5.Text='O') and (Label9.Text='O') then button1.Enabled:=false and textbox1.Enabled=false;
  if (Label3.Text='O') and (Label5.Text='O') and (Label7.Text='O') then button1.Enabled:=false and textbox1.Enabled=false;
  if (Label1.Text='O') and (Label4.Text='O') and (Label7.Text='O') then button1.Enabled:=false and textbox1.Enabled=false;
  if (Label2.Text='O') and (Label5.Text='O') and (Label8.Text='O') then button1.Enabled:=false and textbox1.Enabled=false;
  if (Label3.Text='O') and (Label6.Text='O') and (Label9.Text='O') then button1.Enabled:=false and textbox1.Enabled=false;
  
  if textbox2.Enabled = true then textbox2.Enabled :=false; //Переход между TextBox
  if textbox2.Enabled = false then textbox1.Enabled :=true; //Переход между TextBox

end;

procedure Form2.textBox1_TextChanged(sender: Object; e: EventArgs);
begin
  
end;

procedure Form2.label1_Click(sender: Object; e: EventArgs);
begin
  
end;

procedure Form2.textBox1_KeyPress(sender: Object; e: KeyPressEventArgs);
begin
   e.Handled := not (e.KeyChar in '1'..'9');//Ввод только цифровых значений
end;

procedure Form2.textBox2_TextChanged(sender: Object; e: EventArgs);
begin
  
end;

procedure Form2.textBox2_KeyPress(sender: Object; e: KeyPressEventArgs);
begin
  e.Handled := not (e.KeyChar in '1'..'9');//Ввод только цифровых значений
end;

procedure Form2.button1_KeyPress(sender: Object; e: KeyPressEventArgs);
begin

end;


end.

введите сюда описание изображения


Ответы (0 шт):