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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
program pendu_final_mot_inclu;
{$APPTYPE CONSOLE}
uses
SysUtils,
windows;
var
mot,motafficher,lettreMauvaise, motTemp : string;
lettre : char;
erreur, CptMot : integer;
Tmot : array [1..200] of string;
lettres : set of char =['a'..'z','A'..'Z',
'é','è','à','ï','ë','â','ô','î','ê'];
//---------------------------------------------//
// //
// Procédures //
// //
//---------------------------------------------//
procedure CompteMot (S : string); // 'S' remplace 'Ligne' => la fonction peut etre utilisé ailleur du coup.
var
i : Integer;
motTemp : string;
begin
for i := 1 to length(s) do // parcour du string pr trouver les mots, cad la ligne
begin
if charinset(s[i],lettres) then // si != lettre ca vx dire qu'on a un mot !
motTemp:= motTemp + s[i]
else begin
if (length(MotTemp) > 4) then
begin
CptMot:= CptMot +1; // Compteur de mot. Permet de le placer
Tmot[CptMot]:= motTemp; // ajouter au tableau
end; // 'end' du if
motTemp := ''; // vider motTemp
end; // 'end' du else if
end; // 'end' du for
end;
procedure OuvertureFichier();
var
Ligne : string;
f : text;
begin
assignfile (f, 'liste_mot_francais.txt');
reset(f); // ouvrir en lecture
while not eof(f) do
begin
readln(f,Ligne);
CompteMot(Ligne); // a chaque ligne, verifier les mot qui y sont
end;
CloseFile(f);
end;
procedure CreeMotCacher (mot:string); // permet d'afficher le mot avec des '-'
var
i:integer;
begin
for i := 1 to length(mot) do
motafficher:= motafficher + '-';
end;
procedure ajouteLettreTrouve (lettre:char) ; // remplace les '-' par les bonne lettres
var
i : integer;
begin
for i := 1 to length(mot) do
begin
if (mot[i]= lettre) then
motAfficher[i]:=lettre;
end;
end;
procedure ajouteLettreMauvaise(lettre:char) ; // Affichage des lettres inexistante
begin
lettreMauvaise:=lettreMauvaise+lettre;
dec(erreur);
end;
procedure cls; // Procédure qui permet d'effacer l'écran
var
stdOutputHandle : Cardinal;
cursorPos : TCoord;
width, height : Cardinal;
nbChars : Cardinal;
begin
stdOutputHandle := GetStdHandle(STD_OUTPUT_HANDLE);
cursorPos := GetLargestConsoleWindowSize(stdOutputHandle);
width := cursorPos.X;
height := cursorPos.Y;
cursorPos.X := 0;
cursorPos.Y := 0;
FillConsoleOutputCharacter(stdOutputHandle, ' ', width*height,
cursorPos, nbChars);
cursorPos.X := 0;
cursorPos.Y := 0;
SetConsoleCursorPosition(stdOutputHandle, cursorPos);
end;
procedure verification;
var
VerifieLettre : boolean;
i : integer;
begin
VerifieLettre:=false;
for i:=1 to length(mot) do
begin
if (mot[i] = lettre) then
begin
VerifieLettre:=true;
end;
end;
if VerifieLettre=True then
ajouteLettreTrouve (lettre)
else
ajouteLettreMauvaise(lettre);
end;
var
choix : integer;
//---------------------------------------------//
// //
// Programme principal //
// //
//---------------------------------------------//
begin
repeat
writeln('1. Jouer');
writeln('0. quitter');
writeln('Votre choix ?');
readln(choix);
cls;
case choix of
1:begin
CptMot:=0;
OuvertureFichier(); // affichage des mots trouves
lettreMauvaise:='';
erreur:=7;
writeln('//-----------------------//');
writeln('// Jeu du Pendu //');
writeln('//-----------------------//');
writeln;
Randomize;
mot:= Tmot[random(CptMot)];
CreeMotCacher(mot);
writeln('Trouvez le mot cacher. Vous avez 7 chances ;). Enjoye :p ! ');
writeln;
writeln('Le jeu commence !');
writeln;
while ((erreur <>0 ) and (motAfficher <> mot)) do
begin
writeln('Mot a trouver : ', motafficher); // Affichage mot cacher:
write('Entrer une lettre : ');
readln(lettre);
verification();
writeln('Mot cahcer : ', motafficher);
cls; // Nettoyage ecran
writeln('Les lettres erronnees : ', lettreMauvaise);
writeln('Tentative(s) restante(s) : ', erreur);
writeln;
writeln;
end;
if (erreur = 0) and (motAfficher <> mot) then // Sortie du jeu :
begin
writeln;
writeln('Partie terminee.');
writeln('La reponse etait : ', mot);
end
else
begin
writeln;
writeln(' Bravo !!! vous avez gagne :D ');
writeln;
writeln(' Le mot trouve est : ', mot);
end ;
writeln(' Merci d''avoir jouer ');
readln;
cls;
end;
0:begin
writeln('Bye Bye');
readln;
end
else
writeln('mauvais choix');
readln;
cls;
end;
until choix=0;
end. |
Partager