Esempio n. 1
0
        /// <summary>
        ///     Clears the currently targeted prey item from the hunting form, also clears out associated shooting word used to
        ///     kill it. Finally it will clear the input buffer.
        /// </summary>
        private void ClearTarget()
        {
            // Clear the target.
            _target = null;

            // Set the shooting word back to none.
            ShootingWord = HuntWord.None;

            // Clear the input buffer.
            GameSimulationApp.Instance.InputManager.ClearBuffer();
        }
Esempio n. 2
0
        /// <summary>
        ///     Creates a prey item from another one as reference.
        /// </summary>
        /// <param name="preyItem">Prey item that should be copied.</param>
        public PreyItem(PreyItem preyItem)
        {
            // Prey specific settings for how long they live on the field.
            Lifetime = preyItem.Lifetime;
            LifetimeMax = preyItem.LifetimeMax;

            // Prey specific for total length of time they may be targeted.
            TargetTime = preyItem.TargetTime;
            TargetTimeMax = preyItem.TargetTimeMax;

            // Copy of the animal from the prey item.
            Animal = new SimItem(preyItem.Animal, 1);
        }
Esempio n. 3
0
        /// <summary>
        ///     Creates a prey item from another one as reference.
        /// </summary>
        /// <param name="preyItem">Prey item that should be copied.</param>
        public PreyItem(PreyItem preyItem)
        {
            // Prey specific settings for how long they live on the field.
            Lifetime    = preyItem.Lifetime;
            LifetimeMax = preyItem.LifetimeMax;

            // Prey specific for total length of time they may be targeted.
            TargetTime    = preyItem.TargetTime;
            TargetTimeMax = preyItem.TargetTimeMax;

            // Copy of the animal from the prey item.
            Animal = new SimItem(preyItem.Animal, 1);
        }
Esempio n. 4
0
        /// <summary>
        ///     Selects a random shooting word from the enumeration of values, if the value is not none it will select a random
        ///     animal to be used as prey from the list of prey still on the field. If there are no animals to use for prey, the
        ///     shooting word is just reset to none.
        /// </summary>
        private void TryPickPrey()
        {
            // Skip if we already have a target.
            if (_target != null)
            {
                return;
            }

            // Check if there is any prey we are currently hunting.
            if (_sortedPrey.Count <= 0)
            {
                return;
            }

            // There is a chance that you will not get prey this tick.
            if (GameSimulationApp.Instance.Random.NextBool())
            {
                return;
            }

            // Randomly select one of the hunting words from the list.
            var tempShootWord = (HuntWord)GameSimulationApp.Instance.Random.Next(_shootWords.Count);

            // Check if we are already trying to hunt a particular animal.
            if ((tempShootWord == HuntWord.None) || (tempShootWord == ShootingWord))
            {
                return;
            }

            // Set the shooting word to the one we have now verified.
            ShootingWord = tempShootWord;

            // Randomly select one of the prey from the list.
            var randomPreyIndex = GameSimulationApp.Instance.Random.Next(_sortedPrey.Count);
            var randomPrey      = _sortedPrey[randomPreyIndex];

            // Check the prey to make sure it is still alive.
            if (randomPrey.Lifetime > randomPrey.LifetimeMax)
            {
                return;
            }

            // Set the verified prey as hunting target.
            _target = new PreyItem(randomPrey);

            // Remove the old prey from the list now that it is a target.
            _sortedPrey.Remove(randomPrey);
        }
Esempio n. 5
0
 /// <summary>
 ///     Called when the currently targeted prey decides to run away from the hunter.
 /// </summary>
 /// <param name="target">Prey that sensed danger and ran away.</param>
 private void Hunt_TargetFledEvent(PreyItem target)
 {
     SetForm(typeof(PreyFlee));
 }
Esempio n. 6
0
        /// <summary>
        ///     Selects a random shooting word from the enumeration of values, if the value is not none it will select a random
        ///     animal to be used as prey from the list of prey still on the field. If there are no animals to use for prey, the
        ///     shooting word is just reset to none.
        /// </summary>
        private void TryPickPrey()
        {
            // Skip if we already have a target.
            if (_target != null)
                return;

            // Check if there is any prey we are currently hunting.
            if (_sortedPrey.Count <= 0)
                return;

            // There is a chance that you will not get prey this tick.
            if (GameSimulationApp.Instance.Random.NextBool())
                return;

            // Randomly select one of the hunting words from the list.
            var tempShootWord = (HuntWord) GameSimulationApp.Instance.Random.Next(_shootWords.Count);

            // Check if we are already trying to hunt a particular animal.
            if ((tempShootWord == HuntWord.None) || (tempShootWord == ShootingWord))
                return;

            // Set the shooting word to the one we have now verified.
            ShootingWord = tempShootWord;

            // Randomly select one of the prey from the list.
            var randomPreyIndex = GameSimulationApp.Instance.Random.Next(_sortedPrey.Count);
            var randomPrey = _sortedPrey[randomPreyIndex];

            // Check the prey to make sure it is still alive.
            if (randomPrey.Lifetime > randomPrey.LifetimeMax)
                return;

            // Set the verified prey as hunting target.
            _target = new PreyItem(randomPrey);

            // Remove the old prey from the list now that it is a target.
            _sortedPrey.Remove(randomPrey);
        }
Esempio n. 7
0
        /// <summary>
        ///     Clears the currently targeted prey item from the hunting form, also clears out associated shooting word used to
        ///     kill it. Finally it will clear the input buffer.
        /// </summary>
        private void ClearTarget()
        {
            // Clear the target.
            _target = null;

            // Set the shooting word back to none.
            ShootingWord = HuntWord.None;

            // Clear the input buffer.
            GameSimulationApp.Instance.InputManager.ClearBuffer();
        }