Esempio n. 1
0
        /* isp ActivateFormation()
         *
         * Input variables:
         * battleFormation =
         * battleFormationType =
         *
         * State variables:
         *
         *
         */
        public void ActivateFormation(BattleFormation battleFormation, BattleFormationType battleFormationType)
        {
            if (battleFormation is null)
            {
                throw new ArgumentNullException(nameof(BattleFormation));
            }
            if (battleFormation.GeneralInCharge == null)
            {
                var article = battleFormationType == BattleFormationType.Offensive ? "an" : "a";
                throw new InvalidOperationException($"A general must be assigned in charge of {battleFormation.Name} formation in your '{Name}' planet to activate it as {article} {battleFormationType.ToString().ToLower()} formation");
            }
            var formation = Formations.SingleOrDefault(f => f.Equals(battleFormation));

            if (formation == null)
            {
                throw new ArgumentException("Formation does not exist");
            }
            if (battleFormationType == BattleFormationType.Offensive)
            {
                battleFormation.SetStatus(true);
                ActiveOffensiveFormation = battleFormation;
            }

            if (battleFormationType == BattleFormationType.Defensive)
            {
                battleFormation.SetStatus(true);
                ActiveDefensiveFormation = battleFormation;
            }
        }
Esempio n. 2
0
 /* isp ExistsFormation()
  *
  * Input variables:
  * battleFormation =
  *
  * State variables:
  *
  *
  */
 public bool ExistsFormation(BattleFormation battleFormation)
 {
     if (battleFormation is null)
     {
         throw new ArgumentNullException(nameof(BattleFormation));
     }
     return(Formations?.SingleOrDefault(f => f.Equals(battleFormation)) != null);
 }
Esempio n. 3
0
        /* isp UpdateFormation()
         *
         * Input variables:
         * battleFormation =
         * newFormation =
         *
         * State variables:
         *
         *
         */
        public void UpdateFormation(BattleFormation battleFormation, BattleFormation newFormation)
        {
            if (battleFormation is null)
            {
                throw new ArgumentNullException(nameof(battleFormation), "Invalid source formation");
            }
            if (newFormation is null)
            {
                throw new ArgumentNullException(nameof(battleFormation), "Invalid new formation");
            }
            var existingFormation = Formations?.SingleOrDefault(f => f.Equals(battleFormation));

            if (existingFormation != null)
            {
                existingFormation = newFormation;
            }
        }