Ejemplo n.º 1
0
 /** @param event */
 @Subscribe
 public void play(final PlayEvent event) {
   _affected = _model.paint(event.paint());
   if (won()) {
     _bus.post(new GameWonEvent(_affected, _model.turns()));
     _model =
         DrenchModel.Generator.createRandomModel(
             _model.width(), _model.height(), _model.maxTurns() - 1);
     for (AI ai : _loader._ais.values()) {
       ai.initialize(this);
     }
   } else if (lost()) {
     _bus.post(new GameOverEvent(_affected));
     _model =
         DrenchModel.Generator.createRandomModel(
             _model.width(), _model.height(), _model.maxTurns());
   } else {
     _bus.post(new PlayedEvent(_affected, _model.turns()));
   }
 }
Ejemplo n.º 2
0
 public GameAILoader() {
   _finder = new ClassAIFinder();
   _classes = _finder.getAIClasses(AI.class, "ch.hesso");
   ImmutableMap.Builder<String, AI> builder = ImmutableMap.builder();
   for (Class<? extends AI> ai : _classes) {
     try {
       AI instance = ai.newInstance();
       instance.initialize(GameController.this);
       if (instance.kind().equals(PLAYER)) {
         _default = instance;
         _defaultAIName = instance.name();
       }
       builder.put(instance.name(), instance);
       initClassFields(ai, instance);
     } catch (InstantiationException | IllegalAccessException e) {
       LOG.log(Level.SEVERE, "[GameController.GameAILoader.GameAILoader]: " + e.getMessage());
     }
   }
   _ais = builder.build();
   if (_default == null && _ais.size() > 0) {
     _default = _ais.values().asList().get(0);
     _defaultAIName = _ais.keySet().asList().get(0);
   }
 }