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.

86 lines
2.3 KiB

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<Color> livingColor = new SimpleObjectProperty<>();
public Color getLivingColor() { return livingColor.get(); }
public void setLivingColor(Color color) { livingColor.set(color); }
public static ObjectProperty<Color> livingColorProperty() { return livingColor; }
private ObjectProperty<Paint> activeColor = new SimpleObjectProperty<>();
public Paint getActiveColor() { return activeColor.get(); }
public void setActiveColor(Color color) { activeColor.set(color); }
public Property<Paint> 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());
}
}