Advertisement
Vincent38190

fonction.c

Jan 20th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.25 KB | None | 0 0
  1. #ifndef DEF_FONCTION
  2. #define DEF_FONCTION
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <time.h>
  7. #include <ctype.h>
  8. #include "fonction.h"
  9. #include "dico.h"
  10. #endif // DEF_FONCTION
  11.  
  12.  
  13.  
  14. char lireCaractere()
  15. {
  16.     char caractere = 0;
  17.     caractere = getchar(); // On lit le premier caractère
  18.     caractere = toupper(caractere); // On met la lettre en majuscule si elle ne l'est pas déjà
  19.  
  20.     // On lit les autres caractères mémorisés un à un jusqu'au \n (pour les effacer)
  21.     while (getchar() != '\n') ;
  22.  
  23.     return caractere; // On retourne le premier caractère qu'on a lu
  24. }
  25.  
  26. void CopierLeMotMystere(const char motMystere[], char penduMotMystere[])
  27. {
  28.  
  29.     int tailleMotMystere = strlen(motMystere), i = 0;
  30.     int nombreMystere = (rand() % (tailleMotMystere - 1)) + 1;
  31.     for(i=0;i<tailleMotMystere;i++)
  32.     {
  33.         penduMotMystere[i] = '-';
  34.     }
  35.     penduMotMystere[nombreMystere] = motMystere[nombreMystere];
  36.     char lettreAfficher = penduMotMystere[nombreMystere];
  37.     for(i=0;i<tailleMotMystere;i++)
  38.     {
  39.         if(motMystere[i] == lettreAfficher)
  40.         {
  41.             penduMotMystere[i] = lettreAfficher;
  42.         }
  43.  
  44.     }
  45.  
  46. }
  47.  
  48. void TestCaractere(const char motMystere[],char penduMotMystere[],int *essaiRestant,int *test,char afficherFaute[])
  49. {
  50.         //int caractere = lireCaractere();
  51.       int tailleMotMystere = strlen(motMystere), i = 0;
  52.       int variablePourEssai = 0;
  53.      //3. char chaine[1] = "";
  54.       *test = TestResultat(motMystere,penduMotMystere);
  55.     if(*test != 1)
  56.     {
  57.            char caractere = lireCaractere();
  58.           // char* pointerCaractere = NULL;
  59.            //pointerCaractere = &caractere;
  60.            for(i=0;i<tailleMotMystere;i++)
  61.       {
  62.         if(motMystere[i] == caractere)
  63.         {
  64.             penduMotMystere[i] = caractere;
  65.             printf("\nBravo tu as trouve une lettre !!!!!!!!!!");
  66.         }
  67.         else
  68.         {
  69.             variablePourEssai++;
  70.         }
  71.  
  72.       }
  73.         if(variablePourEssai == tailleMotMystere)
  74.             {
  75.             *essaiRestant = *essaiRestant - 1;
  76.             strcat(afficherFaute,&caractere);
  77.                 int tailleFaute = strlen(afficherFaute), p = 0;
  78.                     for(p=0;p<tailleFaute;p++)
  79.                     {
  80.                         if(afficherFaute[p] < 65 || afficherFaute[p] > 90)
  81.                             afficherFaute[p] = ' ';
  82.                     }
  83.  
  84.             }
  85.     }
  86.  
  87.  
  88. }
  89.  
  90. int TestResultat(const char motMystere[],const char penduMotMystere[])
  91. {
  92.  
  93.     int test = 0;
  94.     if (strcmp(motMystere, penduMotMystere) == 0) // Si chaînes identiques
  95.     {
  96.         test = 1;
  97.     }
  98.     else
  99.     {
  100.        test = 0;
  101.     }
  102.  
  103. /*    int test = 0, tailleMotMystere = strlen(motMystere), taille = 0,i = 0;
  104.     for(i=0;i<tailleMotMystere;i++)
  105.     {
  106.         if(motMystere[i] == penduMotMystere[i])
  107.             taille ++;
  108.     }
  109. if(taille == tailleMotMystere)
  110.     test = 1;
  111. else
  112.     test = 0;
  113. */
  114.  
  115. return test;
  116. }
  117.  
  118. void AfficherPendu(const int essaiRestant)
  119. {
  120.     int faute = 10 - essaiRestant;
  121.     switch(faute)
  122.     {
  123.  
  124.     case 0:
  125.  
  126. printf("\n");
  127. printf("\n");
  128. printf("\n");
  129. printf("\n");
  130. printf("\n");
  131. printf("\n");
  132. printf("\n");
  133. break;
  134.  
  135.     case 1:
  136.  
  137. printf("\n");
  138. printf("\n");
  139. printf("\n");
  140. printf("\n");
  141. printf("\n");
  142. printf("_____________\n");
  143. break;
  144.  
  145.     case 2:
  146.  
  147. printf("\n");
  148. printf(" |\n");
  149. printf(" |\n");
  150. printf(" |\n");
  151. printf(" |\n");
  152. printf(" |\n");
  153. printf("_|____________\n");
  154. break;
  155.  
  156.     case 3:
  157.  
  158. printf("_____________\n");
  159. printf(" |\n");
  160. printf(" |\n");
  161. printf(" |\n");
  162. printf(" |\n");
  163. printf(" |\n");
  164. printf("_|____________\n");
  165. break;
  166.  
  167.     case 4:
  168.  
  169. printf("_____________\n");
  170. printf(" | /\n");
  171. printf(" |/\n");
  172. printf(" |\n");
  173. printf(" |\n");
  174. printf(" |\n");
  175. printf("_|____________\n");
  176. break;
  177.  
  178.     case 5:
  179.  
  180. printf("_____________\n");
  181. printf(" | /       |\n");
  182. printf(" |/\n");
  183. printf(" |\n");
  184. printf(" |\n");
  185. printf(" |\n");
  186. printf("_|____________\n");
  187. break;
  188.  
  189.     case 6:
  190.  
  191. printf("_____________\n");
  192. printf(" | /       |\n");
  193. printf(" |/        O\n");
  194. printf(" |\n");
  195. printf(" |\n");
  196. printf(" |\n");
  197. printf("_|____________\n");
  198. break;
  199.  
  200.     case 7:
  201. printf("_____________\n");
  202. printf(" | /       |\n");
  203. printf(" |/        O\n");
  204. printf(" |         |\n");
  205. printf(" |\n");
  206. printf(" |\n");
  207. printf("_|____________\n");
  208. break;
  209.  
  210.     case 8:
  211.  
  212. printf("_____________\n");
  213. printf(" | /       |\n");
  214. printf(" |/        O\n");
  215. printf(" |        -|-\n");
  216. printf(" |\n");
  217. printf(" |\n");
  218. printf("_|____________\n");
  219. break;
  220.  
  221.     case 9:
  222.  
  223. printf("_____________\n");
  224. printf(" | /       |\n");
  225. printf(" |/        O\n");
  226. printf(" |        -|-\n");
  227. printf(" |         /\\\n");
  228. printf(" |\n");
  229. printf("_|____________\n");
  230. break;
  231.  
  232.     case 10:
  233.  
  234. printf("_____________\n");
  235. printf(" | /       |\n");
  236. printf(" |/        O\n");
  237. printf(" |        -|-\n");
  238. printf(" |         /\\\n");
  239. printf(" |\n");
  240. printf("_|____________\n");
  241. printf("Trop tard je suis mort !\n");
  242. break;
  243.     default:
  244. break;
  245.  
  246.     }
  247.  
  248. }
  249.  
  250. void viderBuffer()
  251. {
  252.     int c = 0;
  253.     while (c != '\n' && c != EOF)
  254.     {
  255.         c = getchar();
  256.     }
  257. }
  258.  
  259. void Pause()
  260. {
  261.   printf("\nAppuyez sur entrer\n");
  262.   getchar();
  263.   viderBuffer;
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement