Пример #1
0
 /**
  * Atualiza o componente view (representado pela classe GameBoard), possivelmente como uma
  * resposta a uma atualizacao do jogo.
  */
 public boolean update(int[][] fModel) {
   boolean existe_celula = false;
   for (int i = 0; i < engine.getHeight(); i++) {
     for (int j = 0; j < engine.getWidth(); j++) {
       if (engine.isCellAlive(i, j)) {
         fModel[i][j] = 1;
         existe_celula = true;
       } else fModel[i][j] = 0;
     }
   }
   return existe_celula;
 }
Пример #2
0
  public void setStrategy(int option) {
    // Injecao de dependencia utilizando Spring Framework para as regras do jogo
    ApplicationContext context = new ClassPathXmlApplicationContext("gameOfLife.xml");
    StrategyConway = (EstrategiaDeDerivacao) context.getBean("conway");

    StrategyHighlife = (EstrategiaDeDerivacao) context.getBean("highLife");

    StrategyLive = (EstrategiaDeDerivacao) context.getBean("liveFreeOrDie");

    this.option = option;
    switch (option) {
      case CONWAY:
        engine.setEstrategia(StrategyConway);
        break;
      case HIGH_LIFE:
        engine.setEstrategia(StrategyHighlife);
        break;
      case LIVE_FREE_OR_DIE:
        engine.setEstrategia(StrategyLive);
        break;
    }
  }
Пример #3
0
 private boolean validPosition(int i, int j) {
   System.out.println(i);
   System.out.println(j);
   return i >= 0 && i < engine.getHeight() && j >= 0 && j < engine.getWidth();
 }