From 3a156893f95bea69b96932ee4d7d78f78720709c Mon Sep 17 00:00:00 2001 From: Axel Date: Thu, 8 Dec 2022 11:53:33 +0100 Subject: [PATCH] Travail du 07/12/22 --- affichage.c | 41 +++++++++++++++++++++++++---------------- affichage.h | 2 +- menu_v2.c | 30 ++++++++++++++++++------------ timer.c | 50 +++++++------------------------------------------- timer.h | 3 ++- 5 files changed, 53 insertions(+), 73 deletions(-) diff --git a/affichage.c b/affichage.c index ced861e..fded41d 100644 --- a/affichage.c +++ b/affichage.c @@ -2,8 +2,6 @@ #include #include #include -#define GRILLE_X 4 -#define GRILLE_Y 4 int Trouvee(int* found, int carte){ int i; @@ -149,10 +147,13 @@ void InsereTableau(int val, int* tab){ } } -int essay(void){ +int essay(int grille_x){ + char afficher_temps[20]; int tab[4][5] = {{},{},{},{}}; int o; - int timerStop; + unsigned long temps_microsec = Microsecondes(); + unsigned long temps_ecoule = 0; + unsigned long temps_ancien = -1; int i,j; int x=1; int temps; @@ -161,24 +162,32 @@ int essay(void){ int found[10] = {}; int carte_1[3] = {0,-1,-1}; int carte_2[3] = {0,-1,-1}; - GenererGrille(GRILLE_Y, GRILLE_X, tab); + GenererGrille(4, grille_x, tab); InitialiserGraphique(); CreerFenetre(10,10,1500,844); ChoisirCouleurDessin(CouleurParComposante(0,0,0)); - DessinerGrille(GRILLE_X,GRILLE_Y,1500,844,0,found,tab); - while(1){ - timer(); + DessinerGrille(grille_x,4,1500,844,0,found,tab); + while(1){ + if (x==1){ + timer(&temps_ecoule, temps_microsec); + } + if (temps_ecoule = temps_ancien+1){ + temps_ancien = temps_ecoule; + ChoisirCouleurDessin(CouleurParNom("black")); + RemplirRectangle(675,25,160,30); + ChoisirCouleurDessin(CouleurParNom("white")); + sprintf(afficher_temps,"Time : %03ds",temps_ecoule); + EcrireTexte(700,50,afficher_temps,1); + } if (ToucheEnAttente()){ touche = Touche(); if (touche == XK_t){ Triche(&x); if (x==-1){ - DessinerGrille(GRILLE_X,GRILLE_Y,1500,844,1,found,tab); - timerStop = 1; + DessinerGrille(grille_x,4,1500,844,1,found,tab); } else{ - DessinerGrille(GRILLE_X,GRILLE_Y,1500,844,0,found,tab); - timerStop = 0; + DessinerGrille(grille_x,4,1500,844,0,found,tab); } } if (touche == XK_space) @@ -189,13 +198,13 @@ int essay(void){ if (x==1){ if (carte_1[0] == 0){ - Jeu(GRILLE_X,GRILLE_Y,1500,844,carte_1,tab); + Jeu(grille_x,4,1500,844,carte_1,tab); if (Trouvee(found,carte_1[0])){ carte_1[0] = 0; } } else if (carte_2[0] == 0){ - Jeu(GRILLE_X,GRILLE_Y,1500,844,carte_2,tab); + Jeu(grille_x,4,1500,844,carte_2,tab); if (carte_1[1] == carte_2[1] && carte_1[2] == carte_2[2]) carte_2[0] = 0; if (Trouvee(found,carte_2[0])) carte_2[0] = 0; } @@ -216,10 +225,10 @@ int essay(void){ while (temps < retourne_time){ temps = Microsecondes(); } - DessinerGrille(GRILLE_X,GRILLE_Y,1500,844,0,found,tab); + DessinerGrille(grille_x,4,1500,844,0,found,tab); } - if (Victoire(found,GRILLE_X,GRILLE_Y)){ + if (Victoire(found,grille_x,4)){ printf("Victoire !\n"); break; } diff --git a/affichage.h b/affichage.h index 5a172ac..8e60222 100644 --- a/affichage.h +++ b/affichage.h @@ -21,7 +21,7 @@ int Victoire(int* found, int x_grille, int y_grille); void InsereTableau(int val, int* tab); -int essay(void); +int essay(int grille_x); #endif /* AFFICHAGE_H */ diff --git a/menu_v2.c b/menu_v2.c index d4746ca..b1b870b 100644 --- a/menu_v2.c +++ b/menu_v2.c @@ -78,14 +78,16 @@ int menu_principal(void){ y=_Y; if((x>68) && (x<488) && (y>266) && (y<696)){ - EffacerEcran(CouleurParNom("grey")); + FermerGraphique(); + essay(3); } if((x>537) && (x<958) && (y>266) && (y<696)){ - EffacerEcran(CouleurParNom("white")); - essay(); + FermerGraphique(); + essay(4); } if((x>1007) && (x<1432) && (y>266) && (y<696)) { - EffacerEcran(CouleurParNom("grey")); + FermerGraphique(); + essay(5); } } } @@ -100,14 +102,16 @@ int menu_principal(void){ x=_X; y=_Y; if((x>68) && (x<488) && (y>266) && (y<696)){ - EffacerEcran(CouleurParNom("grey")); + FermerGraphique(); + essay(3); } if((x>537) && (x<958) && (y>266) && (y<696)){ - EffacerEcran(CouleurParNom("white")); - essay(); + FermerGraphique(); + essay(4); } if((x>1007) && (x<1432) && (y>266) && (y<696)) { - EffacerEcran(CouleurParNom("grey")); + FermerGraphique(); + essay(5); } } } @@ -122,14 +126,16 @@ int menu_principal(void){ x=_X; y=_Y; if((x>68) && (x<488) && (y>266) && (y<696)){ - EffacerEcran(CouleurParNom("grey")); + FermerGraphique(); + essay(3); } if((x>537) && (x<958) && (y>266) && (y<696)){ - EffacerEcran(CouleurParNom("white")); - essay(); + FermerGraphique(); + essay(4); } if((x>1007) && (x<1432) && (y>266) && (y<696)) { - EffacerEcran(CouleurParNom("grey")); + FermerGraphique(); + essay(5); } } } diff --git a/timer.c b/timer.c index af7bd32..d5c1c99 100644 --- a/timer.c +++ b/timer.c @@ -1,48 +1,12 @@ -#include "timer.h" #include -#include #include +#include -unsigned long temps_ecoule = 0; -unsigned long temps = Microsecondes(); -int time; -int seconde_passee; -int minutes = 0; -int secondes = 0; - //int a = 1; -int temps_reference = 0; -char afficher_temps[20]; - -int timer(void){ - //unsigned long temps_ecoule = 0; - //unsigned long temps = Microsecondes(); - //int timer; - //int seconde_passee; - //int minutes = 0; - //int secondes = 0; - //int a = 1; - //int temps_reference = 0; - //char afficher_temps[20]; - - temps_ecoule = (int) (Microsecondes() - temps); - if (temps_reference59){ - minutes = secondes/60; - secondes = secondes - (minutes * 60); - } - ChoisirCouleurDessin(CouleurParNom("black")); - RemplirRectangle(675,25,160,30); - ChoisirCouleurDessin(CouleurParNom("white")); - snprintf(afficher_temps,15,"Time : %02d : %02d",minutes,secondes); - EcrireTexte(700,50,afficher_temps,1); - } +void timer(unsigned long* temps_ecoule, unsigned long temps_microsec){ + unsigned long temps_actuel = Microsecondes(); + if (temps_actuel > temps_microsec + 1000000){ + temps_microsec = temps_actuel; + *temps_ecoule++; + printf("%d",*temps_ecoule); } - return EXIT_SUCCESS; } - - diff --git a/timer.h b/timer.h index b09e02e..73c1c2b 100644 --- a/timer.h +++ b/timer.h @@ -1,7 +1,8 @@ + #ifndef TIMER_H #define TIMER_H -int timer(void); +void timer(unsigned long* temps_ecoule, unsigned long temps_microsec); #endif /* TIMER_H */