From 795a281be9a728701af08543c098955c7bb615d9 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 21 May 2021 23:45:21 +0200 Subject: [PATCH] verification partie gagnee + full maj --- main.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index 4de4f81..36ef894 100644 --- a/main.c +++ b/main.c @@ -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 - printf("Le mot est %s\n", mot); - return 1; + 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--;