SAE11_2021/images.c

63 lines
989 B
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
#include <graph.h>
#include <time.h>
#include "images.h"
2022-11-21 16:10:01 +01:00
2022-11-28 16:58:39 +01:00
int tirage_aleatoire(void){
2022-11-28 16:55:10 +01:00
InitialiserGraphique();
2022-11-21 16:19:18 +01:00
ChoisirEcran(0);
2022-11-28 16:55:10 +01:00
CreerFenetre(0,0,1024,576);
char tirage[50];
2022-11-28 13:42:06 +01:00
int pos_x, pos_y;
2022-11-28 16:55:10 +01:00
int i, j;
2022-11-28 13:42:06 +01:00
int nb;
int tab[40];
2022-11-28 16:55:10 +01:00
int nb_paires;
2022-11-28 16:55:10 +01:00
printf("Combien de paires ? --> ");
scanf("%d", &nb_paires);
ChargerImage("Images/background.png",0,0,0,0,1024,576);
for (i=0;i<40;i++){
tab[i]=0;
}
2022-11-21 16:19:18 +01:00
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++){
for (j=0;j<nb_paires+1;j++){
nb=rand()%(nb_paires*2);
if (tab[nb]!=0){
j--;
}
else{
tab[nb]=j;
2022-11-28 13:42:06 +01:00
}
}
}
/*Tirage des images*/
2022-11-28 16:55:10 +01:00
srand(time(NULL));
i=0;
for (pos_y=10;pos_y<380;pos_y=pos_y+90){
2022-11-28 13:42:06 +01:00
for (pos_x=10;pos_x<650;pos_x=pos_x+90){
2022-11-28 16:55:10 +01:00
if (tab[i]==0){
pos_y=1000;
}
snprintf(tirage,50,"Images/image%d.png",tab[i]);
ChargerImage(tirage,pos_x,pos_y,0,0,80,80);
2022-11-28 16:55:10 +01:00
i++;
}
2022-11-28 16:55: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
}