Program S7;
Uses crt;
Var
mot,masque : string;
//********************************************
Function verif(ch:String) : Boolean;
Var
i : Integer;
test : Boolean;
Begin
i := 0;
Repeat
i := i+1;
If (Upcase(ch[i]) In ['A'..'Z']) Then
test := True
Else test := False;
Until (i>=Length(ch)) Or Not(test);
verif := test And (Length(ch) In [5..20]);
End;
//********************************************
Function masquer(ch:String) : string;
Var
i : Integer;
ch1 : string;
Begin
ch1 := '';
ch1 := ch1+ch[1];
For i:=1 To (Length(ch)-2) Do
ch1 := ch1+'-';
ch1 := ch1+ch[Length(ch)];
masquer := ch1;
End;
//********************************************
Procedure remplace(Var ch:String;ch1:String;c:Char);
Var
i : Integer;
Begin
For i:=2 To (Length(ch)-1) Do
Begin
If ch1[i]=c Then
ch[i] := c;
End;
End;
//********************************************
Procedure deviner(mot:String;Var masque:String);
Var
tentative : Integer;
c : Char;
Begin
Writeln('le mot à deviner est ',masque);
tentative := Length(mot);
Repeat
Writeln('il vous reste ',tentative,' essai(s)');
Repeat
write('proposer un caractere :');
Readln(c);
Until (Upcase(c) In ['A'..'Z']);
remplace(masque,mot,c);
If (masque<>mot) Then
Begin
tentative := tentative-1;
If tentative<>0 Then
Writeln('le mot à deviner est ',masque);
End;
Until (masque=mot) Or (tentative<=0);
If (tentative<=0) Then
Writeln('desole, vous avez perdu ')
Else
Begin
Writeln('bravo, vous avez gagne ');
writeln('le mot masqué est : ',mot);
End;
End;
//********************************************
Begin
Repeat
write('saisir le mot à deviner :');
Readln(mot);
Until verif(mot);
Clrscr;
masque := masquer(mot);
deviner(mot,masque);
End.
Inscription à :
Publier les commentaires (Atom)