Esempio n. 1
0
 public StatePatternExample(
     IGun gun,
     IAmmunitionContainer ammunitionContainer)
 {
     _gun = gun;
     _ammunitionContainer = ammunitionContainer;
 }
 public StatePatternExample(
     IGun gun,
     IAmmunitionContainer ammunitionContainer)
 {
     _gun = gun;
     _ammunitionContainer = ammunitionContainer;
 }
Esempio n. 3
0
 /// <summary>
 /// Specific Constructor
 /// </summary>
 /// <param name="weaponCondition">The condition of the weapon.</param>
 /// <param name="meleeCommand">Command for melee attacks with weapon.</param>
 /// <param name="shootCommand">The rate of shoot attacks allowed with the weapon.</param>
 /// <param name="emptyGunFireCommand">Command for when attempting to shoot with empty weapon.</param>
 /// <param name="ammunitionContainer">Container to hold ammunition for the weapon.</param>
 protected Gun(
     IWeaponCondition weaponCondition,
     ICommand meleeCommand,
     ICommand shootCommand,
     ICommand emptyGunFireCommand,
     IAmmunitionContainer ammunitionContainer) :
     base(
         weaponCondition,
         meleeCommand)
 {
     ShootCommand        = shootCommand;
     EmptyGunFireCommand = emptyGunFireCommand;
     AmmunitionContainer = ammunitionContainer;
     LastShot            = DateTime.MinValue;
 }
Esempio n. 4
0
 /// <summary>
 /// Specific Constructor
 /// </summary>
 /// <param name="weaponCondition">The condition of the weapon.</param>
 /// <param name="meleeCommand">Command for melee attacks with weapon.</param>
 /// <param name="shootCommand">The rate of shoot attacks allowed with the weapon.</param>
 /// <param name="emptyGunFireCommand">Command for when attempting to shoot with empty weapon.</param>
 /// <param name="ammunitionContainer">Container to hold ammunition for the weapon.</param>
 /// <param name="isBurstFireEngaged">If burst fire is currently engaged on the weapon.</param>
 public M16(
     IWeaponCondition weaponCondition,
     ICommand meleeCommand,
     ICommand shootCommand,
     ICommand emptyGunFireCommand,
     IAmmunitionContainer ammunitionContainer,
     bool isBurstFireEngaged)
     : base(weaponCondition,
             meleeCommand,
             shootCommand,
             emptyGunFireCommand,
             ammunitionContainer)
 {
     IsBurstFireEngaged = isBurstFireEngaged;
 }
Esempio n. 5
0
 /// <summary>
 /// Specific Constructor
 /// </summary>
 /// <param name="weaponCondition">The condition of the weapon.</param>
 /// <param name="meleeCommand">Command for melee attacks with weapon.</param>
 /// <param name="shootCommand">The rate of shoot attacks allowed with the weapon.</param>
 /// <param name="emptyGunFireCommand">Command for when attempting to shoot with empty weapon.</param>
 /// <param name="ammunitionContainer">Container to hold ammunition for the weapon.</param>
 /// <param name="isBurstFireEngaged">If burst fire is currently engaged on the weapon.</param>
 public M16(
     IWeaponCondition weaponCondition,
     ICommand meleeCommand,
     ICommand shootCommand,
     ICommand emptyGunFireCommand,
     IAmmunitionContainer ammunitionContainer,
     bool isBurstFireEngaged) :
     base(
         weaponCondition,
         meleeCommand,
         shootCommand,
         emptyGunFireCommand,
         ammunitionContainer)
 {
     IsBurstFireEngaged = isBurstFireEngaged;
 }
Esempio n. 6
0
        /// <summary>
        /// The method to call to reload the weapon.
        /// </summary>
        /// <param name="container">The ammunition container to pass in to fill the weopons magazine, etc.</param>
        /// <returns></returns>
        public override bool Reload(IAmmunitionContainer container)
        {
            lock (this)
            {
                if (!CurrentWeaponConditionState.CanBeUsed)
                {
                    return(false);
                }

                lock (container)
                {
                    var ammunitionCount = Math.Min(container.AmmunitionCount, AmmunitionContainer.MaxiumAmmunitionCount - AmmunitionContainer.AmmunitionCount);
                    if (ammunitionCount == 0)
                    {
                        return(false); // No need to reload, already full, or container has no ammunition to give.
                    }
                    // In game engine, would play animation of trading out ammunition magazine or single bullet in bolt action rifle.
                    container.AmmunitionCount           -= ammunitionCount;
                    AmmunitionContainer.AmmunitionCount += ammunitionCount;
                    return(true);
                }
            }
        }
Esempio n. 7
0
 /// <summary>
 /// The method to call to reload the weapon.
 /// </summary>
 /// <param name="container">The ammunition container to pass in to fill the weopons magazine, etc.</param>
 /// <returns></returns>
 public abstract bool Reload(IAmmunitionContainer container);
Esempio n. 8
0
        /// <summary>
        /// The method to call to reload the weapon.
        /// </summary>
        /// <param name="container">The ammunition container to pass in to fill the weopons magazine, etc.</param>
        /// <returns></returns>
        public override bool Reload(IAmmunitionContainer container)
        {
            lock (this)
            {
                if (!CurrentWeaponConditionState.CanBeUsed)
                    return false;

                lock (container)
                {
                    var ammunitionCount = Math.Min(container.AmmunitionCount, AmmunitionContainer.MaxiumAmmunitionCount - AmmunitionContainer.AmmunitionCount);
                    if (ammunitionCount == 0)
                        return false; // No need to reload, already full, or container has no ammunition to give.

                    // In game engine, would play animation of trading out ammunition magazine or single bullet in bolt action rifle.
                    container.AmmunitionCount -= ammunitionCount;
                    AmmunitionContainer.AmmunitionCount += ammunitionCount;
                    return true;
                }
            }
        }