From 7f5478f37420a672194353c4a088319c68a6e62d Mon Sep 17 00:00:00 2001 From: proal Date: Thu, 1 Dec 2022 12:35:57 +0100 Subject: [PATCH] =?UTF-8?q?Les=20images=20se=20retournent=20apr=C3=A8s=202?= =?UTF-8?q?=20clics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- images.c | 6 +++--- jeu.c | 43 +++++++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/images.c b/images.c index a7c7553..4c300a9 100644 --- a/images.c +++ b/images.c @@ -13,7 +13,7 @@ int tirage_aleatoire(void){ int i, j; int nb,score; int tab[40]; - int nb_paires=20; + int nb_paires=10; int positions[20][4]; ChargerImage("Images/background.png",0,0,0,0,1024,576); @@ -47,9 +47,9 @@ int tirage_aleatoire(void){ i=0; for (pos_y=10;pos_y<=370;pos_y=pos_y+90){ for (pos_x=10;pos_x<=640;pos_x=pos_x+90){ - /*if (tab[i]==-1){ + if (tab[i]==-1){ pos_y=1000; - }*/ + } if (positions[tab[i]][0]==0){ positions[tab[i]][0]=pos_x; positions[tab[i]][1]=pos_y; diff --git a/jeu.c b/jeu.c index e4c70fb..270d7bd 100644 --- a/jeu.c +++ b/jeu.c @@ -18,6 +18,7 @@ int jeu(int position[20][4]){ couleur c=CouleurParComposante(0,0,0); temps2=Microsecondes(); while(score<20){ + printf("\n\nVoici le score: %d\n", score); temps=(Microsecondes()-temps2)/1000000; //if(temps!=temps3){ snprintf(tempstab,50,"%ld secondes ecoulees",temps); @@ -29,7 +30,10 @@ int jeu(int position[20][4]){ EcrireTexte(867,100,tempstab,0); //} temps3=temps; - for (repet=0;repet<3;repet++){ + repet=0; + comparer[0]="vide"; + comparer[1]="vide"; + while (repet<2){ if (SourisCliquee()){ clic_x=_X; clic_y=_Y; @@ -57,22 +61,41 @@ int jeu(int position[20][4]){ if (im_x!=0 && im_y!=0){ for (i=0;i<20;i++){ for (j=0;j<2;j++){ - if (position[i][(j*2)]==im_x){ - if (position[i][(j*2+1)]==im_y){ - g=i+1; - snprintf(affichage,50,"Images/image%d.png",g); - comparer[repet]=affichage; - ChargerImage(affichage,im_x,im_y,0,0,80,80); - } + if (position[i][(j*2)]==im_x && position[i][(j*2+1)]==im_y){ + g=i+1; + snprintf(affichage,50,"Images/image%d.png",g); + printf("Voici repet: %d\n", repet); + printf("Voici affichage: %s\n", affichage); + comparer[repet]=affichage; + printf("Voici comparer[0]: %s\n", comparer[0]); + printf("Voici comparer[1]: %s\n\n", comparer[1]); + ChargerImage(affichage,im_x,im_y,0,0,80,80); + repet++; } } } - } + } + } + } + printf("Voici comparer[0]: %s\n", comparer[0]); + printf("Voici comparer[1]: %s\n", comparer[1]); + /*printf("%d\n", im_x); + printf("%d\n", im_y);*/ + if (comparer[0]==comparer[1]){ + score++; + } + if (score!=20){ + sleep(1); + for (pos_y=10;pos_y<=370;pos_y=pos_y+90){ + for (pos_x=10;pos_x<=640;pos_x=pos_x+90){ + ChargerImage("Images/image0.png",pos_x,pos_y,0,0,80,80); + } } } /*pour faire ça on va stocker temporairement quelles images (position) on a retournées dans tab[3], on check si toutes les cases du tableau sont utilisées et si oui alors on sleep(1) et on recharge l'image 0 sur les positions enregistrées dans le tab ensuite on revient au début de la boucle et on reset le tab[3] à 0.*/ } - return score; + FermerGraphique(); + return EXIT_SUCCESS; } \ No newline at end of file