Ajout du score a l'ecran+fin+makefile+mode triche

This commit is contained in:
morinl 2022-12-02 16:12:33 +01:00
parent 35cd80d6b8
commit 19ee66cc3b
8 changed files with 79 additions and 22 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

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

@ -58,10 +58,7 @@ 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 /*j'ai mis la triche dans le jeu.c*/
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++;
@ -81,7 +78,7 @@ int tirage_aleatoire(int nb_paires){
} }
printf("\n"); printf("\n");
}*/ }*/
score=jeu(positions, nb_paires); score=jeu(positions, nb_paires,tab);
Touche(); Touche();
FermerGraphique(); FermerGraphique();
printf("\n"); printf("\n");

81
jeu.c
View File

@ -6,24 +6,28 @@
#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, stock_g_1, stock_g_2; 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;
unsigned long temps, temps2,temps3; unsigned long temps, temps2,temps3=1;
char tempstab[50],affichage[50];; char tempstab[50],affichage[50],scoretab[50];
char* comparer1[50], comparer2[50]; char* comparer1[50], comparer2[50];
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);
@ -50,6 +54,55 @@ int jeu(int position[20][4], int nb_paires){
EcrireTexte(867,100,tempstab,0); EcrireTexte(867,100,tempstab,0);
} }
temps3=temps; 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;
}
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;
}
}
}
if (SourisCliquee()){ if (SourisCliquee()){
clic_x=_X; clic_x=_X;
clic_y=_Y; clic_y=_Y;
@ -116,8 +169,18 @@ 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);
} }
ChargerImage("./Images/FIN.png",300,500,0,0,445,31); score2=score;
}
ChargerImage("./Images/FIN.png",300,460,0,0,399,87);
Touche(); Touche();
FermerGraphique(); FermerGraphique();
return 1; 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

4
main.c
View File

@ -11,8 +11,6 @@ int main(void){
int temps,coucou; int temps,coucou;
int nb_paires=menu(); int nb_paires=menu();
char tableautemps[50]; char tableautemps[50];
int x=tirage_aleatoire(nb_paires); tirage_aleatoire(nb_paires);
if (x==1){
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);