» codelab : http://codelab.fr/accueil » Forum : Processing : http://codelab.fr/processing » Puzzle sur Processing : http://codelab.fr/6577 Ceci est la version imprimable d'un sujet du forum, pour retourner à la version complète : Puzzle sur Processing |
Damiendu40 — 2017-04-26 16:53:11 |
Bonjour à tous ! PImage[] images = new PImage[17]; float[] X = new float[16]; float[] Y = new float[16]; int[] positionX = new int[16]; int[] positionY = new int[16]; boolean[] tableau = new boolean[16]; int compteur; void quadrillage(){ background(255); line(0, 0, 940, 0); line(0, 90, 940, 90); line(0, 180, 940, 180); line(0, 270, 940, 270); line(0, 360, 940, 360); line(0, 0, 0, 360); line(235, 0, 235, 360); line(470, 0, 470, 360); line(705, 0, 705, 360); line(940, 0, 940, 360); image(images[16],0,450); } void placer(int e){ for(int g=0;g<e;g++){ image(images[g],X[g],Y[g]); } for(int h=15;h>e;h--){ image(images[h],X[h],Y[h]); } } void setup() { compteur = 0; background(0); size(940, 700); fill(255); rect(400, 150, 150, 75); fill(0); text("Cliquez pour jouer !", 420, 180); for(int i=0;i<images.length;i++){ images[i]= loadImage("image"+i+".jpg"); } for(int y=0;y<X.length;y++){ X[y]=random(400,940); } for(int z=0;z<X.length;z++){ Y[z]=random(370,700); } for(int a=0;a<positionX.length;a++){ positionX[a]=a*235; if(positionX[a]>705 && compteur<4){ positionX[a]=(a*235)-(4*235); compteur=compteur+1; } if(positionX[a]>705 && compteur <=8){ positionX[a]=(a*235)-(8*235); compteur=compteur+1; } if(positionX[a]>705 && compteur <=12){ positionX[a]=(a*235)-(12*235); compteur=compteur+1; } } for(int b=0;b<positionY.length;b++){ if(b<=3){ positionY[b]=0; } if(b>3 && b<=7){ positionY[b]=90; } if(b>7 && b<=11){ positionY[b]=180; } if(b>11 && b<=15){ positionY[b]=270; } } } void draw() { if(mouseX<550 || mouseX>400 ){ if(mouseY<225 || mouseY>150 ){ if(mousePressed==true){ int e=0; for(int f=0;f<=15;f++){ if(!tableau[e]){ quadrillage(); placer(e); image(images[e], X[e], Y[e]); X[e]= mouseX; Y[e]= mouseY; } if(mouseX==positionX[e] && mouseY==positionY[e]){ tableau[e]= true; } if(tableau[e]){ e=e+1; } if(e==16){ background(255); } } } } } } |
Mushussu — 2017-04-27 09:51:22 |
Bonjour, |
Damiendu40 — 2017-04-27 10:17:57 |
Voilà le fichier avec tout ce qu'il faut ! |
Mushussu — 2017-04-28 03:42:52 |
Bonjour, PImage[] images = new PImage[17]; float[] X = new float[16]; float[] Y = new float[16]; int[] positionX = new int[16]; int[] positionY = new int[16]; IntList tirage; boolean[] tableau = new boolean[16]; int compteur; void quadrillage() { background(255); line(0, 0, 940, 0); line(0, 90, 940, 90); line(0, 180, 940, 180); line(0, 270, 940, 270); line(0, 360, 940, 360); line(0, 0, 0, 360); line(235, 0, 235, 360); line(470, 0, 470, 360); line(705, 0, 705, 360); line(940, 0, 940, 360); image(images[16], 0, 450); } void placer(int e) { for (int g=0; g<e; g++) { image(images[g], X[g], Y[g]); } for (int h=15; h>e; h--) { image(images[h], X[h], Y[h]); } } void setup() { compteur = 0; background(0); size(940, 700); tirage = new IntList(); for (int i = 0; i < 16; i++) { tirage.append(i); } tirage.shuffle(); println(tirage); fill(255); rect(400, 150, 150, 75); fill(0); text("Cliquez pour jouer !", 420, 180); for (int i=0; i<images.length; i++) { images[i]= loadImage("image"+i+".jpg"); } for (int y=0; y<X.length; y++) { X[y]=random(400, 940); } for (int z=0; z<X.length; z++) { Y[z]=random(370, 700); } for (int a=0; a<positionX.length; a++) { positionX[a]=a*235; if (positionX[a]>705 && compteur<4) { positionX[a]=(a*235)-(4*235); compteur=compteur+1; } if (positionX[a]>705 && compteur <=8) { positionX[a]=(a*235)-(8*235); compteur=compteur+1; } if (positionX[a]>705 && compteur <=12) { positionX[a]=(a*235)-(12*235); compteur=compteur+1; } } for (int b=0; b<positionY.length; b++) { if (b<=3) { positionY[b]=0; } if (b>3 && b<=7) { positionY[b]=90; } if (b>7 && b<=11) { positionY[b]=180; } if (b>11 && b<=15) { positionY[b]=270; } } } void draw() { if (mouseX<550 || mouseX>400 ) { if (mouseY<225 || mouseY>150 ) { if (mousePressed==true) { int e=0; for (int f=0; f<=15; f++) { int element = tirage.get(e); if (!tableau[element]) { quadrillage(); placer(element); image(images[element], X[element], Y[element]); X[element]= mouseX; Y[element]= mouseY; } if (mouseX==positionX[element] && mouseY==positionY[element]) { tableau[element]= true; } if (tableau[element]) { e=e+1; } if (e==16) { background(255); } } } } } } Remarques importantes : |
Damiendu40 — 2017-04-28 07:56:09 |
Bonjour ! |