⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 简单的井字游戏!
💻 PAS
字号:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Image1: TImage;
    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 Button11Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
  private
  A:array[1..3,1..3] of integer;



    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  p:Boolean;
  k:Boolean;

  cnt:integer;

implementation

uses Unit2, Unit4, Unit3;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if k then
  begin
    if p then
    begin
      Button1.Caption:='O';
      A[1][1]:=1;
      p:=false;
      if (A[1][2]=1) and (A[1][3]=1) then
      begin
         form3.showmodal;
        k:=false;
      end
       else
       if (A[2][2]=1) and (A[3][3]=1) then
       begin
        form3.showmodal;
        k:=false;
      end
      else
       if (A[2][1]=1) and (A[3][1]=1) then
         begin
        form3.showmodal;
        k:=false;
        end
      end
    else
    begin
      Button1.Caption:='X';
      A[1][1]:=2;
      p:=True;
      if (A[1][2]=2) and (A[1][3]=2) then
       begin
          form2.showmodal;
        k:=false;
      end
      else
        if (A[2][2]=2) and (A[3][3]=2) then
       begin
           form2.showmodal;
        k:=false;
      end
      else
        if (A[2][1]=2) and (A[3][1]=2) then
       begin
          form2.showmodal;
        k:=false;
      end

  end;
  Inc(cnt);
     if (cnt=9) and k then
       form4.showmodal;
     Button1.Enabled:=false;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if k then
  begin
  if k then
  begin
    Button2.Caption:='O';
     A[1][2]:=1;
   p:=false;
    if (A[1][1]=1) and (A[1][3]=1) then
     begin
         form3.showmodal;
        k:=false;
      end
    else
      if (A[2][2]=1) and (A[3][2]=1) then
      begin
         form3.showmodal;
        k:=false;
      end
  end
  else
  begin
    Button2.Caption:='X';
     A[1][2]:=2;
    p:=True;
    if (A[1][1]=2) and (A[1][3]=2) then
      begin
          form2.showmodal;
        k:=false;
      end
    else
      if (A[2][2]=2) and (A[3][2]=2) then
       begin
          form2.showmodal;
        k:=false;
      end
   end;

  Inc(cnt);
      if (cnt=9) and k then
       form4.showmodal;
       Button2.Enabled:=false;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  if k then
  begin
  if p then
  begin
    Button3.Caption:='O';
     A[1][3]:=1;
    p:=false;
    if (A[1][1]=1) and (A[1][2]=1) then
        begin
         form3.showmodal;
        k:=false;
      end
       else
        if (A[2][2]=1) and (A[3][1]=1) then
         begin
         form3.showmodal;
        k:=false;
      end
    else
      if (A[2][3]=1) and (A[3][3]=1) then
      begin
         form3.showmodal;
        k:=false;
      end
  end
  else
  begin
    Button3.Caption:='X ';
     A[1][3]:=2;
    p:=True;
    if (A[1][1]=2) and (A[1][2]=2) then
      begin
         form2.showmodal;
        k:=false;
      end
      else
        if (A[2][2]=2) and (A[3][1]=2) then
         begin
        form2.showmodal;
        k:=false;
      end
    else
      if (A[2][3]=2) and (A[3][3]=2) then
      begin
        form2.showmodal;
        k:=false;
      end
  end;
  Inc(cnt);
      if (cnt=9) and k then
    form4.showmodal;
       Button3.Enabled:=false;
  end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  if k then
  begin
  if p then
  begin
    Button4.Caption:='O';
     A[2][1]:=1;
    p:=false;
    if (A[1][1]=1) and (A[3][1]=1) then
       begin
       form3.showmodal;
        k:=false;
      end
    else
      if (A[2][2]=1) and (A[2][3]=1) then
       begin
      form3.showmodal;
       k:=false;
      end
  end
  else
  begin
    Button4.Caption:='X ';
     A[2][1]:=2;
    p:=True;
    if (A[1][1]=2) and (A[3][1]=2) then
       begin
       form2.showmodal;
       k:=false;
      end
    else
      if (A[2][2]=2) and (A[2][3]=2) then
       begin
        form2.showmodal;
        k:=false;
      end
  end;
  Inc(cnt);
     if (cnt=9) and k then
    form4.showmodal;
       Button4.Enabled:=false;
    end;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  if k then
  begin
  if p then
  begin
    Button5.Caption:='O';
     A[2][2]:=1;
    p:=false;
    if (A[1][2]=1) and (A[3][2]=1) then
        begin
     form3.showmodal;
        k:=false;
      end
    else
      if (A[1][3]=1) and (A[3][1]=1) then
         begin
       form3.showmodal;
       k:=false;
      end
        else
          if (A[1][1]=1) and (A[3][3]=1) then
           begin
      form3.showmodal;
        k:=false;
      end
      else
      if (A[2][1]=1) and (A[2][3]=1) then
       begin
      form3.showmodal;
        k:=false;
      end
  end
  else
  begin
    Button5.Caption:='X ';
     A[2][2]:=2;
     p:=True;
    if (A[1][2]=2) and (A[3][2]=2) then
        begin
      form2.showmodal;
        k:=false;
      end
    else
      if (A[1][3]=2) and (A[3][1]=2) then
         begin
      form2.showmodal;
        k:=false;
      end
        else
          if (A[1][1]=2) and (A[3][3]=2) then
           begin
      form2.showmodal;
        k:=false;
      end
      else
      if (A[2][1]=2) and (A[2][3]=2) then
       begin
      form2.showmodal;
        k:=false;
      end
  end;
  Inc(cnt);
      if (cnt=9) and k then
    form4.showmodal;
       Button5.Enabled:=false;
  end;
