Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef DEF_FONCTION
- #define DEF_FONCTION
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include <ctype.h>
- #include "fonction.h"
- #include "dico.h"
- #endif // DEF_FONCTION
- char lireCaractere()
- {
- char caractere = 0;
- caractere = getchar(); // On lit le premier caractère
- caractere = toupper(caractere); // On met la lettre en majuscule si elle ne l'est pas déjà
- // On lit les autres caractères mémorisés un à un jusqu'au \n (pour les effacer)
- while (getchar() != '\n') ;
- return caractere; // On retourne le premier caractère qu'on a lu
- }
- void CopierLeMotMystere(const char motMystere[], char penduMotMystere[])
- {
- int tailleMotMystere = strlen(motMystere), i = 0;
- int nombreMystere = (rand() % (tailleMotMystere - 1)) + 1;
- for(i=0;i<tailleMotMystere;i++)
- {
- penduMotMystere[i] = '-';
- }
- penduMotMystere[nombreMystere] = motMystere[nombreMystere];
- char lettreAfficher = penduMotMystere[nombreMystere];
- for(i=0;i<tailleMotMystere;i++)
- {
- if(motMystere[i] == lettreAfficher)
- {
- penduMotMystere[i] = lettreAfficher;
- }
- }
- }
- void TestCaractere(const char motMystere[],char penduMotMystere[],int *essaiRestant,int *test,char afficherFaute[])
- {
- //int caractere = lireCaractere();
- int tailleMotMystere = strlen(motMystere), i = 0;
- int variablePourEssai = 0;
- //3. char chaine[1] = "";
- *test = TestResultat(motMystere,penduMotMystere);
- if(*test != 1)
- {
- char caractere = lireCaractere();
- // char* pointerCaractere = NULL;
- //pointerCaractere = &caractere;
- for(i=0;i<tailleMotMystere;i++)
- {
- if(motMystere[i] == caractere)
- {
- penduMotMystere[i] = caractere;
- printf("\nBravo tu as trouve une lettre !!!!!!!!!!");
- }
- else
- {
- variablePourEssai++;
- }
- }
- if(variablePourEssai == tailleMotMystere)
- {
- *essaiRestant = *essaiRestant - 1;
- strcat(afficherFaute,&caractere);
- int tailleFaute = strlen(afficherFaute), p = 0;
- for(p=0;p<tailleFaute;p++)
- {
- if(afficherFaute[p] < 65 || afficherFaute[p] > 90)
- afficherFaute[p] = ' ';
- }
- }
- }
- }
- int TestResultat(const char motMystere[],const char penduMotMystere[])
- {
- int test = 0;
- if (strcmp(motMystere, penduMotMystere) == 0) // Si chaînes identiques
- {
- test = 1;
- }
- else
- {
- test = 0;
- }
- /* int test = 0, tailleMotMystere = strlen(motMystere), taille = 0,i = 0;
- for(i=0;i<tailleMotMystere;i++)
- {
- if(motMystere[i] == penduMotMystere[i])
- taille ++;
- }
- if(taille == tailleMotMystere)
- test = 1;
- else
- test = 0;
- */
- return test;
- }
- void AfficherPendu(const int essaiRestant)
- {
- int faute = 10 - essaiRestant;
- switch(faute)
- {
- case 0:
- printf("\n");
- printf("\n");
- printf("\n");
- printf("\n");
- printf("\n");
- printf("\n");
- printf("\n");
- break;
- case 1:
- printf("\n");
- printf("\n");
- printf("\n");
- printf("\n");
- printf("\n");
- printf("_____________\n");
- break;
- case 2:
- printf("\n");
- printf(" |\n");
- printf(" |\n");
- printf(" |\n");
- printf(" |\n");
- printf(" |\n");
- printf("_|____________\n");
- break;
- case 3:
- printf("_____________\n");
- printf(" |\n");
- printf(" |\n");
- printf(" |\n");
- printf(" |\n");
- printf(" |\n");
- printf("_|____________\n");
- break;
- case 4:
- printf("_____________\n");
- printf(" | /\n");
- printf(" |/\n");
- printf(" |\n");
- printf(" |\n");
- printf(" |\n");
- printf("_|____________\n");
- break;
- case 5:
- printf("_____________\n");
- printf(" | / |\n");
- printf(" |/\n");
- printf(" |\n");
- printf(" |\n");
- printf(" |\n");
- printf("_|____________\n");
- break;
- case 6:
- printf("_____________\n");
- printf(" | / |\n");
- printf(" |/ O\n");
- printf(" |\n");
- printf(" |\n");
- printf(" |\n");
- printf("_|____________\n");
- break;
- case 7:
- printf("_____________\n");
- printf(" | / |\n");
- printf(" |/ O\n");
- printf(" | |\n");
- printf(" |\n");
- printf(" |\n");
- printf("_|____________\n");
- break;
- case 8:
- printf("_____________\n");
- printf(" | / |\n");
- printf(" |/ O\n");
- printf(" | -|-\n");
- printf(" |\n");
- printf(" |\n");
- printf("_|____________\n");
- break;
- case 9:
- printf("_____________\n");
- printf(" | / |\n");
- printf(" |/ O\n");
- printf(" | -|-\n");
- printf(" | /\\\n");
- printf(" |\n");
- printf("_|____________\n");
- break;
- case 10:
- printf("_____________\n");
- printf(" | / |\n");
- printf(" |/ O\n");
- printf(" | -|-\n");
- printf(" | /\\\n");
- printf(" |\n");
- printf("_|____________\n");
- printf("Trop tard je suis mort !\n");
- break;
- default:
- break;
- }
- }
- void viderBuffer()
- {
- int c = 0;
- while (c != '\n' && c != EOF)
- {
- c = getchar();
- }
- }
- void Pause()
- {
- printf("\nAppuyez sur entrer\n");
- getchar();
- viderBuffer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement