Skip to content
Snippets Groups Projects
Select Git revision
  • ae7810dd7401020577a0619bf73881bc8e9f7a61
  • master default protected
2 results

App.java

Blame
  • Forked from COUETOUX Basile / Formula
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ViewElement.java 1.71 KiB
    package view;
    
    import javafx.scene.paint.Color;
    import model.*;
    import util.Position;
    
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.lang.reflect.Modifier;
    
    public enum ViewElement {
      FIREFIGHTER(Color.BLUE, StandardFireFighter.class),
      MOTORIZEDFIREFIGHTER(Color.DARKBLUE, MotorizedFireFighter.class),
      CLOUD(Color.GRAY, Cloud.class)  ,
      MOUNTAIN(Color.BROWN, Mountain.class),
      ROAD(Color.BLACK, Road.class),
      ROCK(Color.LIGHTYELLOW, Rock.class),
      FIRE(Color.RED,Fire.class,Fire.factory),
      EMPTY(Color.WHITE, null);
      final Color color;
      public final Class<?> c;
      final ElementFactory elementFactory;
      ViewElement(Color color, Class<?> c) {
        this.color = color;
        this.c = c;
        this.elementFactory=null;
      }
      ViewElement(Color color, Class<?> c,ElementFactory elementFactory) {
        this.color = color;
        this.c = c;
        this.elementFactory=elementFactory;
      }
      public Element instanciate(BoardData boardData,Position position){
        Element element;
          Class<?>[] arg2=new Class[]{BoardData.class,Position.class};
          Class<?>[] arg1=new Class[]{Position.class};
          if (elementFactory!=null) {
            element=elementFactory.getNewElement(boardData,position);
          }
          else {
            try {
              element=(Element)this.c.getDeclaredConstructor(arg1).newInstance(position);
            } catch (InstantiationException e) {
              throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
              throw new RuntimeException(e);
            } catch (InvocationTargetException e) {
              throw new RuntimeException(e);
            } catch (NoSuchMethodException e) {
              throw new RuntimeException(e);
            }
          }
          return element;
      }
    }