コード例 #1
0
        public void OnNewWatcher(Obserwator 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;
                }
            }
        }
コード例 #2
0
        public void Create()
        {
            Obserwator obs = new Obserwator(count++);

            watchers.Add(obs);
            if (watcherDelegate != null)
            {
                foreach (WatcherDelegate del in watcherDelegate.GetInvocationList())
                {
                    del(obs);
                }
            }
            obs.Subscribe(this);
        }
コード例 #3
0
 private double Distance(Obserwator watcher)
 {
     return(Math.Round(Math.Sqrt(Math.Pow((x - watcher.x), 2) + Math.Pow((y - watcher.y), 2)), 7));
 }