Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Vincent Jacques 2101 */ /* R=82 V=86 B=66 J=74 N=78 O=79 */
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <ctype.h>
- #define MAX 122
- #define MIN 97
- void bienvenue ();
- short menu ();
- void pseudo_ (char *ptpseudo);
- void gencat (char *pt);
- void tentatives (char *ptent);
- void correction (char *cat, char *ce,short *ptccp, short *ptcomptent);
- void comment_jouer ();
- int main()
- {
- char cat[4]; /*Combinaison A Trouver*/
- char ce[4]; /*Combinaison Entree*/
- short comptent=0;
- short ptccp=0,choix=0,retour_menu=1;
- char pseudo[25];
- srand(time(NULL));
- bienvenue();
- while(retour_menu==1)
- {
- choix=menu();
- system("cls");
- switch(choix)
- {
- case 1:pseudo_(&pseudo[0]);
- system("cls");
- gencat(&cat[0]);
- printf("\t\tA toi de jouer %s! \n",pseudo);
- printf("\t\tEntre une combinaison de couleur: \n");
- printf("%s\n",cat);
- do
- {
- tentatives(&ce[0]);
- correction (&cat[0],&ce[0],&ptccp,&comptent);
- }while(comptent <10 && ptccp < 4);
- if (comptent==10)
- {
- printf("\n\t\t PERDU PERDU PERDU PERDU ! \n");
- }
- retour_menu=1;
- break;
- break;
- case 2: comment_jouer ();
- retour_menu=1;
- break;
- case 3: retour_menu=0;
- break;
- default:
- break;
- }
- }
- printf("\n\t\tAurevoir! \n");
- /*gencat(&cat[0]); generateur du tableau a trouver
- printf(" \n");
- printf("%c",cat[0]);
- printf("%c",cat[1]);
- printf("%c",cat[2]);
- printf("%c",cat[3]);
- printf(" \n");
- do
- {
- tentatives(&ce[0]);
- correction (&cat[0],&ce[0],&ptccp,&comptent);
- printf("%hd \n",comptent);
- }while(comptent <10 && ptccp < 4);
- printf(" \n");printf(" \n");
- printf("%c",ce[0]);
- printf("%c",ce[1]);
- printf("%c",ce[2]);
- printf("%c",ce[3]);
- printf("%hd \n",comptent);*/
- return 0;
- }
- void bienvenue ()
- {
- char c;
- printf("\n");
- printf("\t\t*-----------------------------------------------* \n");
- printf("\t\t*-----------------------------------------------* \n");
- printf("\t\t*-----------------------------------------------* \n");
- printf("\t\t*------- MasterMind v1.0 -----------------------* \n");
- printf("\t\t*-----------------------------------------------* \n");
- printf("\t\t*-----------------------------------------------* \n");
- printf("\t\t*--------------------(Appuyer sur ENTER)--------* \n");
- printf("\t\t*-----------------------------------------------* \n");
- printf("\t\t*-------------------By Vincent Jacques 2101-----* \n");
- fflush(stdin);
- do
- {
- c=getchar();
- system("cls");
- }while(c != '\n');
- }
- short menu ()
- {
- short choix;
- do
- {
- printf("\n");
- printf("\t\t*-------------- MasterMind v1.0 ----------------* \n");
- printf("\t\t*-----------------------------------------------* \n");
- printf("\t\t*-----------------------------------------------* \n");
- printf("\t\t* 1) Jouer -------------------------------------* \n");
- printf("\t\t* 2) Comment jouer?-----------------------------* \n");
- printf("\t\t* 3) Quitter -----------------------------------* \n");
- printf("\t\t*-----------------------------------------------* \n");
- printf("\t\t*-----------------------------------------------* \n");
- printf("\t\t*-----------------------------------------------* \n");
- scanf("%hd",&choix);
- }while(choix<0 && choix>4);
- return(choix);
- }
- void pseudo_ (char *ptpseudo)
- {
- char pseudo;
- fflush(stdin);
- printf("\t\tQuel est ton pseudo? \n");
- pseudo=getchar();
- while ( pseudo != '\n')
- {
- *ptpseudo =pseudo;
- ptpseudo++;
- pseudo=getchar();
- }
- *ptpseudo='\0';
- }
- void gencat (char *pt)
- {
- short i,doublons,j;
- char couleur;
- for(i=0;i<4;i++)
- {
- do
- {
- do
- {
- doublons=0;
- couleur=rand()% (MAX-MIN+1)+MIN;
- }while(couleur != 'r' && couleur != 'v' && couleur != 'b' && couleur != 'j' && couleur != 'n' && couleur != 'o');
- pt[i]=couleur;
- if(i>0)
- {
- for(j=0;j<i;j++)
- {
- if(couleur == pt[j])
- {
- doublons=1;
- }
- }
- }
- }while(doublons==1);
- }
- }
- void tentatives (char *ptent)
- {
- short i,j;
- short doubles;
- fflush(stdin);
- for(i=0;i<4;i++)
- {
- do
- {
- do
- {
- doubles=0;
- ptent[i]= getchar();
- ptent[i]= tolower(ptent[i]);
- }while(*ptent != 'r' && *ptent != 'v' && *ptent != 'b' && *ptent != 'j' && *ptent != 'n' && *ptent != 'o');
- for(j=0;j<i;j++)
- {
- if(ptent[i]== ptent[j])
- {
- doubles=1;
- }
- }
- }while(doubles==1);
- }
- }
- void correction (char *cat, char *ce,short *ptccp, short *ptcomptent)
- {
- short i,j,ccp=0,ccmmp=0; /* Couleur Correctement place(ccp) & Couleur Correcte Mais Mal Placee(ccmmp) */
- /* printf("\n");
- printf("\t\t** \n");
- printf("\t\t** \n");
- printf("\t\t** \n");
- printf("\t\t** \n");
- printf("\t\t** \n");
- printf("\t\t** \n");
- printf("\t\t** \n");
- printf("\t\t** \n");
- printf("\t\t** \n");*/
- for(i=0;i<4;i++)
- {
- for(j=0;j<4;j++)
- {
- if (cat[i]==ce[j] && i==j)
- {
- ccp++;
- }
- if (cat[i]==ce[j] && i!=j )
- {
- ccmmp++;
- }
- }
- }
- *ptcomptent=*ptcomptent+1;
- *ptccp=ccp;
- if (*ptccp == 4)
- {
- printf("bravo tu es le plus fort \n");
- printf("Tu as reussi en %hd tentative(s) \n",*ptcomptent);
- }
- if (*ptccp !=4)
- {
- printf("\n il y a %hd couleur(s) correctement placee(s)\n",ccp);
- printf(" et il y a %hd couleur(s) mal placee(s) \n",ccmmp);
- printf(" Il te reste %hd tentative(s) \n",10-*ptcomptent);
- }
- }
- void comment_jouer ()
- {
- printf("\n");
- printf("\t* Comment jouer: * \n");
- printf("\t* * \n");
- printf("\t* L'ordinateur va generer une combinaison de 4 couleurs * \n");
- printf("\t* distinctes. * \n");
- printf("\t* Ensuite, en un maximum de 10 tentatives vous devrez * \n");
- printf("\t* retrouver cette combinaison. * \n");
- printf("\t* * \n");
- printf("\t* Vous Avez le choix parmis les couleurs suivantes: * \n");
- printf("\t* Rouge = r, Vert = v, Bleu = b, orange = o, Jaune = j, Noire = n* \n");
- }
Add Comment
Please, Sign In to add comment