Correction Affichage, Ajout Best Score par lecture de ficheirs
This commit is contained in:
parent
7afb378891
commit
c5b8ea1870
82
gui.c
82
gui.c
@ -2,35 +2,91 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <graph.h>
|
#include <graph.h>
|
||||||
|
|
||||||
void Menu(unsigned long *bestscore)
|
int lireScore()
|
||||||
|
{
|
||||||
|
int score;
|
||||||
|
FILE* fichier = fopen("score.txt", "r");
|
||||||
|
if (fichier == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Le fichier score.txt n'existe pas. Création du fichier avec la valeur 0.\n");
|
||||||
|
|
||||||
|
score = 0;
|
||||||
|
|
||||||
|
/* Ouvrir le fichier en mode écriture pour créer le fichier s'il n'existe pas */
|
||||||
|
fichier = fopen("score.txt", "w");
|
||||||
|
if (fichier == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Erreur lors de la création du fichier score.txt\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Écrire la valeur 0 par défaut */
|
||||||
|
fprintf(fichier, "%d\n", score);
|
||||||
|
|
||||||
|
fclose(fichier);
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
fscanf(fichier, "%d", &score);
|
||||||
|
fclose(fichier);
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sauvegarderScore(unsigned long nouveauScore)
|
||||||
|
{
|
||||||
|
FILE* fichier = fopen("score.txt", "w");
|
||||||
|
if (fichier == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Erreur lors de l'ouverture du fichier score.txt pour écriture\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(fichier, "%ld\n", nouveauScore);
|
||||||
|
|
||||||
|
fclose(fichier);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckScore(unsigned long nouveauScore)
|
||||||
|
{
|
||||||
|
unsigned long scoreActuel = lireScore();
|
||||||
|
|
||||||
|
if (nouveauScore > scoreActuel || scoreActuel == 0)
|
||||||
|
{
|
||||||
|
sauvegarderScore(nouveauScore);
|
||||||
|
printf("Le score a été enregistré avec succès.\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Le score précédent est plus grand ou égal. Aucun changement effectué.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu()
|
||||||
{
|
{
|
||||||
char buf[100];
|
char buf[100];
|
||||||
couleur text;
|
couleur text;
|
||||||
|
unsigned long bestscore = lireScore();
|
||||||
text=CouleurParComposante(78, 93, 47);
|
text=CouleurParComposante(78, 93, 47);
|
||||||
ChoisirEcran(0);
|
ChoisirEcran(0);
|
||||||
ChargerImage("./images/Menu.png",0,0,0,0,930,710);
|
ChargerImage("./images/Menu.png",0,0,0,0,930,710);
|
||||||
ChoisirCouleurDessin(text);
|
ChoisirCouleurDessin(text);
|
||||||
snprintf(buf,100,"BEST SCORE : %07ld",*bestscore);
|
snprintf(buf,100,"BEST SCORE : %07ld",bestscore);
|
||||||
EcrireTexte(450,470,buf,2);
|
EcrireTexte(420,350,buf,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pause(unsigned long *bestscore)
|
void Pause()
|
||||||
{
|
{
|
||||||
char buf[100];
|
|
||||||
couleur text;
|
|
||||||
text=CouleurParComposante(78, 93, 47);
|
|
||||||
ChoisirEcran(0);
|
ChoisirEcran(0);
|
||||||
ChargerImage("./images/Pause.png",0,0,0,0,930,710);
|
ChargerImage("./images/Pause.png",0,0,0,0,930,710);
|
||||||
ChoisirCouleurDessin(text);
|
|
||||||
snprintf(buf,100,"BEST SCORE : %07ld",*bestscore);
|
|
||||||
EcrireTexte(450,300,buf,2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PerduGUI(unsigned long *bestscore)
|
void PerduGUI()
|
||||||
{
|
{
|
||||||
char buf[100];
|
char buf[100];
|
||||||
|
unsigned long bestscore = lireScore();
|
||||||
ChoisirEcran(0);
|
ChoisirEcran(0);
|
||||||
ChargerImage("./images/Perdu.png",0,0,0,0,930,710);
|
ChargerImage("./images/Perdu.png",0,0,0,0,930,710);
|
||||||
snprintf(buf,100,"BEST SCORE : %07ld",*bestscore);
|
snprintf(buf,100,"BEST SCORE : %07ld",bestscore);
|
||||||
EcrireTexte(450,250,buf,2);
|
EcrireTexte(420,350,buf,2);
|
||||||
}
|
}
|
11
gui.h
11
gui.h
@ -1,10 +1,13 @@
|
|||||||
#ifndef GUI_H
|
#ifndef GUI_H
|
||||||
#define GUI_H
|
#define GUI_H
|
||||||
|
|
||||||
|
void CheckScore(unsigned long nouveauScore);
|
||||||
|
void sauvegarderScore(unsigned long nouveauScore);
|
||||||
|
int lireScore();
|
||||||
|
|
||||||
void Menu();
|
void Menu();
|
||||||
void PerduGUI(unsigned long *bestscore)
|
void PerduGUI();
|
||||||
;void Pause(unsigned long *bestscore);
|
void Pause();
|
||||||
void Reinitialiser();
|
int AfficherGUI();
|
||||||
int AfficherGUI(unsigned char menu);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
BIN
images/Menu.png
BIN
images/Menu.png
Binary file not shown.
Before ![]() (image error) Size: 40 KiB After ![]() (image error) Size: 23 KiB ![]() ![]() |
4
images/Menu.png:Zone.Identifier
Normal file
4
images/Menu.png:Zone.Identifier
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[ZoneTransfer]
|
||||||
|
ZoneId=3
|
||||||
|
ReferrerUrl=https://pixlr.com/fr/express/
|
||||||
|
HostUrl=https://pixlr.com/fr/express/
|
BIN
images/Pause.png
BIN
images/Pause.png
Binary file not shown.
Before ![]() (image error) Size: 41 KiB After ![]() (image error) Size: 44 KiB ![]() ![]() |
4
images/Pause.png:Zone.Identifier
Normal file
4
images/Pause.png:Zone.Identifier
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[ZoneTransfer]
|
||||||
|
ZoneId=3
|
||||||
|
ReferrerUrl=https://pixlr.com/fr/express/
|
||||||
|
HostUrl=https://pixlr.com/fr/express/
|
BIN
images/Perdu.png
BIN
images/Perdu.png
Binary file not shown.
Before ![]() (image error) Size: 38 KiB After ![]() (image error) Size: 43 KiB ![]() ![]() |
4
images/Perdu.png:Zone.Identifier
Normal file
4
images/Perdu.png:Zone.Identifier
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[ZoneTransfer]
|
||||||
|
ZoneId=3
|
||||||
|
ReferrerUrl=https://pixlr.com/fr/express/
|
||||||
|
HostUrl=https://pixlr.com/fr/express/
|
16
main.c
16
main.c
@ -14,7 +14,6 @@ int main()
|
|||||||
{
|
{
|
||||||
unsigned char pause = 0;
|
unsigned char pause = 0;
|
||||||
unsigned long score = 0;
|
unsigned long score = 0;
|
||||||
unsigned long bestscore = 0;
|
|
||||||
unsigned long suivant;
|
unsigned long suivant;
|
||||||
unsigned long suivant2;
|
unsigned long suivant2;
|
||||||
int game_on=0;
|
int game_on=0;
|
||||||
@ -57,11 +56,8 @@ int main()
|
|||||||
while(window_on)
|
while(window_on)
|
||||||
{
|
{
|
||||||
if(perdu == 1)
|
if(perdu == 1)
|
||||||
{ if(score>bestscore)
|
{
|
||||||
{
|
PerduGUI();
|
||||||
bestscore=score;
|
|
||||||
}
|
|
||||||
PerduGUI(&bestscore);
|
|
||||||
if (ToucheEnAttente() == 1)
|
if (ToucheEnAttente() == 1)
|
||||||
{
|
{
|
||||||
switch (Touche())
|
switch (Touche())
|
||||||
@ -74,7 +70,7 @@ int main()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Menu(&bestscore);
|
Menu();
|
||||||
if (ToucheEnAttente() == 1)
|
if (ToucheEnAttente() == 1)
|
||||||
{
|
{
|
||||||
switch (Touche())
|
switch (Touche())
|
||||||
@ -93,6 +89,7 @@ int main()
|
|||||||
case XK_Escape:
|
case XK_Escape:
|
||||||
free(serpent);
|
free(serpent);
|
||||||
free(pastilles);
|
free(pastilles);
|
||||||
|
free(obstacle);
|
||||||
FermerGraphique();
|
FermerGraphique();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -148,6 +145,7 @@ int main()
|
|||||||
{
|
{
|
||||||
free(serpent);
|
free(serpent);
|
||||||
free(pastilles);
|
free(pastilles);
|
||||||
|
free(obstacle);
|
||||||
FermerGraphique();
|
FermerGraphique();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -157,7 +155,7 @@ int main()
|
|||||||
|
|
||||||
if(pause==1)
|
if(pause==1)
|
||||||
{
|
{
|
||||||
Pause(&bestscore);
|
Pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -189,6 +187,7 @@ int main()
|
|||||||
}
|
}
|
||||||
else if (valeur_retourne == 2)
|
else if (valeur_retourne == 2)
|
||||||
{
|
{
|
||||||
|
CheckScore(score);
|
||||||
perdu=1;
|
perdu=1;
|
||||||
game_on=0;
|
game_on=0;
|
||||||
}
|
}
|
||||||
@ -199,6 +198,7 @@ int main()
|
|||||||
}
|
}
|
||||||
free(serpent);
|
free(serpent);
|
||||||
free(pastilles);
|
free(pastilles);
|
||||||
|
free(obstacle);
|
||||||
FermerGraphique();
|
FermerGraphique();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
2
main.h
2
main.h
@ -8,7 +8,7 @@
|
|||||||
#define T_PIXEL 15
|
#define T_PIXEL 15
|
||||||
#define DECALEMENT 30
|
#define DECALEMENT 30
|
||||||
#define PASTILLES 5
|
#define PASTILLES 5
|
||||||
#define OBSTACLE 100
|
#define OBSTACLE 30
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
1
score.txt
Normal file
1
score.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
5
|
Loading…
x
Reference in New Issue
Block a user