end;


procedure TForm1.Button6Click(Sender: TObject);
begin
  if k then
  begin
  if p then
  begin
    Button6.Caption:='O ';
     A[2][3]:=1;
    p:=false;
    if (A[1][3]=1) and (A[3][3]=1) then
       begin
       form3.showmodal;
        k:=false;
      end
    else
      if (A[2][1]=1) and (A[2][2]=1) then
      begin
       form3.showmodal;
        k:=false;
      end
  end
  else
  begin
    Button6.Caption:='X';
     A[2][3]:=2;
    p:=True;
    if (A[1][3]=2) and (A[3][3]=2) then
       begin
       form2.showmodal;
        k:=false;
      end
    else
      if (A[2][1]=2) and (A[2][2]=2) then
       begin
       form2.showmodal;
        k:=false;
      end
  end;
  Inc(cnt);
     if (cnt=9) and k then
      form4.showmodal;
       Button6.Enabled:=false;
  end;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
  if k then
  begin
  if p then
  begin
     Button7.Caption:='O';
      A[3][1]:=1;
   p:=false;
    if (A[1][1]=1) and (A[2][1]=1) then
        begin
         form3.showmodal;
       k:=false;
      end
    else
      if (A[3][2]=1) and (A[3][3]=1) then
       begin
          form3.showmodal;
        k:=false;
      end
      else
       if (A[1][3]=1) and (A[2][2]=1) then
         begin
          form3.showmodal;
        k:=false;
      end
  end
  else
  begin
    Button7.Caption:='X';
     A[3][1]:=2;
    p:=true;
    if (A[1][1]=2) and (A[2][1]=2) then
       begin
       form2.showmodal;
        k:=false;
      end
    else
      if (A[3][2]=2) and (A[3][3]=2) then
       begin
        form2.showmodal;
       k:=false;
      end
      else
       if (A[1][3]=2) and (A[2][2]=2) then
         begin
      form2.showmodal;
        k:=false;
      end
  end;
  Inc(cnt);
    if (cnt=9) and k then
      form4.showmodal;
       Button7.Enabled:=false;
  end;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
  if k then
  begin
  if p then
  begin
    Button8.Caption:='O';
     A[3][2]:=1;
    p:=false;
    if (A[1][2]=1) and (A[2][2]=1) then
        begin
          form3.showmodal;
        k:=false;
      end
    else
      if (A[3][1]=1) and (A[3][3]=1) then
       begin
          form3.showmodal;
        k:=false;
      end
  end
  else
  begin
    Button8.Caption:='X';
     A[3][2]:=2;
    p:=True;
    if (A[1][2]=2) and (A[2][2]=2) then
       begin
       form2.showmodal;
        k:=false;
      end
    else
      if (A[3][1]=2) and (A[3][3]=2) then
      begin
       form2.showmodal;
        k:=false;
      end
  end;
  Inc(cnt);
     if (cnt=9) and k then
      form4.showmodal;
       Button8.Enabled:=false;
  end;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
  if  K then
  begin
  if p then
  begin
    Button9.Caption:='O';
     A[3][3]:=1;
    p:=false;
    if (A[1][3]=1) and (A[2][3]=1) then
        begin
       form3.showmodal;
        k:=false;
      end
    else
      if (A[3][1]=1) and (A[3][2]=1) then
       begin
       form3.showmodal;
        k:=false;
      end
      else
       if (A[1][1]=1) and (A[2][2]=1) then
         begin
       form3.showmodal;
        k:=false;
      end
  end
  else
  begin
    Button9.Caption:='X';
     A[3][3]:=2;
    p:=true;
    if (A[1][3]=2) and (A[2][3]=2) then
        begin
       form2.showmodal;
        k:=false;
      end
    else
      if (A[3][1]=2) and (A[3][2]=2) then
      begin
       form2.showmodal;
        k:=false;
      end
      else
       if (A[1][1]=2) and (A[2][2]=2) then
        begin
      form2.showmodal;
        k:=false;
      end               
  end;
  Inc(cnt);
      if (cnt=9) and k then
      form4.showmodal;
       Button9.Enabled:=false;
  end;
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.Button10Click(Sender: TObject);
var n,m:integer;
begin
  k:=True;
  p:=True;
   cnt:=0;

    for n:=1 to 3 do
      for m:=1 to 3 do
      A[n][m]:=0;
    Button1.Caption:=' ';
    Button2.Caption:=' ';
    Button3.Caption:=' ';
    Button4.Caption:=' ';
    Button5.Caption:=' ';
    Button6.Caption:=' ';
    Button7.Caption:=' ';
    Button8.Caption:=' ';
    Button9.Caption:=' ';
    A[1,1]:=0;
    A[1,2]:=0;
    A[1,2]:=0;
    A[2,1]:=0;
    A[2,2]:=0;
    A[2,3]:=0;
    A[3,1]:=0;
    A[3,2]:=0;
    A[3,3]:=0;
    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;



end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -