Skip to content
Snippets Groups Projects
Select Git revision
  • 6a4221ab87822872a7792717c06491941e0e19b3
  • main default protected
  • master
3 results

ByteGrayColorTest.java

Blame
  • 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 ;
        }
    
    }