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

ModelElement.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.
    GameOfLifeState.java 1.02 KiB
    package model.automata;
    
    import javafx.scene.paint.Color;
    import model.State;
    
    import java.util.List;
    
    /**
     * {@link GameOfLifeState} instances represent the possible states of a {@link GameOfLifeState}.
     */
    public enum GameOfLifeState implements State<GameOfLifeState> {
        ALIVE, DEAD;
    
    
        @Override
        public Color getColor() {
            switch(this) {
                case ALIVE:
                    return Color.RED;
                case DEAD:
                    return Color.WHITE;
            }
            return Color.BLACK;
        }
    
        @Override
        public GameOfLifeState next() {
            if (this == GameOfLifeState.ALIVE) {
                return GameOfLifeState.DEAD;
            }
            else if (this == GameOfLifeState.DEAD) {
                return GameOfLifeState.ALIVE;
            }
    
        }
    
        @Override
        public GameOfLifeState update(List<GameOfLifeState> neighbours) {
            int count = State.count(ALIVE, neighbours);
            if (count == 3) return ALIVE ;
            if ((count == 2) && this.equals(ALIVE))return ALIVE ;
            return DEAD ;
        }
    
    }