Exemplo n.º 1
0
  public List<MapObserver> getNeighborsCloseTo(MapObserver observer, float max) {
    List<MapObserver> ret = new ArrayList<MapObserver>();

    Location aLoc = observer.getLocation();
    float ax = aLoc.x;
    float ay = aLoc.y;

    Location bLoc;
    float deltaX, deltaY;
    double dist;

    for (Block b : notificationArea) {
      synchronized (b.observers) {
        for (MapObserver o : b.observers) {
          if (observer == o) {
            continue; // Skip himself.
          }

          bLoc = o.getLocation();
          deltaX = bLoc.x - ax;
          deltaY = bLoc.y - ay;
          dist = Math.sqrt(deltaX * deltaX + deltaY * deltaY);

          if (dist < max) {
            ret.add(o);
          }
        }
      }
    }

    return ret;
  }
Exemplo n.º 2
0
 public void notifyAppearanceChangeSelfAndNeigh(MapObserver observer) {
   for (Block b : notificationArea) {
     synchronized (b.observers) {
       for (MapObserver o : b.observers) {
         o.notifyAppearanceChange(observer);
       }
     }
   }
 }
Exemplo n.º 3
0
 public void notifyNearChatSelfAndNeigh(MapObserver observer, String text) {
   for (Block b : notificationArea) {
     synchronized (b.observers) {
       for (MapObserver o : b.observers) {
         o.notifyNearChat(observer, text);
       }
     }
   }
 }
Exemplo n.º 4
0
 public void notifyMoveSelfAndNeigh(MapObserver observer) {
   for (Block b : notificationArea) {
     synchronized (b.observers) {
       for (MapObserver o : b.observers) {
         if (observer != o) {
           o.notifyMove(observer);
         }
       }
     }
   }
 }
Exemplo n.º 5
0
 public void makeAwareOfOthers(MapObserver observer) {
   for (Block b : notificationArea) {
     synchronized (b.observers) {
       for (MapObserver o : b.observers) {
         if (observer != o) {
           observer.notifyMove(o); // Brackets all the way down. :)
         }
       }
     }
   }
 }
Exemplo n.º 6
0
 public void notifySelfAboutOthers(MapObserver observer) {
   // TODO: optimize this: send notif only about the cells not in range previously.
   for (Block b : notificationArea) {
     synchronized (b.observers) {
       for (MapObserver o : b.observers) {
         if (observer != o) {
           observer.notifyMove(o);
         }
       }
     }
   }
 }