From 0873aebe7d81ece3043ec1d2cadc1a1083b67573 Mon Sep 17 00:00:00 2001 From: keraudre <yann.keraudren@etu-upec.fr> Date: Sun, 24 Dec 2023 20:21:24 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20de=20l'=C3=A9cran=20de=20fin=20du=20jeu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snake/Makefile | 10 ++++- snake/affichage_timer.c | 43 ++++++++++++++++++ snake/affichage_timer.h | 12 +++++ snake/ajout_score.c | 4 +- snake/deplacement.c | 39 ++++++++++++++++ snake/ecran_fin.c | 72 +++++++++++++++++++---------- snake/ecran_fin.h | 11 +++++ snake/fenetre.c | 20 ++++----- snake/main.c | 68 ++++++++++++++++++++-------- snake/pomme.png | Bin 1476 -> 1535 bytes snake/score_init.c | 18 ++++---- snake/time.c | 97 ---------------------------------------- snake/time.h | 10 ----- 13 files changed, 231 insertions(+), 173 deletions(-) create mode 100644 snake/affichage_timer.c create mode 100644 snake/affichage_timer.h create mode 100644 snake/ecran_fin.h delete mode 100644 snake/time.c delete mode 100644 snake/time.h diff --git a/snake/Makefile b/snake/Makefile index 779c3d8..564ff88 100755 --- a/snake/Makefile +++ b/snake/Makefile @@ -14,6 +14,8 @@ OFILES = plateau_init.o \ ajout_score.o \ score_init.o \ supp_queue.o \ + affichage_timer.o \ + ecran_fin.o \ main.o @@ -33,13 +35,17 @@ augmentation_serpent.o : augmentation_serpent.h deplacement.o : deplacement.h supp_queue.h -supp_queue.o : supp_queue.h augmentation_serpent.h ajout_score.h +supp_queue.o : supp_queue.h augmentation_serpent.h ajout_score.h + +ecran_fin.o : ecran_fin.h ajout_score.o : ajout_score.h score_init.o : score_init.h -main.o : main.c fenetre.h deplacement.h +affichage_timer.o : affichage_timer.h + +main.o : main.c fenetre.h deplacement.h affichage_timer.h ecran_fin.h diff --git a/snake/affichage_timer.c b/snake/affichage_timer.c new file mode 100644 index 0000000..65f002c --- /dev/null +++ b/snake/affichage_timer.c @@ -0,0 +1,43 @@ +/* fonction d'affichage du score dans la fenêtre graphique */ + + +#include <stdlib.h> +#include <stdio.h> +#include "affichage_timer.h" + + +void affichage_timer(unsigned char minutes, unsigned char secondes) { + + + char min[5]; + char sec[5]; + + couleur grey, white; + + + + grey = CouleurParComposante(35,35,35); + ChoisirCouleurDessin(grey); + RemplirRectangle(1250, 150, 170, 70); + + + + + + sprintf(min, "%hhu", minutes); + + sprintf(sec, "%hhu", secondes); + + + + white = CouleurParComposante(255, 255, 255); + ChoisirCouleurDessin(white); + + EcrireTexte(1290, 180, min, 2); + + EcrireTexte(1330, 180, ":", 2); + + EcrireTexte(1370, 180, sec, 2); + + +} diff --git a/snake/affichage_timer.h b/snake/affichage_timer.h new file mode 100644 index 0000000..079c42c --- /dev/null +++ b/snake/affichage_timer.h @@ -0,0 +1,12 @@ + + +#ifndef AFFICHAGE_TIMER_H +#define AFFICHAGE_TIMER_H + +#include <graph.h> + + +void affichage_timer( unsigned char minutes, unsigned char secondes) ; + + +#endif /* AFFICHAGE_TIMER_H */ diff --git a/snake/ajout_score.c b/snake/ajout_score.c index c07b364..67bda44 100644 --- a/snake/ajout_score.c +++ b/snake/ajout_score.c @@ -27,12 +27,12 @@ void ajout_score(short int* compteur) { ChoisirCouleurDessin(grey); - RemplirRectangle( 1250, 570, 70, 40); + RemplirRectangle( 1300, 620, 70, 40); ChoisirCouleurDessin(white); - EcrireTexte(1270, 600, a, 2); + EcrireTexte(1310, 650, a, 2); } diff --git a/snake/deplacement.c b/snake/deplacement.c index e57da60..7e34c25 100644 --- a/snake/deplacement.c +++ b/snake/deplacement.c @@ -256,10 +256,49 @@ unsigned char deplacement (struct adresse* pointeur, unsigned char* sens, unsign } + + /* pour quiiter directement le jeu */ + + if ( touche == XK_Escape) { + + return 0; + + } + + + + + + + /* pour mette le jeu pause puis soit reprendere le jeu soit quiiter le jeu */ + + if (touche == XK_space) { + + touche = Touche(); + + if ( touche == XK_space) { + + return 1; + + } + + if ( touche == XK_Escape) { + + return 0; + } + } + } + + + + + + + else { diff --git a/snake/ecran_fin.c b/snake/ecran_fin.c index 523e724..7d1d113 100644 --- a/snake/ecran_fin.c +++ b/snake/ecran_fin.c @@ -6,20 +6,24 @@ #include <stdlib.h> #include <stdio.h> -#include <graph.h> +#include "ecran_fin.h" +void ecran_fin(short int* compteur, unsigned char minutes, unsigned char secondes) { -int main(void) { - -couleur grey, green, yellow, red, black; - - - InitialiserGraphique(); - CreerFenetre(400,150,650,500); + couleur grey, white, red; + + char comp[10]; + + char min[5]; + char sec[5]; + + int touche; + + @@ -27,40 +31,60 @@ couleur grey, green, yellow, red, black; grey = CouleurParComposante(60, 60, 60); ChoisirCouleurDessin(grey); - RemplirRectangle(0,0,650,500); + RemplirRectangle(400,150,650,500); red = CouleurParComposante(255,0,0); ChoisirCouleurDessin(red); - EcrireTexte(280,50, "DEAD", 2); + EcrireTexte(680,250, "DEAD", 2); - EcrireTexte(90,370, "space = play", 2); + EcrireTexte(490,370, "espace = rejouer", 2); - EcrireTexte(400,370, "echap = quit", 2); + EcrireTexte(800,370, "echap = quitter", 2); - yellow = CouleurParComposante(255,255,0); - ChoisirCouleurDessin(yellow); + white = CouleurParComposante(255,255,255); + ChoisirCouleurDessin(white); - EcrireTexte(20,200, "score : ", 2); + EcrireTexte(420,500, "Votre score : ", 2); - EcrireTexte(20,250, " time : ", 2); + sprintf(comp, "%hd", *compteur); + + EcrireTexte( 620, 500, comp, 2); + + + EcrireTexte(750,500, "Temps ", 2); + + sprintf(min, "%hhd", minutes); + + EcrireTexte (875, 500, min, 2); + + EcrireTexte (900, 500, ":", 2); + + sprintf( sec, "%hhd", secondes); + + EcrireTexte( 920, 500, sec, 2); + -/* - ajout_score(); - time() - */ - - Touche(); - FermerGraphique(); + free(compteur); - return EXIT_SUCCESS; + touche = Touche(); + + if ( touche == XK_Escape ) { + return; + } + + if ( touche == XK_space) { + + main(); + + } } diff --git a/snake/ecran_fin.h b/snake/ecran_fin.h new file mode 100644 index 0000000..2af53d7 --- /dev/null +++ b/snake/ecran_fin.h @@ -0,0 +1,11 @@ + + +#ifndef ECRAN_FIN_H +#define ECRAN_FIN_H + +#include <graph.h> + +void ecran_fin( short int* compteur, unsigned char minutes, unsigned char secondes); + + +#endif /* ECRAN_FIN_H */ diff --git a/snake/fenetre.c b/snake/fenetre.c index ed0d755..59aa87c 100755 --- a/snake/fenetre.c +++ b/snake/fenetre.c @@ -18,11 +18,11 @@ int start (struct adresse* pointeur) { int i, j; - char* texte1 = "espace = lancer"; + char* texte1 = "Touche directionnelles = déplacement"; - char* texte2 = "espace = pause"; + char* texte2 = "Espace = pause"; - char* texte3 = "echap = quitter"; + char* texte3 = "Echap = quitter"; int score=0; @@ -63,14 +63,12 @@ int start (struct adresse* pointeur) { white = CouleurParComposante(255,255,255); ChoisirCouleurDessin(white); - EcrireTexte(1250, 300, texte1, 1); - EcrireTexte(1250, 345, texte2, 1); - EcrireTexte(1250, 390, texte3, 1); - - /*affichage compteur pomme (score)*/ - - - + EcrireTexte(1290, 140, "Temps", 2); + EcrireTexte(1250, 300, "Utiliser les fleches", 1); + EcrireTexte(1250, 320, "pour se deplacer", 1); + EcrireTexte(1250, 370, "Espace = pause", 1); + EcrireTexte(1250, 435, "Echape = quiiter", 1); + EcrireTexte(1290, 600, "Score",2); diff --git a/snake/main.c b/snake/main.c index 5c168a0..330d416 100644 --- a/snake/main.c +++ b/snake/main.c @@ -7,10 +7,12 @@ #include "deplacement.h" #include "score_init.h" #include "ecran_lancement.h" +#include "affichage_timer.h" +#include "ecran_fin.h" -#define CYCLE 200000L - +#define CYCLE_SERPENT 200000L +#define CYCLE_TIMER 1000000L int main(void) { @@ -21,7 +23,7 @@ int main(void) { short int* compteur = NULL; - int i = 0, j; + int i; unsigned short* indice_queue = pointeur -> indice_queue; @@ -32,13 +34,14 @@ int main(void) { unsigned char* tete = pointeur -> tete; - unsigned char jeu; + unsigned char jeu, entrer, minutes, secondes; - unsigned long suivant; + unsigned long suivant_serpent, suivant_timer; unsigned long acceleration = 0L; - int numsprite; + int numsprite; + @@ -51,7 +54,10 @@ int main(void) { *retard = 0; - suivant = Microsecondes() + CYCLE; + suivant_serpent = Microsecondes() + CYCLE_SERPENT; + + suivant_timer = Microsecondes() + CYCLE_TIMER; + @@ -66,29 +72,35 @@ int main(void) { jeu = ecran_lancement(); + if (jeu == 1) { + + entrer = 1; + } + numsprite = start(pointeur); compteur = score_init(); + minutes = 0; + + secondes = 0; + + affichage_timer(minutes, secondes); + while (jeu == 1) { - if (Microsecondes() > suivant) { - - /* printf("(%d %d)\n", pointeur -> corps_serpent[*indice_queue][0], pointeur -> corps_serpent[*indice_queue][1]); - - printf("[%hhu %hhu]\n", tete[0], tete[1]);*/ - + if (Microsecondes() > suivant_serpent) { jeu = deplacement(pointeur, sens, retard, compteur, &acceleration, numsprite); - suivant = Microsecondes() + CYCLE - acceleration; + suivant_serpent = Microsecondes() + CYCLE_SERPENT - acceleration; - printf("{%ld}", acceleration); + printf("%u:%u\n", minutes, secondes); @@ -96,8 +108,27 @@ int main(void) { } + if (Microsecondes () > suivant_timer) { + + + secondes++; + + suivant_timer = Microsecondes() + CYCLE_TIMER; + + if (secondes == 60) { + + secondes = 0; + + minutes++; + + + } + affichage_timer(minutes,secondes); + } } + + LibererSprite(numsprite); @@ -132,13 +163,14 @@ int main(void) { free(pointeur); - free(compteur); - free(retard); + free(retard); - + if (entrer == 1 ) { + ecran_fin(compteur, minutes, secondes); + } FermerGraphique(); diff --git a/snake/pomme.png b/snake/pomme.png index df5b26c3df1c77ca131630cf1d3ad13729c45e72..0ac8c01034a4ebdbe65b947db7443095a1e1e7ff 100644 GIT binary patch delta 1422 zcmX@Y{hxb6K>gwXpAc6D28JM6W_L;E5LxC>IcCE&c9Hqqd^1@^=5hPWFk6T)snu`@ zP2hA8W6Drr=Bs0~5@F(RWoNWzxM^;F$HHQTuKIs1C%YWMX@P2d)ojN!HMhyiUNbd) z?dG;!PVTy?=`IC@o$~UxEiF&$>fW-j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Zn?fxRkli;`{J0s=J-OIO+CmdSP zE%ISk0K-!zh9g~t6M1YZ{!X@Fl@&1vF*LO@F|#r;(l#)#GBCJjsj+c#CKieHDHC`n d&tg?jfax$bhv-OqJP#C^44$rjF6*2UngC<e#2x?u diff --git a/snake/score_init.c b/snake/score_init.c index 9b372a4..71db24d 100644 --- a/snake/score_init.c +++ b/snake/score_init.c @@ -10,23 +10,23 @@ short int* score_init(void) { couleur white; - short int* compteur = NULL; - char a[20]; + short int* compteur = NULL; + char a[20]; - white = CouleurParComposante(255,255,255); - ChoisirCouleurDessin(white); + white = CouleurParComposante(255,255,255); + ChoisirCouleurDessin(white); - compteur = malloc(sizeof(short int)); - *compteur = 0; + compteur = malloc(sizeof(short int)); + *compteur = 0; - sprintf(a, "%d", *compteur); + sprintf(a, "%hd", *compteur); - EcrireTexte(1270, 600, a, 2); + EcrireTexte(1310, 650, a, 2); - return compteur; + return compteur; } diff --git a/snake/time.c b/snake/time.c deleted file mode 100644 index fc43c3c..0000000 --- a/snake/time.c +++ /dev/null @@ -1,97 +0,0 @@ - -#include <stdlib.h> -#include <stdio.h> -#include <graph.h> - - -#define CYCLE 1000000L - - -int main(void) { - - unsigned long suivant; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* int* time = NULL; */ - - /* time = malloc( sizeof(short int)); - - time[0] = 0; - time[1] = 0; */ - - - suivant = Microsecondes() + CYCLE; - - /*printf("%d : %d\n", &time[0],&time[1]);*/ - - while (1) { - - if (Microsecondes() > suivant) { - - - - /* une periode s'est écoulé */ - /* prochaine date */ - - suivant = Microsecondes()+CYCLE; - - /*time[1]++; - - if ( time[1] == 60) { - - time[1] = 0; - - time[0] ++; - - }*/ - printf("%lu", Microsecondes()); - - - - - - - } - - - /* if ( ToucheEnAttente() == 1 ) { - - if (Touche() == XK_space) { - - break; - - } - }*/ - - - } - - return EXIT_SUCCESS; - -} diff --git a/snake/time.h b/snake/time.h deleted file mode 100644 index 612f1b4..0000000 --- a/snake/time.h +++ /dev/null @@ -1,10 +0,0 @@ - - - -#ifndef TIME_H -#define TIME_H - -void time(void); - - -#endif /* TIME_H */