Beispiel #1
0
 public void OnNewWatcher(Watcher watcher)
 {
     if (friends.Contains(watcher))
     {
         return;
     }
     if (friends.Count == 0)
     {
         friends.Add(watcher);
     }
     else if (friends.Count == 1)
     {
         double distance = Distance(watcher);
         if (distance < Distance(friends[0]))
         {
             friends.Add(watcher);
             friends[1] = friends[0];
             friends[0] = watcher;
         }
         else
         {
             friends.Add(watcher);
         }
     }
     else
     {
         double distance1 = Distance(friends[0]);
         double distance2 = Distance(friends[1]);
         double distance  = Distance(watcher);
         if (distance > distance2)
         {
             return;
         }
         if (distance < distance2 && distance > distance1)
         {
             friends[1] = watcher;
         }
         else
         {
             friends[1] = friends[0];
             friends[0] = watcher;
         }
     }
 }
Beispiel #2
0
 private double Distance(Watcher watcher)
 {
     return(Math.Round(Math.Sqrt(Math.Pow((x - watcher.x), 2) + Math.Pow((y - watcher.y), 2)), 7));
 }