Пример #1
0
  /**
   * handles objects, so deletes them if they should be deleted, all changes are made recursively
   *
   * @param objects the objects which should be handled
   * @return the rest of the objects which shouldn't be deleted
   */
  public ArrayList<SpaceObject> handleObjects(ArrayList<SpaceObject> objects) {
    if (objects.size() <= 0) return objects;

    SpaceObject thisObject = objects.get(0);
    ArrayList<SpaceObject> remainingObjects = getRestOfList(objects);
    ArrayList<SpaceObject> thisOverlappingObjects = thisObject.overlapingObjects(objects);

    if (thisObject.shouldBeDeletedIfOverlaps(thisOverlappingObjects)) {

      for (SpaceObject overlappingObject :
          thisObject.shouldBeBothDeletedIfOverlaps(thisOverlappingObjects)) {
        this.score += overlappingObject.getPoints();
        remainingObjects.remove(overlappingObject);
      }

      this.score += thisObject.getPoints();
      return handleObjects(remainingObjects);

    } else if (thisObject.shouldBeDeletedAsItCrashsWithWall(this.resolution)) {
      return handleObjects(remainingObjects);
    } else {
      remainingObjects = handleObjects(remainingObjects);
      remainingObjects.add(thisObject);
      return remainingObjects;
    }
  }
Пример #2
0
  /**
   * returns the points which can be earned if all asteroids were shot down
   *
   * @return the points which can be earned if all asteroids were shot down
   */
  public int getTotalPoints() {
    int totalPoints = 0;

    for (SpaceObject object : this.objects) {
      totalPoints += object.getPoints();
    }

    return totalPoints;
  }