unit Unit1;
{$mode Delphi}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
Buttons;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
ImageList1: TImageList;
Label1: TLabel;
Label2: TLabel;
reiniciar: TButton;
RadioGroup1: TRadioGroup;
SpeedButton1: TSpeedButton;
procedure buttonClick(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
private
public
end;
var
Form1 : TForm1;
CartaVirada1 : TSpeedButton;
CartaVirada2 : TSpeedButton;
ViradasJogador : Integer;
ViradasIa : Integer;
jogadaJogador : integer;
guardado: array[0..15] of TSpeedbutton;
I : Integer;
botao : TSpeedButton;
implementation
{$R *.lfm}
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
cont : Integer;
num : Integer;
linha : Integer;
coluna : Integer;
capBotao : array[0..7] of String = ('A','B', 'C', 'D', 'E', 'F','G','H');
capBotao2 : array[0..7] of String = ('A','B', 'C', 'D', 'E', 'F','G','H');
capBotaoRandom : array[0..7] of String = ('.','.', '.', '.', '.', '.','.','.');
Resultado : array[0..15] of String = ('.', '.', '.', '.', '.', '.', '.', '.', '.',
'.', '.', '.', '.', '.', '.', '.');
begin
label2.caption := 'Jogando:';
RadioGroup1.Visible := false;
reiniciar.visible := true;
reiniciar.enabled := true;
Randomize;
cont := 0;
linha := 30;
coluna := 30;
for I := 0 to 7 do
begin
cont := Random(8);
capBotaoRandom[I] := capBotao[cont];
while capBotao[cont] = '.' do
begin
cont := Random(8);
capBotaoRandom[I] := capBotao[cont];
end;
capBotao[cont] := '.';
for num := 0 to 7 do
begin
Resultado[num] := capBotaoRandom[num];
end;
end;
for I := 0 to 7 do
begin
cont := Random(8);
capBotaoRandom[I] := capBotao2 [cont];
while capBotao2 [cont] = '.' do
begin
cont := Random(8);
capBotaoRandom[I] := capBotao2 [cont];
end;
capBotao2[cont] := '.';
end;
for num := 0 to 7 do
begin
resultado[num + 8] := capBotaoRandom[num];
end;
for I := 0 to 15 do
begin
botao := TSpeedButton.Create(Self);
botao.Parent := Form1;
botao.Height := 150;
botao.Width := 150;
botao.Top := coluna;
botao.Left := linha;
botao.Hint := resultado[I];
botao.Name := 'btn' + IntToStr(I);
botao.Caption := '';
botao.OnClick := buttonClick();
guardado[I] := botao;
ImageList1.GetBitmap(I, TSpeedButton[I].Glyph);
if ((I+1) mod 4 = 0) then
begin
coluna := coluna + 150;
linha := 30;
end
else
linha := linha + 150;
end;
end;
procedure TForm1.buttonClick(Sender: TObject);
begin
if(Sender as TSpeedButton).Caption = '' then
(Sender as TSpeedButton).Caption := (Sender as TSpeedButton).Hint
else
(Sender as TSpeedButton).Caption := '';
Application.ProcessMessages;
ViradasJogador := ViradasJogador + 1;
if(ViradasJogador mod 2 = 1)then
CartaVirada1 := (Sender as TSpeedButton);
CartaVirada1.Enabled := false;
if(ViradasJogador mod 2 = 0) then
begin
CartaVirada2 := (Sender as TSpeedButton);
CartaVirada1.Enabled := true;
if(CartaVirada1.Name = CartaVirada2.Name) then
begin
CartaVirada1.Caption := '';
CartaVirada2.Caption := '';
end
else if(CartaVirada2.Caption = CartaVirada1.Caption) then
begin
CartaVirada1.Visible := false;
CartaVirada2.Visible := false;
end;
if (CartaVirada2.Caption <> CartaVirada1.Caption) then
begin
label1.caption := 'PC';
Sleep(900);
CartaVirada1.Caption := '';
CartaVirada2.Caption := '';
end;
CartaVirada1 := Nil;
CartaVirada2 := Nil;
jogadaJogador := 1;
end;
if label1.caption = 'PC' then
begin
end;
end;
end.