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.

37 lines
784 B

  1. package de.edu.hsfulda.ciip.tdd;
  2. import java.util.ArrayList;
  3. import java.util.Collection;
  4. import java.util.Collections;
  5. import java.util.List;
  6. import java.util.stream.Collector;
  7. import java.util.stream.Collectors;
  8. public class GameCell {
  9. private State state;
  10. private State nextState;
  11. private final List<GameCell> neighbors = new ArrayList<>();
  12. public GameCell(State state) {
  13. this.state = state;
  14. }
  15. public State getState() {
  16. return state;
  17. }
  18. public void calculateNextGen() {
  19. List<State> neigborStates = neighbors.stream().map(GameCell::getState).collect(Collectors.toList());
  20. nextState = state.nextBy(neigborStates);
  21. }
  22. public void activateNextGeneration() {
  23. state = nextState;
  24. }
  25. public void addNeigbour(GameCell gameCell) {
  26. neighbors.add(gameCell);
  27. }
  28. }