| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 
 | #include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
 
	char mot[5], mot2[5], cpt, etoile[5],nom1[20],nom2[20];
        // mot : la combinaison à trouver
        // mot2 : la conbinaison 
		// cnt : lecture continuer
		// etoile : le message qu'on va afficher avec des etoiles
		// nom1, nom2 : les noms des deux joueurs..
 
 
	int niv, i, len, ctrlLONG, ctrlCHIFFRE, BP, nbc, nbrx,nbrOK,nbrKO;   
 
 
int saisieJOUEUR2DIFFICILE(){
	do{
		printf("\n");
		scanf("%s",mot2);
		if(strcmp(mot2,"sorti")==0){
		printf("le mot choisi par %s est %s.\ntapez une touche pour terminer...\n",nom1,mot);
		getchar();
		return (0);
		}
		ctrlLONG = 0;
		len = strlen(mot2);
		if(len!=5){
			printf("la longeur du mot doit etre 5.\n");
			ctrlLONG = 1;
		}
 
 
		if(ctrlLONG==0)break;
	}
    while(1);
 
 
	nbrOK = 0;
	for(i = 0 ; i<5 ; i++){
		if(mot2[i]==mot[i]){
			nbrOK = nbrOK + 1;
			if(nbrOK==5)
				return nbrOK;
		}
	}
	strcpy(etoile,"*****");
	if(mot2[0]==mot[1]||mot2[0]==mot[2]||mot2[0]==mot[3]||mot2[0]==mot[4])
		etoile[0]='$';
	if(mot2[1]==mot[0]||mot2[1]==mot[2]||mot2[1]==mot[3]||mot2[1]==mot[4])
		etoile[1]='$';
	if(mot2[2]==mot[0]||mot2[2]==mot[1]||mot2[2]==mot[3]||mot2[2]==mot[4])
		etoile[2]='$';
	if(mot2[3]==mot[0]||mot2[3]==mot[1]||mot2[3]==mot[2]||mot2[3]==mot[4])
		etoile[3]='$';
	if(mot2[4]==mot[0]||mot2[4]==mot[1]||mot2[4]==mot[2]||mot2[4]==mot[3])
		etoile[3]='$';
	nbrKO = 0;
	for(i=0 ; i<5 ; i++){
		if(etoile[i]=='$'){
			nbrKO = nbrKO + 1;
		}
	}
	printf("il existe %d chiffres bien places, %d chiffres mal places.",nbrOK,nbrKO);
	printf("\n");
	return nbrOK; 
 
}
 
/////////////////////////////////////////////////////////////////////////////////
 
void saisieJOUEUR1(){
      //scanf("%s" ,&nom1);
		printf("\n%s, tapez 5 chiffres \n",nom1);
		do{
			ctrlLONG = ctrlCHIFFRE = 0; 
			scanf("%s",&mot);
			len = strlen(mot);
			if(len!=5){
				printf("la longeur du mot doit etre 5\n");
				ctrlLONG = 1;
			}
 
			else  {
			for(i = 0 ; i < 5 ; i++){
				if(mot[i]>'9'||mot[i]<'0'){
					ctrlCHIFFRE = 1;
					printf("\n%c n'est pas un chiffre, ",mot[i]);
				}
            }
		  }
			printf("\n");
			if(ctrlLONG==0&&ctrlCHIFFRE==0);
            break;
		}
        while(1);
        printf("votre mot est :%s\n",mot);
        system("PAUSE");
	  system("cls") ;              
}
//////////////////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
system("cls");
printf("veuilez saisir le nom du premier joueur : ");
scanf("%s",&nom1);
printf("deuxieme joueur :");
scanf("%s",&nom2);
 
 
saisieJOUEUR1();
		printf("niveau facile :\n");
		printf("%s, essayez de deviner le nombre saisi par %s.\n tapez \"sorti\" pour sortir.\n",nom2,nom1);
		nbrx=0;
	    do{ 
	       BP =  saisieJOUEUR2DIFFICILE();
	       nbrx=nbrx+1;
 
	       }
        while(BP!=5) ;
	       if(BP==5){
			printf("%s \n bravo, vous avez devine le mot secret en %s coup(s)..\n",mot,nbrx);
} 
 
 
  system("PAUSE");	
  return 0;
} | 
Partager