コード例 #1
0
        public void AddWorkers(UnitCollection units, uint amount)
        {
            if (units == null)
            {
                throw new ArgumentNullException(nameof(units));
            }

            units.Add(new UnitAmount(UnitInfo.WorkerUnitType, amount));
        }
コード例 #2
0
        public decimal GetLabourPower(UnitCollection units)
        {
            if (units == null)
            {
                throw new ArgumentNullException(nameof(units));
            }

            return(units.GetAll().Sum(u => (u.Amount * u.Unit.Workload)));
        }
コード例 #3
0
        public decimal GetMilitaryPower(UnitCollection units, MilitarySide side)
        {
            if (units == null)
            {
                throw new ArgumentNullException(nameof(units));
            }

            switch (side)
            {
            case MilitarySide.Ofense:
                return(units.GetAll().Sum(u => (u.Amount * (u.Unit.Ofense))));

            case MilitarySide.Defense:
                return(units.GetAll().Sum(u => (u.Amount * (u.Unit.Defense))));

            case MilitarySide.Both:
                return(units.GetAll().Sum(u => (u.Amount * (u.Unit.Ofense + u.Unit.Defense))));

            default:
                throw new ArgumentOutOfRangeException(nameof(side), side, null);
            }
        }
コード例 #4
0
 public void Substract(UnitCollection manySubstract)
 {
     foreach (var razedDefender in manySubstract._units)
     {
         if (this._units.ContainsKey(razedDefender.Key))
         {
             uint currentAmount = this._units[razedDefender.Key];
             if (currentAmount > razedDefender.Value)
             {
                 currentAmount -= razedDefender.Value;
             }
             else
             {
                 currentAmount = 0;
             }
             this._units[razedDefender.Key] = currentAmount;
         }
         else
         {
             this._units.Add(razedDefender.Key, 0);
         }
     }
 }