From 914e6b115585770ee0ee31de2a0236ea3efc2eca Mon Sep 17 00:00:00 2001 From: proal Date: Fri, 25 Nov 2022 10:59:42 +0100 Subject: [PATCH] =?UTF-8?q?tirage=20al=C3=A9atoire=20r=C3=A9ussi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- images.c | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/images.c b/images.c index 8f08f55..0ec3cc0 100644 --- a/images.c +++ b/images.c @@ -5,38 +5,43 @@ #include "images.h" +int aleatoire(int pos_x, int pos_y){ + int nb; + int position[20][4]; + nb=rand()%20; + if (position[nb][0]<10){ + position[nb][0]=pos_x; + position[nb][1]=pos_y; + return nb; + } + else if (position[nb][2]<10){ + position[nb][2]=pos_x; + position[nb][3]=pos_y; + return nb; + } + else{ + aleatoire(pos_x, pos_y); + } +} + void main(void){ InitialiserGraphique(); ChoisirEcran(0); CreerFenetre(0,0,1024,576); - int images_dispo[20]; - int nb_tire; - int boucle; + int boucle, boucle2; char tirage[50]; int tire; int pos_x; int pos_y; + int position[20][4]; ChargerImage("Images/background.png",0,0,0,0,1024,576); - /*Remplissage du tableau*/ - for(boucle=0;boucle<20;boucle++){ - images_dispo[boucle]=2; - } - - /*Tirage de la première image*/ + /*Tirage des images*/ + srand(time(NULL)); for (pos_y=10;pos_y<380;pos_y=pos_y+90){ - for (pos_x=10;pos_x<650;pos_x=pos_x+90){ - srand(time(NULL)); - nb_tire=rand()%20; - while (images_dispo[nb_tire]==0){ - printf("oui"); - srand(time(NULL)); - nb_tire=rand()%20; - } - images_dispo[nb_tire]--; - - tire=nb_tire+1; + for (pos_x=10;pos_x<650;pos_x=pos_x+90){ + tire=aleatoire(pos_x, pos_y, position)+1; snprintf(tirage,50,"Images/image%d.png",tire); ChargerImage(tirage,pos_x,pos_y,0,0,80,80); } @@ -44,4 +49,7 @@ void main(void){ Touche(); FermerGraphique(); -} \ No newline at end of file +} + + +