Guest User

Untitled

a guest
Jun 23rd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.70 KB | None | 0 0
  1. /* Vincent Jacques 2101 */ /* R=82 V=86 B=66 J=74 N=78 O=79 */
  2.  
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <time.h>
  7. #include <ctype.h>
  8.  
  9. #define MAX 122
  10. #define MIN 97
  11.  
  12. void bienvenue ();
  13. short menu ();
  14. void pseudo_ (char *ptpseudo);
  15. void gencat (char *pt);
  16. void tentatives (char *ptent);
  17. void correction (char *cat, char *ce,short *ptccp, short *ptcomptent);
  18. void comment_jouer ();
  19.  
  20. int main()
  21. {
  22.     char cat[4]; /*Combinaison A Trouver*/
  23.     char ce[4]; /*Combinaison Entree*/
  24.     short comptent=0;
  25.     short ptccp=0,choix=0,retour_menu=1;
  26.     char pseudo[25];
  27.  
  28.  
  29.  
  30.  
  31.     srand(time(NULL));
  32.  
  33.     bienvenue();
  34.  
  35.  
  36.     while(retour_menu==1)
  37.     {
  38.  
  39.  
  40.     choix=menu();
  41.     system("cls");
  42.  
  43.     switch(choix)
  44.         {
  45.             case 1:pseudo_(&pseudo[0]);
  46.             system("cls");
  47.             gencat(&cat[0]);
  48.             printf("\t\tA toi de jouer %s! \n",pseudo);
  49.             printf("\t\tEntre une combinaison de couleur:  \n");
  50.             printf("%s\n",cat);
  51.                                     do
  52.                             {
  53.                             tentatives(&ce[0]);
  54.                             correction (&cat[0],&ce[0],&ptccp,&comptent);
  55.  
  56.  
  57.                             }while(comptent <10 && ptccp < 4);
  58.                                 if (comptent==10)
  59.                                 {
  60.                                     printf("\n\t\t PERDU PERDU PERDU PERDU ! \n");
  61.                                 }
  62.  
  63.  
  64.                 retour_menu=1;
  65.                 break;
  66.  
  67.                 break;
  68.             case 2:     comment_jouer ();
  69. retour_menu=1;
  70.                 break;
  71.             case 3: retour_menu=0;
  72.  
  73.                 break;
  74.             default:
  75.  
  76.                 break;
  77.         }
  78.     }
  79. printf("\n\t\tAurevoir! \n");
  80.  
  81.     /*gencat(&cat[0]);  generateur du tableau a trouver
  82.  
  83.     printf(" \n");
  84.     printf("%c",cat[0]);
  85.     printf("%c",cat[1]);
  86.     printf("%c",cat[2]);
  87.     printf("%c",cat[3]);
  88.     printf(" \n");
  89.  
  90.     do
  91.     {
  92.     tentatives(&ce[0]);
  93.     correction (&cat[0],&ce[0],&ptccp,&comptent);
  94.     printf("%hd \n",comptent);
  95.  
  96.     }while(comptent <10 && ptccp < 4);
  97.  
  98.  
  99.     printf(" \n");printf(" \n");
  100.     printf("%c",ce[0]);
  101.     printf("%c",ce[1]);
  102.     printf("%c",ce[2]);
  103.     printf("%c",ce[3]);
  104.     printf("%hd \n",comptent);*/
  105.  
  106.  
  107.  
  108.  
  109.     return 0;
  110. }
  111.  
  112. void bienvenue ()
  113. {
  114.     char c;
  115.     printf("\n");
  116.     printf("\t\t*-----------------------------------------------* \n");
  117.     printf("\t\t*-----------------------------------------------* \n");
  118.     printf("\t\t*-----------------------------------------------* \n");
  119.     printf("\t\t*------- MasterMind v1.0 -----------------------* \n");
  120.     printf("\t\t*-----------------------------------------------* \n");
  121.     printf("\t\t*-----------------------------------------------* \n");
  122.     printf("\t\t*--------------------(Appuyer sur ENTER)--------* \n");
  123.     printf("\t\t*-----------------------------------------------* \n");
  124.     printf("\t\t*-------------------By Vincent Jacques 2101-----* \n");
  125.  
  126.     fflush(stdin);
  127.     do
  128.     {
  129.     c=getchar();
  130.     system("cls");
  131.  
  132.     }while(c != '\n');
  133.  
  134. }
  135.  
  136. short menu ()
  137. {
  138.     short choix;
  139.     do
  140.     {
  141.             printf("\n");
  142.     printf("\t\t*-------------- MasterMind v1.0 ----------------* \n");
  143.     printf("\t\t*-----------------------------------------------* \n");
  144.     printf("\t\t*-----------------------------------------------* \n");
  145.     printf("\t\t* 1) Jouer -------------------------------------* \n");
  146.     printf("\t\t* 2) Comment jouer?-----------------------------* \n");
  147.     printf("\t\t* 3) Quitter -----------------------------------* \n");
  148.     printf("\t\t*-----------------------------------------------* \n");
  149.     printf("\t\t*-----------------------------------------------* \n");
  150.     printf("\t\t*-----------------------------------------------* \n");
  151.     scanf("%hd",&choix);
  152.     }while(choix<0 && choix>4);
  153.     return(choix);
  154. }
  155.  
  156. void pseudo_ (char *ptpseudo)
  157. {
  158.        char pseudo;
  159.    fflush(stdin);
  160.    printf("\t\tQuel est ton pseudo? \n");
  161.    pseudo=getchar();
  162.  
  163.         while ( pseudo != '\n')
  164.         {
  165.             *ptpseudo =pseudo;
  166.             ptpseudo++;
  167.             pseudo=getchar();
  168.         }
  169.         *ptpseudo='\0';
  170. }
  171.  
  172.  
  173. void gencat (char *pt)
  174. {
  175.     short i,doublons,j;
  176.     char couleur;
  177.  
  178.     for(i=0;i<4;i++)
  179.     {
  180.         do
  181.         {
  182.             do
  183.                 {
  184.  
  185.                    doublons=0;
  186.                     couleur=rand()% (MAX-MIN+1)+MIN;
  187.  
  188.                     }while(couleur != 'r' && couleur != 'v' && couleur != 'b' && couleur != 'j' && couleur != 'n' && couleur != 'o');
  189.                   pt[i]=couleur;
  190.  
  191.                   if(i>0)
  192.                   {
  193.                       for(j=0;j<i;j++)
  194.                             {
  195.                                 if(couleur == pt[j])
  196.                                 {
  197.                                     doublons=1;
  198.                                 }
  199.                             }
  200.  
  201.                   }
  202.         }while(doublons==1);
  203.     }
  204. }
  205.  
  206. void tentatives (char *ptent)
  207. {
  208.     short i,j;
  209.     short doubles;
  210.     fflush(stdin);
  211.   for(i=0;i<4;i++)
  212.     {
  213.         do
  214.         {
  215.             do
  216.                 {
  217.                     doubles=0;
  218.  
  219.                     ptent[i]= getchar();
  220.                     ptent[i]= tolower(ptent[i]);
  221.                 }while(*ptent != 'r' && *ptent != 'v' && *ptent != 'b' && *ptent != 'j' && *ptent != 'n' && *ptent != 'o');
  222.  
  223.         for(j=0;j<i;j++)
  224.             {
  225.                 if(ptent[i]== ptent[j])
  226.                 {
  227.                     doubles=1;
  228.                 }
  229.             }
  230.  
  231.         }while(doubles==1);
  232.     }
  233. }
  234.  
  235. void correction (char *cat, char *ce,short *ptccp, short *ptcomptent)
  236. {
  237.     short i,j,ccp=0,ccmmp=0; /* Couleur Correctement place(ccp) & Couleur Correcte Mais Mal Placee(ccmmp) */
  238.  
  239.  
  240.    /* printf("\n");
  241.     printf("\t\t** \n");
  242.     printf("\t\t** \n");
  243.     printf("\t\t** \n");
  244.     printf("\t\t** \n");
  245.     printf("\t\t** \n");
  246.     printf("\t\t** \n");
  247.     printf("\t\t** \n");
  248.     printf("\t\t** \n");
  249.     printf("\t\t** \n");*/
  250.  
  251.  
  252.     for(i=0;i<4;i++)
  253.     {
  254.             for(j=0;j<4;j++)
  255.             {
  256.  
  257.  
  258.                     if (cat[i]==ce[j] && i==j)
  259.                     {
  260.                         ccp++;
  261.                     }
  262.                     if (cat[i]==ce[j] && i!=j )
  263.                              {
  264.                                 ccmmp++;
  265.                              }
  266.  
  267.             }
  268.  
  269.     }
  270.  
  271. *ptcomptent=*ptcomptent+1;
  272. *ptccp=ccp;
  273.  
  274.     if (*ptccp == 4)
  275.     {
  276.         printf("bravo tu es le plus fort \n");
  277.         printf("Tu as reussi en %hd tentative(s) \n",*ptcomptent);
  278.     }
  279.  
  280.  
  281.     if (*ptccp !=4)
  282.     {
  283. printf("\n il y a %hd couleur(s) correctement placee(s)\n",ccp);
  284. printf(" et il y a %hd couleur(s) mal placee(s) \n",ccmmp);
  285. printf(" Il te reste %hd tentative(s) \n",10-*ptcomptent);
  286.     }
  287.  
  288. }
  289.  
  290. void comment_jouer ()
  291. {
  292.  
  293.     printf("\n");
  294.     printf("\t*                       Comment jouer:                           * \n");
  295.     printf("\t*                                                                * \n");
  296.     printf("\t* L'ordinateur va generer une combinaison de 4 couleurs          * \n");
  297.     printf("\t*  distinctes.                                                   * \n");
  298.     printf("\t* Ensuite, en un maximum de 10 tentatives vous devrez            * \n");
  299.     printf("\t*  retrouver cette combinaison.                                  * \n");
  300.     printf("\t*                                                                * \n");
  301.     printf("\t* Vous Avez le choix parmis les couleurs suivantes:              * \n");
  302.     printf("\t* Rouge = r, Vert = v, Bleu = b, orange = o, Jaune = j, Noire = n* \n");
  303. }
Add Comment
Please, Sign In to add comment