예제 #1
0
        public void Add(Egg egg)
        {
            if (egg == null)
            {
                throw new NullRefNestException(string.Format("Nest '{0}' got empty egg", GetName()));
            }

            if (_eggs.Contains(egg))
            {
                throw new ContainNestException(string.Format("Nest '{0}' already contains egg '{1}'", GetName(), egg.GetFullName()));
            }

            _eggs.Add(egg);
            egg.Knock += EggOnKnock;
            egg.SetNest(null);
            egg.SetNest(this);
        }
예제 #2
0
        public void Remove(Egg egg)
        {
            if (egg == null)
            {
                throw new NullRefNestException(string.Format("Nest {0} got empty egg", GetName()));
            }

            if (!_eggs.Contains(egg))
            {
                throw new ContainNestException(string.Format("Nest {0} does not contains egg {1}", GetName(), egg.GetFullName()));
            }

            _eggs.Remove(egg);
            egg.SetNest(null);
            egg.Knock -= EggOnKnock;
        }
예제 #3
0
        public void MoveTo(Egg egg, Nest nest)
        {
            if (egg == null)
            {
                throw new NullRefNestException(string.Format("Nest {0} got empty egg", GetName()));
            }

            if (nest == null)
            {
                throw new NullRefNestException(string.Format("Nest {0} got empty nest", GetName()));
            }

            if (!_eggs.Contains(egg))
            {
                throw new ContainNestException(string.Format("Nest {0} does not contains egg {1}", GetName(), egg.GetFullName()));
            }

            _eggs.Remove(egg);
            nest._eggs.Add(egg);
            egg.Knock -= EggOnKnock;
            egg.Knock += nest.EggOnKnock;
            egg.SetNest(nest);
        }