Merge branch 'master' of dwarves.iut-fbleau.fr:morinl/SAE11_2021

This commit is contained in:
morinl 2022-12-03 16:41:31 +01:00
commit a7efec73fa
8 changed files with 128 additions and 41 deletions

BIN
Images/FIN.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
Images/score.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@ -13,4 +13,5 @@ menu.o: menu.c menu.h
$(CC) menu.c $(CFLAGS) $(CC) menu.c $(CFLAGS)
jeu.o: jeu.c jeu.h images.h jeu.o: jeu.c jeu.h images.h
$(CC) jeu.c $(CFLAGS) $(CC) jeu.c $(CFLAGS)
run:./jeu run:
./jeu

View File

@ -47,6 +47,7 @@ int tirage_aleatoire(int nb_paires){
for (pos_y=10;pos_y<=370;pos_y=pos_y+90){ for (pos_y=10;pos_y<=370;pos_y=pos_y+90){
for (pos_x=10;pos_x<=640;pos_x=pos_x+90){ for (pos_x=10;pos_x<=640;pos_x=pos_x+90){
if (tab[i]==-1){ if (tab[i]==-1){
pos_x=650;
pos_y=1000; pos_y=1000;
} }
if (positions[tab[i]][0]==0){ if (positions[tab[i]][0]==0){
@ -57,18 +58,14 @@ int tirage_aleatoire(int nb_paires){
positions[tab[i]][2]=pos_x; positions[tab[i]][2]=pos_x;
positions[tab[i]][3]=pos_y; positions[tab[i]][3]=pos_y;
} }
/*Triche
snprintf(tirage,50,"Images/image%d.png",(tab[i]+1));
ChargerImage(tirage,pos_x,pos_y,0,0,80,80);*/
ChargerImage("Images/image0.png",pos_x,pos_y,0,0,80,80); ChargerImage("Images/image0.png",pos_x,pos_y,0,0,80,80);
i++; i++;
} }
} }
/*
for (i=0;i<19;i++){ /*for (i=0;i<19;i++){
printf("%03d", i); printf("%03d", i);
printf(" "); printf(" ");
} }
@ -79,8 +76,12 @@ int tirage_aleatoire(int nb_paires){
printf(" "); printf(" ");
} }
printf("\n"); printf("\n");
}
for (i=0;i<40;i++){
printf("%d\n",tab[i]);
}*/ }*/
score=jeu(positions, nb_paires);
score=jeu(positions, nb_paires,tab);
Touche(); Touche();
FermerGraphique(); FermerGraphique();
printf("\n"); printf("\n");

140
jeu.c
View File

@ -6,26 +6,32 @@
#include "jeu.h" #include "jeu.h"
#include <unistd.h> #include <unistd.h>
int jeu(int position[20][4], int nb_paires){ int jeu(int position[20][4], int nb_paires,int tab[40]){
int score=0,repet,test=0; int score=0,score2,repet,test=0;
int pos_x,pos_y; int pos_x,pos_y;
int i,j,g; int i,j,g,n=0,x=0, stock_g_1, stock_g_2;
int repet2, nb_images; int repet2, nb_images;
int clic_x,clic_y,im_y,im_x; int clic_x,clic_y,im_y,im_x, im_x_1, im_x_2, im_y_1, im_y_2;
unsigned long temps, temps2,temps3; unsigned long temps, temps2,temps3=1;
char tempstab[50],affichage[50];; char tempstab[50],affichage[50],scoretab[50];
char* comparer[2];
int tab[3];
couleur c=CouleurParComposante(0,0,0); couleur c=CouleurParComposante(0,0,0);
temps2=Microsecondes(); temps2=Microsecondes();
ChargerImage("./Images/score.png",760,250,0,0,224,63);
printf("Voici le nombre de paires: %d\n", nb_paires); printf("Voici le nombre de paires: %d\n", nb_paires);
nb_images=nb_paires*2; nb_images=nb_paires*2;
score=0; score=0;
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);
while(score<nb_paires){ while(score<nb_paires){
printf("\n\nVoici le score: %d\n", score);
temps=(Microsecondes()-temps2)/1000000; temps=(Microsecondes()-temps2)/1000000;
//if(temps!=temps3){ if(temps!=temps3){
snprintf(tempstab,50,"%ld secondes ecoulees",temps); snprintf(tempstab,50,"%ld secondes ecoulees",temps);
c=CouleurParComposante(0,0,0); c=CouleurParComposante(0,0,0);
ChoisirCouleurDessin(c); ChoisirCouleurDessin(c);
@ -33,12 +39,58 @@ int jeu(int position[20][4], int nb_paires){
c=CouleurParComposante(255,255,255); c=CouleurParComposante(255,255,255);
ChoisirCouleurDessin(c); ChoisirCouleurDessin(c);
EcrireTexte(867,100,tempstab,0); EcrireTexte(867,100,tempstab,0);
//} }
temps3=temps; temps3=temps;
repet=0; repet=0;
comparer[0]="vide"; /*comparer[0]="vide";
comparer[1]="vide"; comparer[1]="vide";*/
while (repet<2){ 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;
/*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;
}
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;
}
ChargerImage("Images/image0.png",pos_x,pos_y,0,0,80,80);
x++;
}
}
n=1;
}
}
}
/*Clic de la souris*/
if (SourisCliquee()){ if (SourisCliquee()){
clic_x=_X; clic_x=_X;
clic_y=_Y; clic_y=_Y;
@ -46,10 +98,17 @@ int jeu(int position[20][4], int nb_paires){
im_x=0; im_x=0;
im_y=0; im_y=0;
/*Détection des coordonées x et y du clic de la souris*/
for (pos_y=370;pos_y>=10;pos_y=pos_y-90){ for (pos_y=370;pos_y>=10;pos_y=pos_y-90){
if (clic_y>=pos_y){ if (clic_y>=pos_y){
if (clic_y<=pos_y+80){ if (clic_y<=pos_y+80){
im_y=pos_y; im_y=pos_y;
if (repet==0){
im_y_1=pos_y;
}
else{
im_y_2=pos_y;
}
break; break;
} }
} }
@ -58,23 +117,31 @@ int jeu(int position[20][4], int nb_paires){
if (clic_x>=pos_x){ if (clic_x>=pos_x){
if (clic_x<=pos_x+80){ if (clic_x<=pos_x+80){
im_x=pos_x; im_x=pos_x;
if (repet==0){
im_x_1=pos_x;
}
else{
im_x_2=pos_x;
}
break; break;
} }
} }
} }
if (im_x!=0 && im_y!=0){ if (im_x!=0 && im_y!=0 && (im_x_1!=im_x_2 || im_y_1!=im_y_2)){
for (i=0;i<20;i++){ for (i=0;i<20;i++){
for (j=0;j<2;j++){ for (j=0;j<2;j++){
if (position[i][(j*2)]==im_x && position[i][(j*2+1)]==im_y){ if (position[i][(j*2)]==im_x && position[i][(j*2+1)]==im_y){
g=i+1; g=i+1;
if (repet==0){
stock_g_1=g;
}
else{
stock_g_2=g;
}
snprintf(affichage,50,"Images/image%d.png",g); 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); ChargerImage(affichage,im_x,im_y,0,0,80,80);
printf("%s\n", affichage);
repet++; repet++;
} }
} }
@ -82,19 +149,28 @@ int jeu(int position[20][4], int nb_paires){
} }
} }
} }
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_x);
printf("%d\n", im_y);*/ printf("%d\n", im_y);*/
if (comparer[0]==comparer[1]){ if (stock_g_1==stock_g_2){
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;
score++; score++;
for (i=0;i<40;i++){
if (tab[i]==stock_g_1){
printf("oui");
//nb_trouves[i]=tab[i];
}
}
} }
repet2=0; repet2=0;
if (score!=20){ if (score!=nb_paires){
sleep(1); sleep(1);
for (pos_y=10;pos_y<=370;pos_y=pos_y+90){ for (pos_y=10;pos_y<=370;pos_y=pos_y+90){
for (pos_x=10;pos_x<=640;pos_x=pos_x+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); ChargerImage("Images/image0.png",pos_x,pos_y,0,0,80,80);
repet2++; repet2++;
if (repet2==nb_images){ if (repet2==nb_images){
pos_x=750; pos_x=750;
@ -103,7 +179,19 @@ int jeu(int position[20][4], int nb_paires){
} }
} }
} }
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;
} }
FermerGraphique(); ChargerImage("./Images/FIN.png",300,460,0,0,399,87);
return EXIT_SUCCESS; Touche();
FermerGraphique();
return 1;
} }

2
jeu.h
View File

@ -1,6 +1,6 @@
#ifndef JEU_H #ifndef JEU_H
#define JEU_H #define JEU_H
int jeu(int positions[20][4], int nb_paires); int jeu(int positions[20][4], int nb_paires,int tab[40]);
#endif #endif

1
main.c
View File

@ -12,6 +12,5 @@ int main(void){
int nb_paires=menu(); int nb_paires=menu();
char tableautemps[50]; char tableautemps[50];
tirage_aleatoire(nb_paires); tirage_aleatoire(nb_paires);
FermerGraphique();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

2
menu.c
View File

@ -15,8 +15,6 @@ int menu(void){
ChoisirCouleurDessin(c); ChoisirCouleurDessin(c);
ChargerImage("Images/background.png",0,0,0,0,1024,576); ChargerImage("Images/background.png",0,0,0,0,1024,576);
ChargerImage("Images/Menu1.png",276,19,0,0,476,63); ChargerImage("Images/Menu1.png",276,19,0,0,476,63);
c=CouleurParComposante(0,0,0);
ChoisirCouleurDessin(c);
ChargerImage("Images/Menu2.png",323,250,0,0,383,44); ChargerImage("Images/Menu2.png",323,250,0,0,383,44);
ChargerImage("Images/Fleche1.png",290,253,0,0,33,39); ChargerImage("Images/Fleche1.png",290,253,0,0,33,39);
ChargerImage("Images/Fleche2.png",710,253,0,0,34,39); ChargerImage("Images/Fleche2.png",710,253,0,0,34,39);