Skip to content
Snippets Groups Projects
Select Git revision
  • b00e7660da24e0b1ec0144aa0b472d6f1bd240cb
  • main default protected
  • variant
3 results

ViewElement.java

Blame
  • Forked from COUETOUX Basile / FirefighterStarter
    15 commits ahead of the upstream repository.
    user avatar
    BACHTARZI Imed eddine authored
    added FFboardFiller to initialize the board with custom values
    b00e7660
    History
    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;
      }
    }