44 lines
855 B
Java
44 lines
855 B
Java
package structure;
|
|
// cedric.gueguen@irisa.fr
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.Random;
|
|
|
|
|
|
public class Grid {
|
|
|
|
private ArrayList<ArrayList<Integer>> m_grid=new ArrayList<>();
|
|
|
|
public Grid(int size_x, int size_y, int max_rand){
|
|
this.generateGrid(size_x,size_y, max_rand);
|
|
}
|
|
|
|
|
|
|
|
|
|
private void generateGrid(int size_x, int size_y, int max_rand){
|
|
for(int x=0;x<size_x;x++){
|
|
m_grid.add(new ArrayList<Integer>());
|
|
for(int y=0;y<size_y;y++){
|
|
m_grid.get(x).add( (int) (Math.random() * max_rand ));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void displayGrid(){
|
|
Iterator<ArrayList<Integer>> i=m_grid.iterator();
|
|
|
|
while(i.hasNext()){
|
|
ArrayList<Integer> current=i.next();
|
|
Iterator<Integer> j=current.iterator();
|
|
|
|
while(j.hasNext()){
|
|
System.out.print(j.next() + " ");
|
|
}
|
|
System.out.println();
|
|
}
|
|
}
|
|
|
|
}
|