unit Unit13;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Mask, ComCtrls, StdCtrls;
type
TForm2 = class(TForm)
AcceptBtn: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Memo1: TMemo;
Memo2: TMemo;
Memo3: TMemo;
ProgressBar1: TProgressBar;
MaskEdit1: TMaskEdit;
SecretLabel: TLabel;
Timer1: TTimer;
procedure AcceptBtnClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SecretLabelClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
public
procedure Init;
end;
TMatrix = class
private
Password : String;
Matr : array[1..15, 1..15] of Integer;
public
constructor Create;
function ChkPsswrd(pwd : String) : Boolean;
procedure GenPass;
end;
var
Form2 : TForm2;
MyMatrix : TMatrix;
implementation
{$R *.dfm}
constructor TMatrix.Create;
var
I, J : Byte;
begin
inherited Create;
Randomize;
for I := 1 to 15 do
for J := 1 to 15 do
Matr[I, J] := Random(9);
end;
function TMatrix.ChkPsswrd(pwd : String) : Boolean;
begin
ChkPsswrd := pwd = password;
end;
procedure TMatrix.GenPass;
begin
password := IntToStr(Matr[10, 11]);
password := password + IntToStr(Matr[7, 7]);
password := password + IntToStr(Matr[5, 12]);
password := password + IntToStr(Matr[11, 2]);
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
Init;
Timer1.Enabled := True;
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Assigned(MyMatrix) then
MyMatrix.Free;
end;
procedure TForm2.Init;
var
I, J : Byte;
LineBuffer : String;
begin
MyMatrix := TMatrix.Create;
MyMatrix.GenPass;
Memo1.Lines.Clear;
LineBuffer := '';
for I := 1 to 15 do
begin
for J := 1 to 15 do
LineBuffer := LineBuffer + IntToStr(MyMatrix.Matr[I, J]) + ' ';
Memo1.Lines.Add(LineBuffer);
LineBuffer := '';
end;
end;
procedure TForm2.AcceptBtnClick(Sender: TObject);
begin
if MaskEdit1.Text = MyMatrix.password then
Timer1.Enabled := False;
end;
procedure TForm2.SecretLabelClick(Sender: TObject);
begin
SecretLabel.Caption := MyMatrix.password;
end;
procedure TForm2.Timer1Timer(Sender: TObject);
var
I, J : Byte;
LineBuffer : String;
begin
if ProgressBar1.Position = 0 then
begin
if not Assigned(MyMatrix) then
MyMatrix := TMatrix.Create;
MyMatrix.GenPass;
Memo1.Lines.Clear;
Memo1.Update;
LineBuffer := '';
for I := 1 to 15 do
begin
for J := 1 to 15 do
LineBuffer := LineBuffer + IntToStr(MyMatrix.Matr[I, J]) + ' ';
Memo1.Lines.Add(LineBuffer);
LineBuffer := '';
end;
ProgressBar1.Position := 30;
end;
ProgressBar1.Position := ProgressBar1.Position - 1;
end;
end.