Exemplo n.º 1
0
  public void obtainBoard() throws IOException {

    boolean dimensionFlag = false;
    boolean nameFlag = false;
    boolean playerFlag = false;
    String line;

    while ((line = inputBoard.readLine()) != null) {

      line = line.replace(" ", "").replace("\t", "").replace("\n", "").split("#")[0];

      if (!line.isEmpty()) {
        if (!dimensionFlag) {
          parseDimension(line);
          dimensionFlag = true;
        } else if (!nameFlag) {
          parseBoardName(line);
          nameFlag = true;
        } else {
          if (line.startsWith("1")) {
            if (playerFlag == true) {
              throw new CorruptedFileException();
            }
            parsePlayer(line);
            playerFlag = true;
          } else {
            BoardLine cell = new BoardLine(line, boardDimension);
            Point point = (new Point(cell.getData(1), cell.getData(2))).add(new Point(1, 1));

            if (cell.isWallLine()) {
              parseWall(point, cell);
            } else if (cell.isMonsterLine()) {
              parseMonster(point, cell);
            } else if (cell.isBonusLine()) {
              parseBonus(point, cell);
            }
          }
        }
      }
    }

    if (!nameFlag || !playerFlag || !dimensionFlag) {
      throw new CorruptedFileException();
    }
    validation();
  }
Exemplo n.º 2
0
 public void parsePlayer(String line) {
   BoardLine cell = new BoardLine(line, boardDimension);
   Point point = (new Point(cell.getData(1), cell.getData(2))).add(new Point(1, 1));
   playerPosition = point;
 }
Exemplo n.º 3
0
 public void parseBonus(Point point, BoardLine cell) {
   putCell(point.x, point.y, new Bonus(point, cell.getData(0), cell.getData(5)));
 }
Exemplo n.º 4
0
 public void parseMonster(Point point, BoardLine cell) {
   putCell(point.x, point.y, new Monster(point, cell.getData(3), cell.getData(4)));
 }