Skip to content
Snippets Groups Projects
Select Git revision
  • 64119975937c9bc2e4908edb7a06389c091ee248
  • main default protected
  • variant
3 results

Board.java

Blame
  • Forked from COUETOUX Basile / FirefighterStarter
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Cell.java 1.56 KiB
    package model;
    
    import javafx.beans.property.Property;
    import javafx.beans.property.SimpleObjectProperty;
    
    /**
     * {@link Cell} instances represent the cells of <i>The Game of Life</i>.
     */
    
    public class Cell {
        private final Property<CellState> stateProperty = new SimpleObjectProperty<>(CellState.DEAD);
    
        /**
         * Determines whether this {@link Cell} is alive or not.
         *
         * @return {@code true} if this {@link Cell} is alive and {@code false} otherwise
         */
    
        public boolean isAlive() {
            return getState().isAlive;
        }
    
        /**
         * Sets the state of this {@link Cell}.
         *
         * @param cellState the new state of this {@link Cell}
         */
    
        public void setState(CellState cellState) {
            getStateProperty().setValue(cellState);
        }
    
        /**
         * Returns the current state of this {@link Cell}.
         *
         * @return the current state of this {@link Cell}
         */
    
        public CellState getState(){
            return getStateProperty().getValue();
        }
    
        /**
         * Change the state of this {@link Cell} from ALIVE to DEAD or from DEAD to ALIVE.
         */
    
        public void toggleState() {
            CellState[] possibleStates = CellState.values();
            int stateOrdinal = getState().ordinal();
            int numberOfPossibleStates = possibleStates.length;
            setState(possibleStates[(stateOrdinal+1)%numberOfPossibleStates]);
        }
    
        /**
         * Returns this {@link Cell}'s state property.
         *
         * @return this {@link Cell}'s state property.
         */
        public Property<CellState> getStateProperty() {
            return stateProperty;
        }
    
    }