From 65f0e3f7c5d2b241a23e6ea0721e69c8e89b79a3 Mon Sep 17 00:00:00 2001 From: vautrin33u <vautrin33u@etu.univ-lorraine.fr> Date: Thu, 31 Dec 2020 15:45:10 +0100 Subject: [PATCH] =?UTF-8?q?d=C3=A9but=20tri=20de=20score=20et=20tableau=20?= =?UTF-8?q?score?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gestion_fichiers.c | 42 ++++++++++++++++++++++++++++++++++++++++++ gestion_fichiers.h | 24 ++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/gestion_fichiers.c b/gestion_fichiers.c index 4ae6360..0843eb4 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 cc82780..4f19a84 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 -- GitLab