diff --git a/gestion_fichiers.c b/gestion_fichiers.c index 4ae63604eeb9f7438188a5ed98fb0cf4d5a9f09b..0843eb483164ffb0099609146b8c492001266813 100644 --- a/gestion_fichiers.c +++ b/gestion_fichiers.c @@ -167,4 +167,46 @@ char** init_map (){ } genere_fichier(nomFichier, tab, hauteur, largeur); return tab; +} + +char* recuperer_highscore(const char* nomFichier){ + //Récupère le tableau des scores et le retransmets + char* tableau[10]; + //Initialisation du tableau + for (int i=0; i<10; i++){ + tableau[i] = NULL; + } + FILE* fichier = NULL; + fichier = fopen(nomFichier, "r"); + if (fichier == NULL){ + int i=0; + char c = '\0'; + while ((c = fgetc(fichier)) != NULL){ + printf("%s", tableau[i]); + i++; + } + } + return tableau; +} + +void trier_highscore (char* highscore, int score_entrant){ + //Trie les scores du plus grand au plus petit + + //traduction char->int + int* tab[10]; + for (int i=0; i<10; i++){ + tab[i] = atoi(highscore[i]); + } + + //trie + + //traduction int->char + for (int i=0; i<10; i++){ + sprintf(highscore[i], "%d", tab[i]); + } +} + + +void ecrire_highscore(const char* nomFichier, char* highscore){ + //ecrire le tableau de score trié et à jour dans le bon fichier } \ No newline at end of file diff --git a/gestion_fichiers.h b/gestion_fichiers.h index cc8278022e11692aa7038439e980ec2e44ac51bf..4f19a84ccb914e32ff8c104cc7e8867078a01a17 100644 --- a/gestion_fichiers.h +++ b/gestion_fichiers.h @@ -62,4 +62,28 @@ char** lire_fichier (const char* nomFichier); * */ void genere_fichier (const char* nomFichier, char** source, int ligne, int colonne); +/** + * @brief écupère le tableau des scores et le retransmets + * + * @param nomFichier Adresse du fichier + * @return char* tableau de score + */ +char* recuperer_highscore(const char* nomFichier); + + +/** + * @brief Trie les scores du plus grand au plus petit + * + * @param highscore tableau de scores + * @param score_entrant score de la partie actuelle + */ +void trier_highscore (char* highscore, int score_entrant); + +/** + * @brief ecrire le tableau de score trié et à jour dans le bon fichier + * + * @param nomFichier Adresse du fichier de score + */ +void ecrire_highscore(const char* nomFichier, char* highscore); + #endif \ No newline at end of file