package model.cellule; import javafx.beans.property.*; import javafx.scene.paint.Color; import javafx.scene.paint.Paint; import model.cellule.observer.ObservableCellule; /** * */ public class Cellule extends ObservableCellule { private Position position; private BooleanProperty alive; private static ObjectProperty livingColor = new SimpleObjectProperty<>(); public Color getLivingColor() { return livingColor.get(); } public void setLivingColor(Color color) { livingColor.set(color); } public static ObjectProperty livingColorProperty() { return livingColor; } private ObjectProperty activeColor = new SimpleObjectProperty<>(); public Paint getActiveColor() { return activeColor.get(); } public void setActiveColor(Color color) { activeColor.set(color); } public Property activeColorProperty() { return activeColor; } private Color deathColor; /** * * @param x position x de la cellule * @param y position y de la cellule * @throws IllegalArgumentException */ public Cellule(int x, int y) throws IllegalArgumentException { deathColor = Color.BLACK; activeColorProperty().setValue(deathColor); position = new Position(x,y); alive = new SimpleBooleanProperty(false); } /** * * @return état de la cellule (vivante ou morte) */ public Boolean isAlive() { return alive.get(); } /** * * @return */ public ReadOnlyBooleanProperty aliveProperty() { return alive; } /** * * @param alive */ public void setAlive(Boolean alive) { setActiveColor(alive ? (Color) getLivingColor() : deathColor); this.alive.set(alive); notifier(this); } public Position getPosition(){ return position; } /** * * @param o * @return */ @Override public boolean equals(Object o) { if (o == null) return false; if (o == this) return true; if (o.getClass() != this.getClass()) return false; if (position.getY() == ((Cellule) o).position.getY() && position.getX() == ((Cellule) o).position.getX() && isAlive() == ((Cellule) o).isAlive()) { return true; } return false; } public void inverseAlive(){ setAlive(!alive.get()); } }