2022-11-24 11:38:45 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <graph.h>
|
|
|
|
#include <time.h>
|
2022-11-22 16:03:31 +01:00
|
|
|
#include "images.h"
|
2022-11-29 23:02:28 +01:00
|
|
|
#include <unistd.h>
|
2022-11-21 16:10:01 +01:00
|
|
|
|
2022-11-29 18:05:27 +01:00
|
|
|
int tirage_aleatoire(void){
|
2022-11-28 16:55:10 +01:00
|
|
|
InitialiserGraphique();
|
2022-11-29 18:05:27 +01:00
|
|
|
char tirage[50], affichage[50];
|
2022-11-29 13:26:23 +01:00
|
|
|
int pos_x, pos_y, clic_x, clic_y, im_y, im_x;
|
2022-11-29 16:35:28 +01:00
|
|
|
int i, j, g;
|
|
|
|
int nb, score=0;
|
2022-11-28 13:42:06 +01:00
|
|
|
int tab[40];
|
2022-11-28 18:34:21 +01:00
|
|
|
int nb_paires=20;
|
|
|
|
int positions[20][4];
|
2022-11-29 21:29:46 +01:00
|
|
|
int repet;
|
2022-11-29 23:02:28 +01:00
|
|
|
char* comparer[2];
|
2022-11-28 16:55:10 +01:00
|
|
|
|
|
|
|
ChargerImage("Images/background.png",0,0,0,0,1024,576);
|
|
|
|
|
2022-11-28 18:34:21 +01:00
|
|
|
/*Initialisation des tableaux*/
|
|
|
|
for (i=0;i<20;i++){
|
2022-11-29 17:27:10 +01:00
|
|
|
for (j=0;j<4;j++){
|
2022-11-28 18:34:21 +01:00
|
|
|
positions[i][j]=0;
|
2022-11-29 16:35:28 +01:00
|
|
|
}
|
2022-11-28 18:34:21 +01:00
|
|
|
}
|
2022-11-28 16:55:10 +01:00
|
|
|
for (i=0;i<40;i++){
|
2022-11-29 17:27:10 +01:00
|
|
|
tab[i]=-1;
|
2022-11-28 16:55:10 +01:00
|
|
|
}
|
2022-11-21 16:19:18 +01:00
|
|
|
|
2022-11-28 18:34:21 +01:00
|
|
|
/*Tirage des images*/
|
2022-11-25 10:59:42 +01:00
|
|
|
srand(time(NULL));
|
2022-11-28 16:55:10 +01:00
|
|
|
for (i=0;i<2;i++){
|
2022-11-29 17:27:10 +01:00
|
|
|
for (j=0;j<nb_paires;j++){
|
2022-11-28 16:55:10 +01:00
|
|
|
nb=rand()%(nb_paires*2);
|
2022-11-29 17:27:10 +01:00
|
|
|
if (tab[nb]!=-1){
|
2022-11-28 16:55:10 +01:00
|
|
|
j--;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
tab[nb]=j;
|
2022-11-28 13:42:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-28 18:34:21 +01:00
|
|
|
/*Affichage des images*/
|
2022-11-28 16:55:10 +01:00
|
|
|
srand(time(NULL));
|
|
|
|
i=0;
|
2022-11-29 18:05:27 +01:00
|
|
|
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-11-29 17:27:10 +01:00
|
|
|
/*if (tab[i]==-1){
|
2022-11-28 16:55:10 +01:00
|
|
|
pos_y=1000;
|
2022-11-29 17:27:10 +01:00
|
|
|
}*/
|
|
|
|
if (positions[tab[i]][0]==0){
|
2022-11-28 18:34:21 +01:00
|
|
|
positions[tab[i]][0]=pos_x;
|
|
|
|
positions[tab[i]][1]=pos_y;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
positions[tab[i]][2]=pos_x;
|
|
|
|
positions[tab[i]][3]=pos_y;
|
|
|
|
}
|
2022-11-29 18:05:27 +01:00
|
|
|
/*Triche
|
2022-11-29 17:27:10 +01:00
|
|
|
snprintf(tirage,50,"Images/image%d.png",(tab[i]+1));
|
2022-11-29 18:05:27 +01:00
|
|
|
ChargerImage(tirage,pos_x,pos_y,0,0,80,80);*/
|
2022-11-29 16:35:28 +01:00
|
|
|
|
2022-11-29 18:05:27 +01:00
|
|
|
ChargerImage("Images/image0.png",pos_x,pos_y,0,0,80,80);
|
2022-11-29 17:27:10 +01:00
|
|
|
|
|
|
|
i++;
|
2022-11-24 11:38:45 +01:00
|
|
|
}
|
2022-11-29 13:26:23 +01:00
|
|
|
}
|
2022-11-29 16:35:28 +01:00
|
|
|
|
2022-11-29 21:29:46 +01:00
|
|
|
/*
|
|
|
|
for (i=0;i<19;i++){
|
|
|
|
printf("%03d", i);
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
for (j=0;j<4;j++){
|
2022-11-29 18:05:27 +01:00
|
|
|
for (i=0;i<20;i++){
|
|
|
|
printf("%03d", positions[i][j]);
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}*/
|
|
|
|
|
2022-11-29 21:29:46 +01:00
|
|
|
while(score<20){
|
|
|
|
for (repet=0;repet<3;repet++){
|
|
|
|
if (SourisCliquee()){
|
|
|
|
clic_x=_X;
|
|
|
|
clic_y=_Y;
|
2022-11-29 18:05:27 +01:00
|
|
|
|
2022-11-29 21:29:46 +01:00
|
|
|
im_x=0;
|
|
|
|
im_y=0;
|
2022-11-29 16:35:28 +01:00
|
|
|
|
2022-11-29 21:29:46 +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-11-29 18:05:27 +01:00
|
|
|
}
|
2022-11-29 16:35:28 +01:00
|
|
|
}
|
2022-11-29 21:29:46 +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-11-29 18:05:27 +01:00
|
|
|
}
|
2022-11-29 16:35:28 +01:00
|
|
|
}
|
2022-11-29 21:29:46 +01:00
|
|
|
|
|
|
|
if (im_x!=0 && im_y!=0){
|
|
|
|
for (i=0;i<20;i++){
|
|
|
|
for (j=0;j<2;j++){
|
|
|
|
if (positions[i][(j*2)]==im_x){
|
|
|
|
if (positions[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);
|
|
|
|
}
|
2022-11-29 18:05:27 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-29 16:35:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-29 21:29:46 +01:00
|
|
|
if (comparer[0]==comparer[1]){
|
2022-11-29 23:02:28 +01:00
|
|
|
score++;
|
2022-11-29 21:29:46 +01:00
|
|
|
}
|
|
|
|
if (score!=20){
|
2022-11-29 23:02:28 +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){
|
|
|
|
ChargerImage("Images/image0.png",pos_x,pos_y,0,0,80,80);
|
|
|
|
}
|
|
|
|
}
|
2022-11-29 21:29:46 +01:00
|
|
|
}
|
2022-11-29 17:27:10 +01:00
|
|
|
}
|
2022-11-28 16:55:10 +01:00
|
|
|
Touche();
|
|
|
|
FermerGraphique();
|
|
|
|
printf("\n");
|
2022-11-28 13:42:06 +01:00
|
|
|
return EXIT_SUCCESS;
|
2022-11-25 10:59:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|