Example #1
0
  private void countJars() {

    for (Cell c : cells) {
      c.resetObjIterator();

      while (c.objectIterator().hasNext()) {
        if (c.objectIterator().next() instanceof Jar) {
          jarCounter++;
        }
      }
    }
  }
Example #2
0
  public boolean allJarsOnMarks() {

    int jars = 0;
    GameObject obj;

    for (Cell c : cells) {
      c.resetObjIterator();

      while (c.objectIterator().hasNext()) {
        if ((obj = c.objectIterator().next()) instanceof Mark) {
          jars += ((Mark) obj).getJarCounter();
        }
      }
    }

    if (jars >= jarCounter) {
      return true;
    }
    return false;
  }
Example #3
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++;
    }
  }