- #include <stdio.h>
- #include <conio.c>
- #include <fcntl.h>
-
- #define MAX_MOTS 10
-
- int main()
- {
- int increment=0;
- int increment2=0;
- int sortie=1;
- int fichier;
- int caralu;
- int ligne=1;
- int hasard=0;
- int vies=5;
- char cara[100];
- char mot[15]="\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
- char essai[15]="\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
- char touche;
-
- /*GENERE UN NUMERO DE LIGNE AU HASARD*/
- while (hasard==0)
- {
- srand((unsigned)time(NULL));
- hasard=rand() % MAX_MOTS;
- }
-
- /*OUVRE PENDU.TXT, O_RDWR VEUT DIRE QU'ON
- OUVRE LE FICHIER POUR LIRE ET/OU ECRIRE DEDANS*/
- fichier=open("pendu.txt",O_RDWR);
-
- /*SI N'ARRIVE PAS A OUVRIR LE FICHIER*/
- if (fichier==-1)
- {
- printf("Impossible d'ouvrir le fichier pendu.txt\n");
- printf("V\x82rifiez qu'il est bien dans le m\x88me\n");
- printf("r\x82pertoire que l'executable.");
- getch();
- return 1;
- }
-
- caralu=read(fichier,cara,100); //LIT LE CONTENU DU FICHIER
-
- //TANT QU'ON N'EST PAS AU NUMERO DE LIGNE
- //EGAL A HASARD COMPTE LE NOMBRE DE LIGNE
- while (hasard!=ligne)
- {
- if (cara[increment]=='\n') ligne++;
- increment++;
- }
-
- /*TANT QUE LA LIGNE N'EST PAS TERMINEE*/
- while (cara[increment]!='\n')
- {
- mot[increment2]=cara[increment];
- essai[increment2]='?';
- increment2++;
- increment++;
- }
- close(fichier); //REFERME LE FICHIER
- while (sortie==1)
- {
- gotoxy(1,1);
- printf("%s\n\n",essai);
- gotoxy(1,4);
- printf("Il reste %d vies",vies);
- gotoxy(1,5);
- printf("Appuyez sur une lettre ");
- touche=getch();
- if (touche==27) sortie=0; //SI ESCAPE QUITTE
- /*SI C'EST UNE MAJUSCULE TRANSFORME EN MINUSCULE*/
- if ((touche<=90)&&(touche>=65)) touche=touche+32;
- /*SI UNE LETTRE A ETE PRESSEE*/
- if ((touche<=122)&&(touche>=97))
- {
- increment2=0;
- for (increment=0 ; increment<=14 ; increment++)
- {
- if (mot[increment]==touche)
- {
- if (essai[increment]==touche)
- {
- gotoxy(1,6);
- printf("Vous avez deja trouve cette lettre ! ");
- vies--;
- }
- else
- {
- gotoxy(1,6);
- printf("Bravo ! Vous avez trouve la lettre %c ! ",touche);
- essai[increment]=touche;
- }
- }
- else increment2++;
- }
- if (increment2==increment)
- {
- gotoxy(1,6);
- printf("Rate ! Cette lettre n'est pas dans le mot ! ");
- vies--;
- }
- }
- if (vies<0)
- {
- gotoxy(1,8);
- printf("PERDU ! Vous n'avez pas trouve le mot !");
- sortie=0;
- getch();
- }
- increment2=0;
- for (increment=0 ; increment<=14 ; increment++)
- {
- if (mot[increment]==essai[increment]) increment2++;
- }
- if (increment2==15)
- {
- gotoxy(1,8);
- printf("BRAVO ! Vous avez trouve le mot ! vous avez gagne !");
- gotoxy(1,1);
- printf("%s",essai);
- sortie=0;
- getch();
- }
- }
- }
#include <stdio.h>
#include <conio.c>
#include <fcntl.h>
#define MAX_MOTS 10
int main()
{
int increment=0;
int increment2=0;
int sortie=1;
int fichier;
int caralu;
int ligne=1;
int hasard=0;
int vies=5;
char cara[100];
char mot[15]="\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
char essai[15]="\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
char touche;
/*GENERE UN NUMERO DE LIGNE AU HASARD*/
while (hasard==0)
{
srand((unsigned)time(NULL));
hasard=rand() % MAX_MOTS;
}
/*OUVRE PENDU.TXT, O_RDWR VEUT DIRE QU'ON
OUVRE LE FICHIER POUR LIRE ET/OU ECRIRE DEDANS*/
fichier=open("pendu.txt",O_RDWR);
/*SI N'ARRIVE PAS A OUVRIR LE FICHIER*/
if (fichier==-1)
{
printf("Impossible d'ouvrir le fichier pendu.txt\n");
printf("V\x82rifiez qu'il est bien dans le m\x88me\n");
printf("r\x82pertoire que l'executable.");
getch();
return 1;
}
caralu=read(fichier,cara,100); //LIT LE CONTENU DU FICHIER
//TANT QU'ON N'EST PAS AU NUMERO DE LIGNE
//EGAL A HASARD COMPTE LE NOMBRE DE LIGNE
while (hasard!=ligne)
{
if (cara[increment]=='\n') ligne++;
increment++;
}
/*TANT QUE LA LIGNE N'EST PAS TERMINEE*/
while (cara[increment]!='\n')
{
mot[increment2]=cara[increment];
essai[increment2]='?';
increment2++;
increment++;
}
close(fichier); //REFERME LE FICHIER
while (sortie==1)
{
gotoxy(1,1);
printf("%s\n\n",essai);
gotoxy(1,4);
printf("Il reste %d vies",vies);
gotoxy(1,5);
printf("Appuyez sur une lettre ");
touche=getch();
if (touche==27) sortie=0; //SI ESCAPE QUITTE
/*SI C'EST UNE MAJUSCULE TRANSFORME EN MINUSCULE*/
if ((touche<=90)&&(touche>=65)) touche=touche+32;
/*SI UNE LETTRE A ETE PRESSEE*/
if ((touche<=122)&&(touche>=97))
{
increment2=0;
for (increment=0 ; increment<=14 ; increment++)
{
if (mot[increment]==touche)
{
if (essai[increment]==touche)
{
gotoxy(1,6);
printf("Vous avez deja trouve cette lettre ! ");
vies--;
}
else
{
gotoxy(1,6);
printf("Bravo ! Vous avez trouve la lettre %c ! ",touche);
essai[increment]=touche;
}
}
else increment2++;
}
if (increment2==increment)
{
gotoxy(1,6);
printf("Rate ! Cette lettre n'est pas dans le mot ! ");
vies--;
}
}
if (vies<0)
{
gotoxy(1,8);
printf("PERDU ! Vous n'avez pas trouve le mot !");
sortie=0;
getch();
}
increment2=0;
for (increment=0 ; increment<=14 ; increment++)
{
if (mot[increment]==essai[increment]) increment2++;
}
if (increment2==15)
{
gotoxy(1,8);
printf("BRAVO ! Vous avez trouve le mot ! vous avez gagne !");
gotoxy(1,1);
printf("%s",essai);
sortie=0;
getch();
}
}
}