verification partie gagnee + full maj

This commit is contained in:
Mylloon 2021-05-21 23:45:21 +02:00
parent a65a1015e1
commit 795a281be9

24
main.c
View file

@ -38,9 +38,13 @@ char * recuperationMot(const char file[]) {
// fermeture du fichier
fclose(fp);
// suppression du saut de ligne à la fin du mot
int tailleMot = longueurMot(mot);
if(mot[tailleMot - 1] == '\n') mot[tailleMot - 1] = 0;
// passage en majusucule du mot
for(int i = 0; i < tailleMot; i++) if(mot[i] >= 97 && mot[i] <= 122) mot[i] = mot[i] - 32;
return mot;
}
@ -50,12 +54,11 @@ char * obfuscation(char mot[], int lettresValidees[], int taille) {
int j = 0;
for(int i = 0; i < taille; i++) {
if(lettresValidees[i] != 1) motCache[j] = '_'; else motCache[j] = mot[i];
j++;
motCache[j] = ' ';
j++;
motCache[j + 1] = ' ';
j = j + 2;
}
printf("[DEBUG: mot: %s, taille mot: %d, mot caché: %s]\n", mot, taille, motCache);
printf("\n[DEBUG: mot: %s, taille mot: %d, mot caché: %s]\n", mot, taille, motCache);
return motCache;
}
@ -66,6 +69,12 @@ int lettreDansMot(char mot[], int tailleMot, char lettre[]) {
return 0;
}
int partieGagnee(int lettresValidees[], int taille) {
for(int i = 0; i < taille; i++) if(lettresValidees[i] != 1) return 0;
return 1;
}
int jeu() {
// mot aléatoire
char liste[14] = "listeMots.txt";
@ -86,14 +95,17 @@ int jeu() {
free(motObfusque);
printf("Nombre d'erreurs restantes : %hu\n", essaisRestants);
printf("Saisissez une lettre : ");
demandeLettre = scanf("%c\n", &lettre);
demandeLettre = scanf(" %c", &lettre);
if(demandeLettre == 1) {
printf("\n");
if(lettre >= 97 && lettre <= 122) lettre = lettre - 32;
// vérification si lettre dans le mot
if(lettreDansMot(mot, tailleMot, &lettre) == 1) {
printf("La lettre %c est dans le mot !\n", lettre);
// verification partie gagner
if(partieGagnee(tableauLettresValidees, tailleMot) == 1) {
printf("Le mot est %s\n", mot);
return 1;
}
} else {
printf("La lettre %c n'est pas dans le mot !\n", lettre);
essaisRestants--;