unit Unit4;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    start: TEdit;
    finish: TEdit;
    p11: TLabel;
    chl: TEdit;
    znak1: TLabel;
    p12: TLabel;
    ch2: TEdit;
    znak2: TLabel;
    X: TLabel;
    comp: TCheckBox;
    Button1: TButton;
    Button2: TButton;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  num, j, i, kolvo, big, small: integer;
maximum, minimum: array [1..100] of integer;
type
TForml=class(TForm)
private
{ Private declarations}
procedure min () ;
procedure max () ;
public
{Public declarations}
end;

implementation
procedure TForml.min();
begin
for i:=1 to kolvo do begin
for j:=1 to kolvo do begin
if minimum[j] > small then small := minimum[j];
end;
end;
end;
procedure Tforml.max();
var temp: integer;
begin
temp :=StrTolnt (finish.Text);
for i:=1 to kolvo do begin
for j:=1 to kolvo do begin
if temp > maximum[j] then
if maximumtj] > 0 then temp:=maximum[j];
end;
end;
if ( (temp <> 0) and (temp <> StrTolnt(finish.Text)) ) then
big := temp;
end;
procedure TForml.FormCreate(Sender: TObject);
begin
Randomize;
num := Random(StrToInt(finish.Text) - StrToInt(start.Text)) + StrToInt(start.Text);
kolvo := 0;
big := StrToInt(finish.Text);
small := StrToInt(start.Text);
end;
procedure TForml.Button2Click(Sender: TObject);
begin
kolvo := kolvo + 1;
begin
if pll.Enabled then begin
if StrToInt(chl.Text) > num then znakl.Caption := '>';
if StrToInt(chl.Text) < nun then znakl.Caption : '<';
if StrToInt(chl.Text) num then
begin
znakl.Caption := '=';
х.Caption := IntToStr(num);
ShowMessage('Победил первый игрок!' + #13#10 + 'Число угадано за ' + IntToStr(kolvo) + ' попытки')
end;
pll.Enabled := False;
chl.Enabled := False;
ch2.Enabled := True;
pl2.Enabled := True;
Exit;
end;
if pl2.Enabled then begin
if StrToInt(ch2.Text) > num then znak2.Caption := '>';
if StrToInt(ch2.Text) < num then znak2.Caption := '<';
if StrToInt(ch2.Text) = num then
begin
znak2.Caption := ' =' ;
x.Caption := IntToStr(num);
ShowMessage('Победил второй игрок!1 + #13#10 +'Число угадано За ' +IntToStr(kolvo) +'попытки')
end;
end;
р12.Enabled := False;
ch2.Enabled := False;
chl.Enabled := True;
pll.Enabled := True;
Expend;
if comp.Checked then begin
if StrToInt(chl.Text) > num then znakl.Caption := '>';
if StrToInt(chl.Text) < num then znakl.Caption := '<';
if StrToInt(chl.Text) = num then
begin
znakl.Caption := '=';
x.Caption := IntToStr(num);
ShowMessage('Вы победили!' + #13#10 + 'Число угадано за ' + IntToStr(kolvo) +' попытки');
Exit;
end;
if znakl.Caption = '>' then
begin
maximum[kolvo] := StrToInt(chl.Text);
max();
end;
if znakl.Caption = '<' then begin
minimum[kolvo] := StrToInt(chl.Text);
min();
end;
ch2.Text := IntToStr(Random(big - small) + small);
end;
if StrToInt(ch2.Text) > num then znak2.Caption := '>';
if StrToInt(ch2.Text) < num then znak2.Caption := '<';
if StrToInt(ch2.Text) = num then begin
znak2.Caption := '=';
x.Caption := IntToStr(num);
ShowMessage('Вы проиграли!' + #13#10 +'В этот раз победил компьютер!' + #13#10 +'Число угадано за ' +IntToStr(kolvo) + 1 попытки');
end;
end;
procedure TForml.compClick(Sender: TObject);
begin
if comp.Checked then begin
ch2.Enabled := False;
р12.Enabled := False;
chl.Enabled := True;
pll.Enabled := Truerend
else begin
ch2.Enabled := True;
р12.Enabled := True;
end;
end;
procedure TForml.ButtonlClick(Sender: TObject);
begin
if ((StrToInt(finish.Text) > StrToInt(start.Text)) and
(StrToInt(start.Text) > 0) and
(StrToInt(finish.Text) < 60000))
then
num := Random(StrToInt(finish.Text) - StrToInt(start.Text)) +StrToInt(start.Text)
else ShowMessage('Неверный диапазон!');
znakl.Caption := ' ' ;
znak2 . Caption : = ' ' ;
chl.Enabled := True;
ch2.Enabled := False;
pll.Enabled := True;
pl2.Enabled := False;
x.Caption :='X';
chl.Text :='0';
ch2.Text := '0';
for i:=1 to kolvo+1 do
begin
minimum[i] := 0;
maximum[i] := 0;
big := StrToInt(finish.Text);
small := StrToInt(start.Text);
end;
kolvo := 0;
end;
end.
