Example #1
0
        /// <summary>
        /// update the status of the object.
        /// in Read mode.
        /// <see cref="IBoardFunctions.GetNearObjects(int, int)"/>
        /// </summary>
        private void UpdateStatus()
        {
            if (DeBuff == DeBuff.Cocoon)
            {
                if (numberOfDaysCocooned < 2)
                {
                    numberOfDaysCocooned++;
                }
                else
                {
                    numberOfDaysCocooned = 0;
                    DeBuff = DeBuff.UnAffected;
                }
            }

            var objectsNear = BoardFunctions.GetNearObjects(X, Y, 1);

            // count is the number of objects around the given object.
            int count = objectsNear.Count;


            /// if the count is not in the boundries given by the <see cref="Info"/> class,
            /// the object's state will become <see cref="State.Depressed"/>.
            if ((count < info.MinObjectsPerArea || count > info.MaxObjectsPerArea) && State == State.Alive)
            {
                ProducerConsumer.Produce(String.Format("Object number {0} became depressed!", Id));
                SetState(State.Depressed);
            }
        }
Example #2
0
        protected override void ActDepressedObject()
        {
            var objects = BoardFunctions.GetNearObjects(X, Y, 1);

            foreach (var obj in objects)
            {
                if (obj.DeBuff == DeBuff.Cocoon)
                {
                    Fight(obj);
                    SetState(State.Alive);
                    break;
                }
            }
        }
Example #3
0
        protected override void ActDepressedObject()
        {
            var dynamicObjects = BoardFunctions.GetNearObjects(X, Y, 1);

            /// if the number of adjacent objects are in the range of [info.MinObjectsPerArea,info.MaxObjectsPerArea]
            /// than the given object will no longer be depressed.
            if (dynamicObjects.Count >= info.MinObjectsPerArea && dynamicObjects.Count <= info.MaxObjectsPerArea)
            {
                ProducerConsumer.Produce(String.Format("Object number {0} is no longer depressed, found {1} objects near it", Id, dynamicObjects.Count));
                SetState(State.Alive);
            }
            else
            {
                ProducerConsumer.Produce(String.Format("Object number {0} is still depressed, found {1} objects near it", Id, dynamicObjects.Count));
            }
        }
Example #4
0
        /// <summary>
        /// Try to fight another object
        /// </summary>
        public virtual void TryToFight()
        {
            ProducerConsumer.Produce(String.Format("Object number {0} is looking for a fight!", Id));

            // get all objects near the given object
            var dynamicObjects = BoardFunctions.GetNearObjects(X, Y, Agility);

            if (dynamicObjects.Count == 0)
            {
                ProducerConsumer.Produce(String.Format("Object number {0} found no one around him to fight", Id));
                return;
            }

            // fight a random object
            int index = MyRandom.Next(0, dynamicObjects.Count);

            Fight(dynamicObjects[index]);
        }