SAE11_2021/jeu.c

123 lines
2.9 KiB
C
Raw Normal View History

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>
int jeu(int position[20][4], int nb_paires){
2022-11-30 22:19:45 +01:00
int score=0,repet,test=0;
2022-11-30 21:06:30 +01:00
int pos_x,pos_y;
2022-12-01 23:17:52 +01:00
int i,j,g, stock_g_1, stock_g_2;
int repet2, nb_images;
int clic_x,clic_y,im_y,im_x;
2022-11-30 22:19:45 +01:00
unsigned long temps, temps2,temps3;
2022-11-30 21:06:30 +01:00
char tempstab[50],affichage[50];;
2022-12-01 23:17:52 +01:00
char* comparer1[50], comparer2[50];
2022-11-30 22:19:45 +01:00
int tab[3];
couleur c=CouleurParComposante(0,0,0);
2022-11-30 21:06:30 +01:00
temps2=Microsecondes();
printf("Voici le nombre de paires: %d\n", nb_paires);
nb_images=nb_paires*2;
score=0;
while(score<nb_paires){
printf("\n\nVoici le score: %d\n", score);
2022-11-30 21:06:30 +01:00
temps=(Microsecondes()-temps2)/1000000;
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-11-30 22:19:45 +01:00
temps3=temps;
repet=0;
2022-12-01 23:17:52 +01:00
/*comparer[0]="vide";
comparer[1]="vide";*/
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-11-30 17:23:59 +01:00
if (SourisCliquee()){
clic_x=_X;
clic_y=_Y;
im_x=0;
im_y=0;
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;
}
}
}
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;
}
}
}
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 && position[i][(j*2+1)]==im_y){
2022-12-01 23:17:52 +01:00
if (repet==0){
g=i+1;
snprintf(comparer1,50,"Images/image%d.png",g);
ChargerImage(comparer1,im_x,im_y,0,0,80,80);
stock_g_1=g;
}
else{
g=i+1;
snprintf(comparer2,50,"Images/image%d.png",g);
ChargerImage(comparer2,im_x,im_y,0,0,80,80);
stock_g_2=g;
}
repet++;
2022-11-30 17:23:59 +01:00
}
}
}
2022-12-01 13:53:28 +01:00
}
}
}
/*printf("%d\n", im_x);
printf("%d\n", im_y);*/
2022-12-01 23:17:52 +01:00
if (stock_g_1==stock_g_2){
2022-12-01 22:32:16 +01:00
score++;
}
repet2=0;
2022-12-01 23:17:52 +01:00
if (score!=nb_paires){
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);
repet2++;
if (repet2==nb_images){
pos_x=750;
pos_y=380;
}
}
2022-11-30 17:23:59 +01:00
}
}
}
Touche();
FermerGraphique();
2022-12-01 23:17:52 +01:00
return 1;
2022-11-30 17:23:59 +01:00
}