Skip to content
Snippets Groups Projects
Select Git revision
  • 5bc396d540113d8fdf5c4769f30f4a0d0ade3759
  • main default protected
2 results

Rotation.java

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ViewElement.java 1.62 KiB
    package view;
    
    import javafx.scene.paint.Color;
    import model.*;
    import util.Position;
    
    import java.lang.reflect.InvocationTargetException;
    
    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),
      FOREST(Color.GREEN, Forest.class),
      FIRE(Color.RED,Fire.class,Fire.factory),
      ROCK(Color.DARKGOLDENROD, Rock.class),
    
      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<?>[] 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;
      }
    }