1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.math, System.Types;
type
TForm1 = class(TForm)
Jouer: TButton;
procedure JouerClick(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.JouerClick(Sender: TObject);
var
nbSecret, NbTest, coup: integer;
reponse, msg: string;
begin
coup := 0;
randomize;
nbSecret := Trunc(Random(101));
// showmessage(nbSecret.tostring);
repeat
InputQuery('Saisissez un nombre', 'valeur', reponse);
NbTest := strtointdef(reponse, -1);
if NbTest = -1 then
exit;
inc(coup);
case CompareValue(NbTest, nbSecret) of
LessThanValue:
msg := format('Le nombre secret est supérieur à %d ',[NbTest]);
EqualsValue :
begin
if coup = 1 then
msg := format('Nombre secret %d trouvé du premier coup !',
[nbSecret])
else
msg := format
('Félicitation, vous avez trouvé le nombre secret qui est : %d en %d coups',
[nbSecret, coup]);
end;
GreaterThanValue :
msg := format('Le nombre secret est inférieur à %d', [NbTest]);
end;
Showmessage(msg);
until (NbTest = nbSecret);
end;
end. |
Partager