コード例 #1
0
        public void ResourcesToCurrencyTest(float type1, float type2, float type3, float result)
        {
            calculator = new ResourceCalculator();
            calculator.AddResource(type1, ResourceType.Food);
            calculator.AddResource(type2, ResourceType.Stone);
            calculator.AddResource(type3, ResourceType.Wood);

            float actual = calculator.CalculateResourceWorth();

            // this test contains an error
            Assert.AreEqual(result, actual);
        }
コード例 #2
0
        /// <summary>
        /// TODO move to (new) BalanceManager-class
        /// Calculates balance based on income and upkeep.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void OnDayPassed(object sender, EventArgsWithPayload <IngameTime> eventArgs)
        {
            double balance = 0;

            using (ResourceCalculator resourceCalculator = new ResourceCalculator())
            {
                foreach (ResourceFactoryController resourceFactory in FactionModel.ResourceFactories)
                {
                    resourceCalculator.AddResource(resourceFactory.ResourceValue, resourceFactory.ResourceType);
                }

                balance += resourceCalculator.CalculateResourceWorth();
            }

            balance -= FactionModel.Buildings.Sum(structure => structure.Def.UpkeepCost);
            balance -= FactionModel.Units.Sum(unit => unit.UnitModel.Def.Upkeep);

            CurrencyController.AlterCurrency((float)balance);
        }