コード例 #1
0
ファイル: editorView.java プロジェクト: louvelg/24h2016
  public void dropObject(DragDropEvent ddEvent) {
    Map<String, String> params =
        FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
    String ligne = getParam("ligne");
    String colonne = getParam("colonne");
    String left = params.get("class");
    String[] sClass = left.split(" ");
    int colTmp = -1;
    int ligneTmp = 0;
    int item = -1;
    String idTmp = "";
    for (String s : sClass) {
      if (StringUtils.startsWith(s, "colonne_")) {
        String c = s.replace("colonne_", "");
        colTmp = Integer.valueOf(c);
      }
      if (StringUtils.startsWith(s, "ligne_")) {
        String c = s.replace("ligne_", "");
        ligneTmp = Integer.valueOf(c);
      }
      if (StringUtils.startsWith(s, "id_")) {
        idTmp = s.replace("id_", "");
      }

      if (StringUtils.startsWith(s, "position_")) {
        String c = s.replace("position_", "");
        item = Integer.valueOf(c);
      }
    }
    int x = Integer.valueOf(ligne);
    int y = Integer.valueOf(colonne);
    String id;
    if (StringUtils.isEmpty(idTmp)) {
      id = params.get("dragId");
      id = id.replaceAll("FormContent:", "");
    } else {
      id = idTmp;
      if (item != -1) pioche.remove(item);
    }
    if (colTmp == -1) {
      Cell newCell = list.get(x).get(y);
      newCell.setType(id);
      newCell.setAngle(0);
    } else {
      Cell c = list.get(ligneTmp).get(colTmp);
      Cell newCell = list.get(x).get(y);
      newCell.setType(c.getType());
      newCell.setAngle(c.getAngle());
      c.setType(Cell.CELL_EMPTY);
      c.setAngle(-1);
    }
  }
コード例 #2
0
ファイル: editorView.java プロジェクト: louvelg/24h2016
 public String getOrientation(Cell cell) {
   if (cell.getType().equals(Cell.CELL_EMPTY) || cell.getType().equals(Cell.CELL_WALL)) {
     return "";
   }
   if (cell.getType().equals(Cell.CELL_LASER_END)) {
     if (cell.getLaserV() == Cell.N) {
       return String.valueOf(Cell.S);
     }
     if (cell.getLaserV() == Cell.S) {
       return String.valueOf(Cell.N);
     }
     if (cell.getLaserH() == Cell.E) {
       return String.valueOf(Cell.W);
     }
     if (cell.getLaserH() == Cell.W) {
       return String.valueOf(Cell.E);
     }
   }
   return String.valueOf(cell.getAngle());
 }
コード例 #3
0
ファイル: editorView.java プロジェクト: louvelg/24h2016
 public void testLaser() {
   Point laserStart = null;
   Point laserEnd = null;
   int direction = 0;
   for (int i = 0; i < cells.length; i++) {
     for (int y = 0; y < cells[i].length; y++) {
       Cell c = cells[i][y];
       if (c.isLaserStart()) {
         laserStart = new Point(i, y);
         direction = c.getAngle();
       }
       if (c.isLaserEnd()) {
         laserEnd = new Point(i, y);
       }
     }
   }
   if (laserStart == null || laserEnd == null) {
     Jsf.error("Un point de depart et d'arrivee est obligatoire");
     return;
   }
   Laser l = new Laser(laserStart, laserEnd, direction);
   board.setLaser(l);
   rebuildLaser();
 }
コード例 #4
0
ファイル: editorView.java プロジェクト: louvelg/24h2016
  public String save() {
    if (StringUtils.isEmpty(levelName)) {
      Jsf.error("Le nom est obligatoire");
      return "";
    }
    if (StringUtils.isEmpty(levelName)) {
      Jsf.error("Le numéro est obligatoire");
      return "";
    }

    if (StringUtils.isEmpty(board.getBoardId())
        && boardService.findBoardByLevelName(levelName) != null) {
      Jsf.error("Un level avec ce nom existe déjà.");
      return "";
    }

    if (StringUtils.isEmpty(board.getBoardId())
        && boardService.findBoardByLevelNumber(levelNumber) != null) {
      Jsf.error("Un level avec ce numéro existe déjà.");
      return "";
    }

    Point laserStart = null;
    Point laserEnd = null;
    int direction = 0;
    for (int i = 0; i < cells.length; i++) {
      for (int y = 0; y < cells[i].length; y++) {
        Cell c = cells[i][y];
        if (c.isLaserStart()) {
          laserStart = new Point(i, y);
          direction = c.getAngle();
        }
        if (c.isLaserEnd()) {
          laserEnd = new Point(i, y);
        }
      }
    }
    if (laserStart == null || laserEnd == null) {
      Jsf.error("Un point de depart et d'arrivee est obligatoire");
      return "";
    }
    Laser l = new Laser(laserStart, laserEnd, direction);
    board.setLaser(l);
    board.setLevelName(levelName);
    board.setLevelNumber(levelNumber);
    board.setHeight(height);
    board.setWidth(width);
    for (Cell c : pioche) {
      c.setFixed(false);
    }
    board.setPioche(pioche);
    if (StringUtils.isEmpty(board.getId())) {
      boardService.createBoard(null, board);
    } else {
      boardService.updateBoard(null, board);
    }
    Jsf.info("Le niveau a été créé.");
    levelName = "";
    levelNumber = "";

    refresh();
    return "pretty:viewEditor";
  }