unit Unit1;
{$mode Delphi}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
GroupBox2: TGroupBox;
procedure FormCreate(Sender: TObject);
procedure FormDblClick(Sender: TObject);
procedure Clique(Sender: TObject);
private
public
end;
var
Form1: TForm1;
CartaVirada1 : TButton;
CartaVirada2 : TButton;
Viradas : Integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Clique(Sender: TObject);
begin
if(Sender as TButton).Caption = 'OK' then
begin
ShowMessage('Esta carta já foi virada');
end
else if(Sender as TButton).Caption <> 'OK' then
begin
if(Sender as TButton).Caption = '' then
(Sender as TButton).Caption := (Sender as TButton).Hint
else
(Sender as TButton).Caption := '';
Viradas := Viradas + 1;
if(Viradas mod 2 = 1)then
CartaVirada1 := (Sender as TButton);
if(Viradas mod 2 = 0) then
begin
CartaVirada2 := (Sender as TButton);
if(CartaVirada1.Name = CartaVirada2.Name) then
begin
CartaVirada1.Caption := '';
CartaVirada2.Caption := '';
end
else if(CartaVirada2.Caption = CartaVirada1.Caption) then
begin
CartaVirada1.Caption := 'OK';
CartaVirada2.Caption := 'OK';
end;
end;
if (CartaVirada2.Caption <> CartaVirada1.Caption) then
begin
ShowMessage('Tente Novamente');
CartaVirada1.Caption := '';
CartaVirada2.Caption := '';
end;
CartaVirada1 := Nil;
CartaVirada2 := Nil;
end;
end;
procedure TForm1.FormDblClick(Sender: TObject);
var
I : Integer;
cont : Integer;
num : Integer;
linha : Integer;
coluna : Integer;
botao : Tbutton;
letras : array[0..5] of char = ('A','B', 'C', 'D', 'E', 'F');
letras2 : array[0..5] of char = ('A','B', 'C', 'D', 'E', 'F');
letrasRandom : array[0..5] of char = ('.','.', '.', '.', '.', '.');
Result :
array[0..11] of char = ('.','.', '.', '.', '.','.','.','.', '.', '.', '.', '.');
begin
Randomize;
cont := 0;
linha := 30;
coluna := 30;
for I := 0 to 5 do
begin
cont := Random(6);
letrasRandom[I] := letras[cont];
while letras[cont] = '.' do
begin
cont := Random(6);
letrasRandom[I] := letras[cont];
end;
letras[cont] := '.';
end;
for num := 0 to 5 do
begin
Result[num] := letrasRandom[num];
end;
for I := 0 to 5 do
begin
cont := Random(6);
letrasRandom[I] := letras2[cont];
while letras2[cont] = '.' do
begin
cont := Random(6);
letrasRandom[I] := letras2[cont];
end;
letras2[cont] := '.';
end;
for num := 0 to 5 do
begin
Result[num + 6] := letrasRandom[num];
end;
for I := 0 to 11 do
begin
botao := TButton.Create(Self);
botao.Parent := Form1;
botao.Height := 90;
botao.Width := 90;
botao.Top := coluna;
botao.Left := linha;
botao.Hint := Result[I];
botao.Name := 'btn' + IntToStr(I);
botao.Caption := '';
botao.OnClick := Clique();
if ((I+1) mod 3 = 0) then
begin
coluna := coluna + 90;
linha := 30;
end
else
linha := linha + 90;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
end.