Jogo de adivinhação em Delphi

Responder
AlbertGaf
Mensagens: 1
Registado: sábado mar 29, 2025 11:28 pm

Jogo de adivinhação em Delphi

Mensagem por AlbertGaf »

unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
NumeroSecreto: Integer;
public
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
NumeroSecreto := Random(10) + 1; // número de 1 a 10
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Palpite: Integer;
begin
Palpite := StrToInt(Edit1.Text);

if Palpite = NumeroSecreto then
ShowMessage('Parabéns! Você acertou!')
else
ShowMessage('Errado! Tente novamente.');
end;

end.
Responder