Example #1
0
        internal void Execute()
        {
            int mileseconds = Randomize.GetValue(Config.foodMinTimeChangeState, Config.foodMaxTimeChangeState);

            Thread.Sleep(mileseconds);

            switch (currentState)
            {
            case FoodState.Good:
                ChangeState(FoodState.Medium);
                actuator.TriggerChangeFood();
                break;

            case FoodState.Medium:
                ChangeState(FoodState.Rotten);
                actuator.TriggerChangeFood();
                break;

            case FoodState.Rotten:
                places[position].Food = null;
                actuator.TriggerChangeFood();
                Destroy();
                break;
            }
        }
Example #2
0
        internal void Execute()
        {
            int timeToNextCat = Randomize.GetValue(Config.catMinTimeToNextCat, Config.catMaxTimeToNextCat);

            Thread.Sleep(timeToNextCat);

            actuator.TriggerShowCat(true);

            Thread.Sleep(Config.catShowingDelay);

            actuator.TriggerShowCat(false);
        }
        private bool ShouldThereBeANewPigeon()
        {
            if (quantityOfPigeons >= Config.environmentMaxNumberOfPigeons)
                return false;

            currentRandomPosition = Randomize.GetValue(0, Config.environmentSize - 1);

            if (places[currentRandomPosition].Pigeon == null)
                return true;

            return false;
        }
        private void ChoseDirection()
        {
            int indexLeftRight = Randomize.GetValue(0, 100);

            if (indexLeftRight % 2 == 0)
            {
                SetDirectionLeft();
            }
            else
            {
                SetDirectionRight();
            }
        }
        public Pigeon(List <Place> places, int currentPosition)
        {
            index         = Randomize.GetValue(1, 9);
            maxTimeWiting = Randomize.GetValue(Config.pigeonMinTimesWaiting, Config.pigeonMaxTimesWaiting);

            ChoseDirection();

            pigeonAction = PigeonAction.Waiting;

            actuator = new PigeonActuator();
            sensor   = new PigeonSensor(this);

            this.places          = places;
            this.currentPosition = currentPosition;

            thread = new Thread(new ThreadStart(Loop));
            thread.Start();
        }
        /// <summary>
        /// This method is triggered when the cat appears.
        /// The pigeon must wake up or disperse to a random position.
        /// </summary>
        internal void WakeUpOrChangePosition()
        {
            if (pigeonAction == PigeonAction.Sleeping)
            {
                SetWakeUp();
                return;
            }

            int newPosition = Randomize.GetValue(0, Config.environmentSize - 1);

            if (!places[newPosition].isClean())
            {
                return;
            }

            SetDirection(newPosition);

            ExecuteWalk(newPosition);
        }