You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

package model.cellule.créateur;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import model.CellulesVivantes;
import model.cellule.Cellule;
import java.util.LinkedList;
import java.util.List;
public class CreateurCellule implements ICreateurCellule {
private int w;
private int h;
public CreateurCellule(int w, int h) throws IllegalArgumentException{
if(w<0 || h<0){
throw new IllegalArgumentException("La longueur et la largeur doivent être supperieur à 0");
}
this.w = w;
this.h = h;
}
public ListProperty<List<Cellule>> creerCellules(CellulesVivantes observer){
return creerCellules(w, h, observer);
}
public ListProperty<List<Cellule>> creerCellules(int colone, int ligne, CellulesVivantes observer){
ObservableList<List<Cellule>> cellsInit = FXCollections.observableArrayList();
ListProperty<List<Cellule>> cells = new SimpleListProperty<>(cellsInit);
List<Cellule> tmp;
Cellule c;
for (int i = 0; i < ligne; i++) {
tmp = new LinkedList<>();
for (int j = 0; j < colone; j++) {
c = new Cellule(j, i);
c.attacher(observer);
tmp.add(c);
}
cells.add(tmp);
}
return cells;
}
public List<Cellule> creerLigneCellule(int ligne){
List<Cellule> cells = new LinkedList<>();
for(int i=0; i<ligne; ++i){
cells.add(new Cellule(i, ligne));
}
++h;
return cells;
}
}