forked from menault/TD3_DEV51_Qualite_Algo
add src
This commit is contained in:
100
src/facile.txt
Normal file
100
src/facile.txt
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
ARBRE
|
||||||
|
LIVRE
|
||||||
|
POMME
|
||||||
|
CHAIR
|
||||||
|
TABLE
|
||||||
|
CHIEN
|
||||||
|
CHAT
|
||||||
|
VACHE
|
||||||
|
CHEVAL
|
||||||
|
PORTE
|
||||||
|
MUR
|
||||||
|
TOIT
|
||||||
|
LUNE
|
||||||
|
SOLEIL
|
||||||
|
MARE
|
||||||
|
NEIGE
|
||||||
|
GLACE
|
||||||
|
FLEUR
|
||||||
|
ROSE
|
||||||
|
BLEUET
|
||||||
|
ORANGE
|
||||||
|
BANANE
|
||||||
|
TOMATE
|
||||||
|
CITRON
|
||||||
|
PAPAYE
|
||||||
|
RAISIN
|
||||||
|
MANGUE
|
||||||
|
CERISE
|
||||||
|
OLIVE
|
||||||
|
PIMENT
|
||||||
|
SUCRE
|
||||||
|
SEL
|
||||||
|
POIVRE
|
||||||
|
MOUTON
|
||||||
|
COQ
|
||||||
|
POULE
|
||||||
|
LAPIN
|
||||||
|
AIGLE
|
||||||
|
TIGRE
|
||||||
|
LION
|
||||||
|
ZEBRE
|
||||||
|
SINGE
|
||||||
|
PANDA
|
||||||
|
KOALA
|
||||||
|
RENARD
|
||||||
|
OURS
|
||||||
|
CRABE
|
||||||
|
POISSON
|
||||||
|
REKIN
|
||||||
|
DAUPHIN
|
||||||
|
BALEINE
|
||||||
|
PLUIE
|
||||||
|
VENT
|
||||||
|
FEU
|
||||||
|
TERRE
|
||||||
|
NUAGE
|
||||||
|
ORAGE
|
||||||
|
PENTE
|
||||||
|
MER
|
||||||
|
RIVAGE
|
||||||
|
RIVIERE
|
||||||
|
ETANG
|
||||||
|
PLAINE
|
||||||
|
COLLINE
|
||||||
|
VALLEE
|
||||||
|
ROCHER
|
||||||
|
SABLE
|
||||||
|
PRAIRIE
|
||||||
|
BOIS
|
||||||
|
FORET
|
||||||
|
GIVRE
|
||||||
|
CAVERNE
|
||||||
|
CERCLE
|
||||||
|
ANGLE
|
||||||
|
CARRE
|
||||||
|
CUBE
|
||||||
|
SPHERE
|
||||||
|
POINT
|
||||||
|
TRAIT
|
||||||
|
CHEMIN
|
||||||
|
ROUTE
|
||||||
|
RUE
|
||||||
|
VILLE
|
||||||
|
VILLAGE
|
||||||
|
PAYS
|
||||||
|
MONDE
|
||||||
|
ETOILE
|
||||||
|
GALAXIE
|
||||||
|
COSMOS
|
||||||
|
TEMPLE
|
||||||
|
CHAPELLE
|
||||||
|
JARDIN
|
||||||
|
FLECHE
|
||||||
|
ECUREUIL
|
||||||
|
COUSIN
|
||||||
|
AMIS
|
||||||
|
ENNEMI
|
||||||
|
VILAIN
|
||||||
|
COQUIN
|
||||||
|
VOYOU
|
||||||
49
src/functions.c
Normal file
49
src/functions.c
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#include "functions.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char choose_letter() {
|
||||||
|
char letter;
|
||||||
|
printf("Entrez une lettre : ");
|
||||||
|
scanf(" %c", &letter);
|
||||||
|
printf("Vous avez choisi la lettre '%c'\n", letter);
|
||||||
|
return letter;
|
||||||
|
}
|
||||||
|
|
||||||
|
int word_size(const char *fullWord) {
|
||||||
|
int size = 0;
|
||||||
|
while (fullWord[size] != '\0') {
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int letter_occurrence(char letter, const char *fullWord) {
|
||||||
|
int wordsize = word_size(fullWord);
|
||||||
|
int letterOccurrence = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < wordsize; i++) {
|
||||||
|
if (fullWord[i] == letter) {
|
||||||
|
letterOccurrence++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (letterOccurrence == 0) {
|
||||||
|
printf("La lettre '%c' n'apparait pas dans le mot.\n", letter);
|
||||||
|
}
|
||||||
|
|
||||||
|
return letterOccurrence;
|
||||||
|
}
|
||||||
|
|
||||||
|
void position_letter(char letter, const char *fullWord, char *partialWord) {
|
||||||
|
int wordsize = word_size(fullWord);
|
||||||
|
for (int i = 0; i < wordsize; i++) {
|
||||||
|
if (fullWord[i] == letter) {
|
||||||
|
partialWord[i] = letter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int has_won(const char *fullWord, const char *partialWord) {
|
||||||
|
return strcmp(fullWord, partialWord) == 0;
|
||||||
|
}
|
||||||
12
src/functions.h
Normal file
12
src/functions.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef FUNCTIONS_H
|
||||||
|
#define FUNCTIONS_H
|
||||||
|
|
||||||
|
#define LIFES 8
|
||||||
|
|
||||||
|
char choose_letter();
|
||||||
|
int word_size(const char *fullWord);
|
||||||
|
int letter_occurrence(char letter, const char *fullWord);
|
||||||
|
void position_letter(char letter, const char *fullWord, char *partialWord);
|
||||||
|
int has_won(const char *fullWord, const char *partialWord);
|
||||||
|
|
||||||
|
#endif
|
||||||
44
src/getfuncs.c
Normal file
44
src/getfuncs.c
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#include "getfuncs.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int getFileLength(const char *filename) {
|
||||||
|
FILE* stream = fopen(filename, "r");
|
||||||
|
if (!stream) return -1;
|
||||||
|
|
||||||
|
int file_length = 0;
|
||||||
|
char buffer[128];
|
||||||
|
while (fgets(buffer, sizeof(buffer), stream)) {
|
||||||
|
file_length++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(stream);
|
||||||
|
return file_length;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fetchWord(const char *filename, char *fullWord, int file_length) {
|
||||||
|
if (file_length <= 0) return -1;
|
||||||
|
|
||||||
|
srand(time(NULL));
|
||||||
|
int random_line = rand() % file_length;
|
||||||
|
|
||||||
|
FILE* stream = fopen(filename, "r");
|
||||||
|
if (!stream) return -1;
|
||||||
|
|
||||||
|
int current = 0;
|
||||||
|
while (fgets(fullWord, 128, stream)) {
|
||||||
|
if (current == random_line) {
|
||||||
|
// Retirer le '\n' si présent
|
||||||
|
char *newline = strchr(fullWord, '\n');
|
||||||
|
if (newline) *newline = '\0';
|
||||||
|
fclose(stream);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
current++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(stream);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
7
src/getfuncs.h
Normal file
7
src/getfuncs.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef GETFUNCS_H
|
||||||
|
#define GETFUNCS_H
|
||||||
|
|
||||||
|
int getFileLength(const char *filename);
|
||||||
|
int fetchWord(const char *filename, char *fullWord, int file_length);
|
||||||
|
|
||||||
|
#endif
|
||||||
61
src/main.c
Normal file
61
src/main.c
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "functions.h"
|
||||||
|
#include "getfuncs.h"
|
||||||
|
|
||||||
|
void play_game(const char *filename) {
|
||||||
|
char fullWord[128];
|
||||||
|
int flength = getFileLength(filename);
|
||||||
|
if (fetchWord(filename, fullWord, flength) != 0) {
|
||||||
|
printf("Erreur de lecture du fichier.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int size = word_size(fullWord);
|
||||||
|
char partialWord[size + 1];
|
||||||
|
for (int i = 0; i < size; i++) partialWord[i] = '_';
|
||||||
|
partialWord[size] = '\0';
|
||||||
|
|
||||||
|
int lifes = LIFES;
|
||||||
|
int won = 0;
|
||||||
|
|
||||||
|
printf("Le mot a deviner contient %d lettres.\n", size);
|
||||||
|
|
||||||
|
while (lifes > 0 && !won) {
|
||||||
|
printf("\nMot actuel : %s\nVies restantes : %d\n", partialWord, lifes);
|
||||||
|
char letter = choose_letter();
|
||||||
|
int occurrence = letter_occurrence(letter, fullWord);
|
||||||
|
|
||||||
|
if (occurrence > 0) {
|
||||||
|
position_letter(letter, fullWord, partialWord);
|
||||||
|
} else {
|
||||||
|
lifes--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_won(fullWord, partialWord)) won = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (won) printf("\nFelicitations ! Vous avez trouve le mot : %s\n", fullWord);
|
||||||
|
else printf("\nVous avez perdu ! Le mot etait : %s\n", fullWord);
|
||||||
|
}
|
||||||
|
|
||||||
|
void play_hard_mode() {
|
||||||
|
printf("Mode difficile : vous devez deviner deux mots !\n");
|
||||||
|
play_game("facile.txt");
|
||||||
|
play_game("moyen.txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int choice;
|
||||||
|
printf("Choisissez le mode :\n1 - Facile\n2 - Moyen\n3 - Difficile\n> ");
|
||||||
|
scanf("%d", &choice);
|
||||||
|
|
||||||
|
switch(choice) {
|
||||||
|
case 1: play_game("facile.txt"); break;
|
||||||
|
case 2: play_game("moyen.txt"); break;
|
||||||
|
case 3: play_hard_mode(); break;
|
||||||
|
default: printf("Mode invalide.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
100
src/moyen.txt
Normal file
100
src/moyen.txt
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
ORDINATEUR
|
||||||
|
PROGRAMME
|
||||||
|
TELEPHONE
|
||||||
|
CARNETAGE
|
||||||
|
UNIVERSITE
|
||||||
|
HABITATION
|
||||||
|
BIBLIOTHEQUE
|
||||||
|
MICROPHONE
|
||||||
|
NAVIGATEUR
|
||||||
|
CONDUCTEUR
|
||||||
|
VOYAGEURS
|
||||||
|
CONSTRUCTEUR
|
||||||
|
CHOCOLATERIE
|
||||||
|
APPARTEMENT
|
||||||
|
RESTAURANT
|
||||||
|
IMPRIMERIE
|
||||||
|
MOUSTACHES
|
||||||
|
CAMPAGNARD
|
||||||
|
INVENTAIRE
|
||||||
|
EXPLORATEUR
|
||||||
|
COMPAGNON
|
||||||
|
MATHEMATICS
|
||||||
|
ASTRONAUTE
|
||||||
|
ARCHITECTE
|
||||||
|
MECANICIEN
|
||||||
|
CHIRURGIEN
|
||||||
|
ELEPHANTES
|
||||||
|
HOSPITALES
|
||||||
|
MONTAGNES
|
||||||
|
DESERTIQUE
|
||||||
|
HUMANISME
|
||||||
|
TROUBADOUR
|
||||||
|
VOYAGEUSES
|
||||||
|
CROCODILES
|
||||||
|
DINOSAURES
|
||||||
|
HERISSONNE
|
||||||
|
CULTIVATEUR
|
||||||
|
PLANTATION
|
||||||
|
CROISSANCE
|
||||||
|
DECORATION
|
||||||
|
TRADITION
|
||||||
|
ORGANISATEUR
|
||||||
|
DEVELOPPEUR
|
||||||
|
INFORMATIQUE
|
||||||
|
AUTOROUTES
|
||||||
|
CARTOGRAPHIE
|
||||||
|
GEOGRAPHIE
|
||||||
|
HISTORIQUE
|
||||||
|
LUMINOSITE
|
||||||
|
TRANSPORTEUR
|
||||||
|
NAVIGATIONS
|
||||||
|
IMAGINATION
|
||||||
|
CITADINITE
|
||||||
|
POPULATION
|
||||||
|
MARCHANDISE
|
||||||
|
ECOLOGISTE
|
||||||
|
BOTANISTES
|
||||||
|
ZOOLOGIQUE
|
||||||
|
HARMONIEUX
|
||||||
|
MEDITATION
|
||||||
|
RESISTANCE
|
||||||
|
INSPIRATION
|
||||||
|
INNOVATION
|
||||||
|
CONDITION
|
||||||
|
SUPERVISEUR
|
||||||
|
SPECTATEURS
|
||||||
|
ILLUMINATION
|
||||||
|
PLATEFORME
|
||||||
|
PERSPECTIVE
|
||||||
|
CALCULATEUR
|
||||||
|
OBSERVATEUR
|
||||||
|
ALGORITHME
|
||||||
|
EDUCATEURS
|
||||||
|
SOUVERAINE
|
||||||
|
PARLEMENTS
|
||||||
|
MINISTREES
|
||||||
|
ACROBATIES
|
||||||
|
MUSICIENNE
|
||||||
|
DIRECTION
|
||||||
|
HORIZONTAL
|
||||||
|
VERTICALES
|
||||||
|
REVOLUTION
|
||||||
|
SCIENTIFIQUE
|
||||||
|
EXPERIENCE
|
||||||
|
CONNAISSANCE
|
||||||
|
LABORATOIRE
|
||||||
|
ELECTRICIEN
|
||||||
|
MAGNIFIQUE
|
||||||
|
COLLECTEURS
|
||||||
|
DETERMINANT
|
||||||
|
FASCINANTS
|
||||||
|
HABITUATION
|
||||||
|
DISPERSION
|
||||||
|
FRATERNITE
|
||||||
|
INTEGRITES
|
||||||
|
RESPONSABLE
|
||||||
|
DEPLACEMENT
|
||||||
|
CONCUBINE
|
||||||
|
EPHEMERE
|
||||||
|
SALOPARD
|
||||||
Reference in New Issue
Block a user