2022-11-30 17:23:59 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <graph.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include "images.h"
|
|
|
|
#include "jeu.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2022-12-02 16:12:33 +01:00
|
|
|
int jeu(int position[20][4], int nb_paires,int tab[40]){
|
|
|
|
int score=0,score2,repet,test=0;
|
2022-11-30 21:06:30 +01:00
|
|
|
int pos_x,pos_y;
|
2022-12-02 16:12:33 +01:00
|
|
|
int i,j,g,n=0,x=0, stock_g_1, stock_g_2;
|
2022-12-01 16:42:34 +01:00
|
|
|
int repet2, nb_images;
|
2022-11-30 17:41:26 +01:00
|
|
|
int clic_x,clic_y,im_y,im_x;
|
2022-12-02 16:12:33 +01:00
|
|
|
unsigned long temps, temps2,temps3=1;
|
|
|
|
char tempstab[50],affichage[50],scoretab[50];
|
2022-12-01 23:17:52 +01:00
|
|
|
char* comparer1[50], comparer2[50];
|
2022-11-30 22:19:45 +01:00
|
|
|
couleur c=CouleurParComposante(0,0,0);
|
2022-11-30 21:06:30 +01:00
|
|
|
temps2=Microsecondes();
|
2022-12-02 16:12:33 +01:00
|
|
|
ChargerImage("./Images/score.png",760,250,0,0,224,63);
|
2022-12-01 16:42:34 +01:00
|
|
|
printf("Voici le nombre de paires: %d\n", nb_paires);
|
|
|
|
nb_images=nb_paires*2;
|
|
|
|
score=0;
|
2022-12-02 16:12:33 +01:00
|
|
|
c=CouleurParComposante(255,255,255); ChoisirCouleurDessin(c);
|
|
|
|
RemplirRectangle(850,320,50,50);
|
|
|
|
snprintf(scoretab,50,"%d",score);
|
|
|
|
c=CouleurParComposante(0,0,0);
|
|
|
|
ChoisirCouleurDessin(c);
|
|
|
|
EcrireTexte(865,360,scoretab,2);
|
2022-12-01 16:42:34 +01:00
|
|
|
while(score<nb_paires){
|
2022-12-01 12:35:57 +01:00
|
|
|
printf("\n\nVoici le score: %d\n", score);
|
2022-12-02 11:40:27 +01:00
|
|
|
|
|
|
|
/*Gestion du temps*/
|
2022-11-30 21:06:30 +01:00
|
|
|
temps=(Microsecondes()-temps2)/1000000;
|
2022-12-01 23:26:15 +01:00
|
|
|
if(temps!=temps3){
|
2022-11-30 22:19:45 +01:00
|
|
|
snprintf(tempstab,50,"%ld secondes ecoulees",temps);
|
|
|
|
c=CouleurParComposante(0,0,0);
|
|
|
|
ChoisirCouleurDessin(c);
|
|
|
|
RemplirRectangle(863,83,120,20);
|
|
|
|
c=CouleurParComposante(255,255,255);
|
|
|
|
ChoisirCouleurDessin(c);
|
|
|
|
EcrireTexte(867,100,tempstab,0);
|
2022-12-01 23:26:15 +01:00
|
|
|
}
|
2022-11-30 22:19:45 +01:00
|
|
|
temps3=temps;
|
2022-12-02 11:40:27 +01:00
|
|
|
|
2022-12-01 12:35:57 +01:00
|
|
|
repet=0;
|
2022-12-02 11:40:27 +01:00
|
|
|
|
2022-12-01 23:26:15 +01:00
|
|
|
while (repet<2){
|
|
|
|
temps=(Microsecondes()-temps2)/1000000;
|
|
|
|
if(temps!=temps3){
|
|
|
|
snprintf(tempstab,50,"%ld secondes ecoulees",temps);
|
|
|
|
c=CouleurParComposante(0,0,0);
|
|
|
|
ChoisirCouleurDessin(c);
|
|
|
|
RemplirRectangle(863,83,120,20);
|
|
|
|
c=CouleurParComposante(255,255,255);
|
|
|
|
ChoisirCouleurDessin(c);
|
|
|
|
EcrireTexte(867,100,tempstab,0);
|
|
|
|
}
|
|
|
|
temps3=temps;
|
2022-12-02 16:12:33 +01:00
|
|
|
/*Triche*/
|
|
|
|
if(ToucheEnAttente() && Touche(XK_t)){
|
|
|
|
n=0;
|
|
|
|
while(n<1){
|
|
|
|
x=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[x]==-1){
|
|
|
|
pos_x=650;
|
|
|
|
pos_y=1000;
|
|
|
|
}
|
|
|
|
if (position[tab[x]][0]==0){
|
|
|
|
position[tab[x]][0]=pos_x;
|
|
|
|
position[tab[x]][1]=pos_y;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
position[tab[x]][2]=pos_x;
|
|
|
|
position[tab[x]][3]=pos_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(affichage,50,"Images/image%d.png",(tab[x]+1));
|
|
|
|
ChargerImage(affichage,pos_x,pos_y,0,0,80,80);
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ToucheEnAttente() && Touche(XK_t)){
|
|
|
|
x=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[x]==-1){
|
|
|
|
pos_x=650;
|
|
|
|
pos_y=1000;
|
|
|
|
}
|
|
|
|
if (position[tab[x]][0]==0){
|
|
|
|
position[tab[x]][0]=pos_x;
|
|
|
|
position[tab[x]][1]=pos_y;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
position[tab[x]][2]=pos_x;
|
|
|
|
position[tab[x]][3]=pos_y;
|
|
|
|
}
|
|
|
|
ChargerImage("Images/image0.png",pos_x,pos_y,0,0,80,80);
|
|
|
|
x++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
n=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-30 17:23:59 +01:00
|
|
|
if (SourisCliquee()){
|
|
|
|
clic_x=_X;
|
|
|
|
clic_y=_Y;
|
|
|
|
|
|
|
|
im_x=0;
|
|
|
|
im_y=0;
|
2022-12-02 11:40:27 +01:00
|
|
|
|
|
|
|
/*Détecter si le clic était sur l'axe des ordonnées d'une image*/
|
2022-11-30 17:23:59 +01:00
|
|
|
for (pos_y=370;pos_y>=10;pos_y=pos_y-90){
|
|
|
|
if (clic_y>=pos_y){
|
|
|
|
if (clic_y<=pos_y+80){
|
|
|
|
im_y=pos_y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-02 11:40:27 +01:00
|
|
|
|
|
|
|
/*Détecter si le clic était sur l'axe des abcisses d'une image*/
|
2022-11-30 17:23:59 +01:00
|
|
|
for (pos_x=640;pos_x>=10;pos_x=pos_x-90){
|
|
|
|
if (clic_x>=pos_x){
|
|
|
|
if (clic_x<=pos_x+80){
|
|
|
|
im_x=pos_x;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-02 11:40:27 +01:00
|
|
|
/*Si les deux boucles précédentes ont été vérifiées (si le clic a bien eu lieu sur une image)*/
|
2022-11-30 17:23:59 +01:00
|
|
|
if (im_x!=0 && im_y!=0){
|
|
|
|
for (i=0;i<20;i++){
|
|
|
|
for (j=0;j<2;j++){
|
2022-12-01 12:35:57 +01:00
|
|
|
if (position[i][(j*2)]==im_x && position[i][(j*2+1)]==im_y){
|
2022-12-01 23:17:52 +01:00
|
|
|
if (repet==0){
|
|
|
|
g=i+1;
|
|
|
|
stock_g_1=g;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
g=i+1;
|
|
|
|
stock_g_2=g;
|
|
|
|
}
|
2022-12-02 10:00:49 +01:00
|
|
|
snprintf(affichage,50,"Images/image%d.png",g);
|
2022-12-02 11:40:27 +01:00
|
|
|
printf("Voici affichage: %s\n",affichage);
|
2022-12-02 10:00:49 +01:00
|
|
|
ChargerImage(affichage,im_x,im_y,0,0,80,80);
|
2022-12-01 12:35:57 +01:00
|
|
|
repet++;
|
2022-11-30 17:23:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-01 13:53:28 +01:00
|
|
|
}
|
2022-12-01 12:35:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*printf("%d\n", im_x);
|
|
|
|
printf("%d\n", im_y);*/
|
2022-12-02 11:40:27 +01:00
|
|
|
|
|
|
|
/*Si les deux images retournées ont le même numéro*/
|
2022-12-01 23:17:52 +01:00
|
|
|
if (stock_g_1==stock_g_2){
|
2022-12-01 22:32:16 +01:00
|
|
|
score++;
|
2022-12-02 11:40:27 +01:00
|
|
|
for (i=0; i<40;i++){
|
|
|
|
if (tab[i]==stock_g_1){
|
|
|
|
tab[i]=0;
|
|
|
|
}
|
|
|
|
}
|
2022-12-01 23:53:31 +01:00
|
|
|
position[stock_g_1-1][0]=0;
|
|
|
|
position[stock_g_1-1][1]=0;
|
|
|
|
position[stock_g_1-1][2]=0;
|
|
|
|
position[stock_g_1-1][3]=0;
|
2022-12-01 12:35:57 +01:00
|
|
|
}
|
2022-12-01 16:42:34 +01:00
|
|
|
repet2=0;
|
2022-12-02 11:40:27 +01:00
|
|
|
i=0;
|
2022-12-01 23:17:52 +01:00
|
|
|
if (score!=nb_paires){
|
2022-12-01 12:35:57 +01:00
|
|
|
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){
|
2022-12-02 11:40:27 +01:00
|
|
|
printf("Voici tab[%d]", i);
|
|
|
|
printf(": %d\n", tab[i]);
|
|
|
|
|
|
|
|
repet2++;
|
|
|
|
if (repet2==nb_images){
|
|
|
|
pos_x=750;
|
|
|
|
pos_y=380;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tab[i]!=0){
|
|
|
|
ChargerImage("Images/image0.png",pos_x,pos_y,0,0,80,80);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
|
2022-12-01 12:35:57 +01:00
|
|
|
}
|
2022-11-30 17:23:59 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-02 16:12:33 +01:00
|
|
|
if(score2!=score){
|
|
|
|
c=CouleurParComposante(255,255,255);
|
|
|
|
ChoisirCouleurDessin(c);
|
|
|
|
RemplirRectangle(850,320,50,50);
|
|
|
|
snprintf(scoretab,50,"%d",score);
|
|
|
|
c=CouleurParComposante(0,0,0);
|
|
|
|
ChoisirCouleurDessin(c);
|
|
|
|
EcrireTexte(865,360,scoretab,2);
|
|
|
|
}
|
|
|
|
score2=score;
|
2022-11-30 17:23:59 +01:00
|
|
|
}
|
2022-12-02 16:12:33 +01:00
|
|
|
ChargerImage("./Images/FIN.png",300,460,0,0,399,87);
|
2022-12-01 17:52:53 +01:00
|
|
|
Touche();
|
|
|
|
FermerGraphique();
|
2022-12-01 23:17:52 +01:00
|
|
|
return 1;
|
2022-11-30 17:23:59 +01:00
|
|
|
}
|