bonjour,
voilà je rencontre un petit soucis avec mon programme, je dois remplir mon tableaux à 2 dimensions par un nombre d'objet mais je dois verifier qu'il n'y a pas déjà un objet sur cette case pour éviter les doublons mais j'ai un peu de mal : j'ai essayé ceci mais ça ne fonctionne pas ...
si quelqu'un pouvait m'aider... merci par avance !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 int x=0; int y=0; int nombreObjet=20; tabObjet = new Objets[20]; boolean verification; for(int i=0; i<nombreObjet;i++){ for(int k =0; k<tabObjet.length; k++){ verification=false; do{ y=(int)(Math.random())%7; x=(int)(Math.random())%7; if(tabObjet[k].getLigne()==x && tabObjet[k].getColonne()==y) verification=false; } i++; }while(!verification) Library.ObjetPlateau(i,x,y);
Partager