示例#1
0
  private void loadMap() {
    char ch;
    CellBuilder cb = new CellBuilder();
    String mapLine;
    Loader.loadMap();

    while ((mapLine = Loader.loadLine()) != null) {

      cols = mapLine.length();

      for (int i = 0; i < cols; i++) {

        Cell nextCell = cb.nextCell();
        cells.add(nextCell);
        nextCell.draw();

        if ((ch = mapLine.charAt(i)) != '_') {
          if (ch == 'r') {
            if (robotPosition != null) {
              System.out.println("You may only create one robot. A robot was discarded");
            } else {
              robotPosition = new Position(i % cols, rows, this);
            }
          } else {

            try {
              GameObject obj =
                  new ObjectBuilder().setPos(nextCell.getPos()).setType(ch).createObject();
              nextCell.addObject(obj);
            } catch (Exception e) {
              System.out.println("No object found for this symbol -> " + ch + ". Discarded");
            }
          }
        }
        nextCell.drawObjects();
      }

      cb.nextRow();
      rows++;
    }
  }
示例#2
0
  public Cell getCell(Position pos) {

    int i = cols * pos.getRow() + pos.getCol();
    return cells.get(i);
  }