Beispiel #1
0
  /** Refreshes knowledge of nearby terrain */
  public void findWater() {
    ArrayList<Point> waterList = new ArrayList<Point>();
    water = null;
    final Point location = summative.getLocation(this);
    assert (location != null);

    for (int x = -sight; x <= sight; x++) {
      for (int y = -sight; y <= sight; y++) {
        if (Math.abs(x) + Math.abs(y) <= sight) {
          if (summative.terrainGet(new Point(location.x + x, location.y + y))
              == Summative.TERRAIN.SEA) {
            waterList.add(new Point(location.x + x, location.y + y));
          }
        }
      }
    }
    if (waterList.size() > 0) {
      water = waterList.get(0);
      for (Point p : waterList) {
        if (Math.abs(p.x - location.x) + Math.abs(p.y - location.y)
            < Math.abs(water.x - location.x) + Math.abs(water.y - location.y)) {
          water = p;
        }
      }
    }
  }
Beispiel #2
0
 /** Diseases itself */
 public void disease() {
   if (summative.rand.nextInt(100) < virulence) {
     diseased = true;
     Point location = summative.getLocation(this);
     summative.addToLog(
         getName() + " at " + location.x + "," + location.y + " caught Jay's Plague.");
   }
 }
Beispiel #3
0
 /** Refreshes to store all the nearby lifeforms */
 public void findNearbyLife() {
   nearbyLife = new ArrayList<Lifeform>();
   final Point location = summative.getLocation(this);
   assert (location != null);
   for (int x = -sight; x <= sight; x++) {
     for (int y = -sight; y <= sight; y++) {
       if (Math.abs(x) + Math.abs(y) <= sight) {
         if (summative.lifeGet(new Point(location.x + x, location.y + y)) != null) {
           nearbyLife.add(summative.lifeGet(new Point(location.x + x, location.y + y)));
         } else if (summative.grassGet(new Point(location.x + x, location.y + y)) != null) {
           nearbyLife.add(summative.grassGet(new Point(location.x + x, location.y + y)));
         }
       }
     }
   }
 }
Beispiel #4
0
  /**
   * Finds all empty nearby spaces
   *
   * @return a point that is adjacent and empty
   */
  public Point nearEmpty() {
    Point temp;
    ArrayList<Point> available = new ArrayList<Point>();
    final Point location = summative.getLocation(this);
    assert (location != null);

    for (int x = -1; x <= 1; x++) {
      for (int y = -1; y <= 1; y++) {
        temp = new Point(location.x + x, location.y + y);
        if (summative.emptyAt(temp) && (summative.terrainGet(temp)) == TERRAIN.LAND) {
          available.add(temp);
        }
      }
    }
    if (available.size() > 0) {
      return available.get((int) (Math.random() * available.size()));
    } else {
      return null;
    }
  }
Beispiel #5
0
 /** Returns the location */
 public Point getLocation() {
   return summative.getLocation(this);
 }
Beispiel #6
0
 /**
  * Sets the location of the lifeform
  *
  * @param p
  */
 public void setLocation(Point p) {
   summative.moveTo(this, p);
 }