Ejemplo n.º 1
0
 public void refresh() {
   String boardId = getParam("editorId");
   if (StringUtils.isEmpty(boardId)) {
     board = BoardFactory.createEmptyBoard(Integer.parseInt(height), Integer.parseInt(width));
     pioche = new ArrayList<Cell>();
   } else {
     board = boardService.findBoardById(getUser(), getParam("editorId"));
     pioche = board.getPioche();
     levelName = board.getLevelName();
     levelNumber = board.getLevelNumber();
     height = board.getHeight();
     width = board.getWidth();
   }
   cells = board.getCells();
   list = new ArrayList<List<Cell>>();
   for (Cell[] cells2 : cells) {
     List<Cell> l1 = new ArrayList<Cell>();
     for (int i = 0; i < cells2.length; i++) {
       l1.add(cells2[i]);
     }
     list.add(l1);
   }
 }
Ejemplo n.º 2
0
  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";
  }