private bool CheckRessourcesAvailability(UnitCost cost)
        {
            Ressources ressources = Ressources.Instance;

            if (ressources.WoodQty >= cost.Wood &&
                ressources.StoneQty >= cost.Stone &&
                ressources.IronQty >= cost.Iron &&
                ressources.FoodQty >= cost.Food &&
                ressources.GoldQty >= cost.Gold)
            {
                ressources.WoodQty  -= (cost.Wood > 0) ? cost.Wood : 0;
                ressources.StoneQty -= (cost.Stone > 0) ? cost.Stone : 0;
                ressources.IronQty  -= (cost.Iron > 0) ? cost.Iron : 0;
                ressources.FoodQty  -= (cost.Food > 0) ? cost.Food : 0;
                ressources.GoldQty  -= (cost.Gold > 0) ? cost.Gold : 0;
                return(true);
            }
            return(false);
        }
Пример #2
0
 public KnightUnit()
 {
     UnitStats = new UnitStats()
     {
         Attack            = 90,
         InfanteryDefence  = 40,
         CavaleryDefence   = 30,
         MagicDefence      = 20,
         ArtillerieDefence = 40,
         Space             = 2,
         FoodUsage         = 25,
         Speed             = 10,
         AttackStructure   = 90
     };
     UnitCost = new UnitCost()
     {
         Iron = 250,
         Gold = 100
     };
     ImagePath  = "pack://application:,,,/Resources/Images/Units/units_knight.png";
     Name       = "Knight";
     UnitType   = UnitType.Cavalery;
     UnitEntity = UnitEntity.Knight;
 }
Пример #3
0
 public GuardianUnit()
 {
     UnitStats = new UnitStats()
     {
         Attack            = 10,
         InfanteryDefence  = 30,
         CavaleryDefence   = 50,
         MagicDefence      = 20,
         ArtillerieDefence = 15,
         Space             = 1,
         FoodUsage         = 3,
         Speed             = 20,
         AttackStructure   = 10
     };
     UnitCost = new UnitCost()
     {
         Iron = 140,
         Gold = 40
     };
     ImagePath  = "pack://application:,,,/Resources/Images/Units/units_guardian.png";
     Name       = "Guardian";
     UnitType   = UnitType.Infantery;
     UnitEntity = UnitEntity.Guardian;
 }
Пример #4
0
 public GuardianUnit()
 {
     UnitStats = new UnitStats()
     {
         Attack = 10,
         InfanteryDefence = 30,
         CavaleryDefence = 50,
         MagicDefence = 20,
         ArtillerieDefence = 15,
         Space = 1,
         FoodUsage = 3,
         Speed = 20,
         AttackStructure = 10
     };
     UnitCost = new UnitCost()
     {
         Iron = 140,
         Gold = 40
     };
     ImagePath = "pack://application:,,,/Resources/Images/Units/units_guardian.png";
     Name = "Guardian";
     UnitType = UnitType.Infantery;
     UnitEntity = UnitEntity.Guardian;
 }
Пример #5
0
 public KnightUnit()
 {
     UnitStats = new UnitStats()
     {
         Attack = 90,
         InfanteryDefence = 40,
         CavaleryDefence = 30,
         MagicDefence = 20,
         ArtillerieDefence = 40,
         Space = 2,
         FoodUsage = 25,
         Speed = 10,
         AttackStructure = 90
     };
     UnitCost = new UnitCost()
     {
         Iron = 250,
         Gold = 100
     };
     ImagePath = "pack://application:,,,/Resources/Images/Units/units_knight.png";
     Name = "Knight";
     UnitType = UnitType.Cavalery;
     UnitEntity = UnitEntity.Knight;
 }
        /// <summary>
        /// Update visual for cost of recruiting current selected units
        /// </summary>
        private void UpdateTotalTroupsCost()
        {
            totalUnitCost = new UnitCost();
            var totalSpaceNeeded = 0;
            _canRecruit = true;

            var remaining = UnitManager.Instance.TotalUnits;
            var unitCounts = UnitManager.Instance.UnitsAvailables;

            // Get remaining units to recruit
            remaining = unitCounts.Aggregate(remaining, (current, unitCount) => current - unitCount.Value);

            foreach (var recruitment in _recruitmentCount)
            {
                var unit = UnitManager.Instance.Units[recruitment.Key];
                var unitCost = unit.GetUnitCost();
                var count = recruitment.Value;

                totalUnitCost.Gold += unitCost.Gold*count;
                totalUnitCost.Iron += unitCost.Iron*count;
                totalUnitCost.Wood += unitCost.Wood*count;

                totalSpaceNeeded += unit.GetUnitStats().Space*count;
            }

            var mainWindow = MainWindow.MIns;
            if (mainWindow == null)
                return;

            var totalRessources = Ressources.Instance;
            var redbrush = new SolidColorBrush(Colors.Red);
            var defaultBrush = (SolidColorBrush)(new BrushConverter().ConvertFrom("#443025"));

            mainWindow.total_wood_recruitment.Content = totalUnitCost.Wood;
            mainWindow.total_wood_recruitment.Foreground = defaultBrush;
            if (totalUnitCost.Wood > totalRessources.WoodQty)
            {
                _canRecruit = false;
                mainWindow.total_wood_recruitment.Foreground = redbrush;
            }

            mainWindow.total_iron_recruitment.Content = totalUnitCost.Iron;
            mainWindow.total_iron_recruitment.Foreground = defaultBrush;
            if (totalUnitCost.Iron > totalRessources.IronQty)
            {
                _canRecruit = false;
                mainWindow.total_iron_recruitment.Foreground = redbrush;
            }

            mainWindow.total_gold_recruitment.Content = totalUnitCost.Gold;
            mainWindow.total_gold_recruitment.Foreground = defaultBrush;
            if (totalUnitCost.Gold > totalRessources.GoldQty)
            {
                _canRecruit = false;
                mainWindow.total_gold_recruitment.Foreground = redbrush;
            }

            mainWindow.total_space_recruitment.Content = totalSpaceNeeded + "/" + remaining;
            mainWindow.total_space_recruitment.Foreground = defaultBrush;
            if (totalSpaceNeeded > remaining)
            {
                _canRecruit = false;
                mainWindow.total_space_recruitment.Foreground = redbrush;
            }
        }
        private bool CheckRessourcesAvailability(UnitCost cost)
        {
            Ressources ressources = Ressources.Instance;

            if (ressources.WoodQty >= cost.Wood &&
                ressources.StoneQty >= cost.Stone &&
                ressources.IronQty >= cost.Iron &&
                ressources.FoodQty >= cost.Food &&
                ressources.GoldQty >= cost.Gold)
            {
                ressources.WoodQty -= (cost.Wood > 0) ? cost.Wood : 0;
                ressources.StoneQty -= (cost.Stone > 0) ? cost.Stone : 0;
                ressources.IronQty -= (cost.Iron > 0) ? cost.Iron : 0;
                ressources.FoodQty -= (cost.Food > 0) ? cost.Food : 0;
                ressources.GoldQty -= (cost.Gold > 0) ? cost.Gold : 0;
                return true;
            }
            return false;
        }
        /// <summary>
        /// Update visual for cost of recruiting current selected units
        /// </summary>
        private void UpdateTotalTroupsCost()
        {
            totalUnitCost = new UnitCost();
            var totalSpaceNeeded = 0;

            _canRecruit = true;

            var remaining  = UnitManager.Instance.TotalUnits;
            var unitCounts = UnitManager.Instance.UnitsAvailables;

            // Get remaining units to recruit
            remaining = unitCounts.Aggregate(remaining, (current, unitCount) => current - unitCount.Value);

            foreach (var recruitment in _recruitmentCount)
            {
                var unit     = UnitManager.Instance.Units[recruitment.Key];
                var unitCost = unit.GetUnitCost();
                var count    = recruitment.Value;

                totalUnitCost.Gold += unitCost.Gold * count;
                totalUnitCost.Iron += unitCost.Iron * count;
                totalUnitCost.Wood += unitCost.Wood * count;

                totalSpaceNeeded += unit.GetUnitStats().Space *count;
            }

            var mainWindow = MainWindow.MIns;

            if (mainWindow == null)
            {
                return;
            }

            var totalRessources = Ressources.Instance;
            var redbrush        = new SolidColorBrush(Colors.Red);
            var defaultBrush    = (SolidColorBrush)(new BrushConverter().ConvertFrom("#443025"));

            mainWindow.total_wood_recruitment.Content    = totalUnitCost.Wood;
            mainWindow.total_wood_recruitment.Foreground = defaultBrush;
            if (totalUnitCost.Wood > totalRessources.WoodQty)
            {
                _canRecruit = false;
                mainWindow.total_wood_recruitment.Foreground = redbrush;
            }

            mainWindow.total_iron_recruitment.Content    = totalUnitCost.Iron;
            mainWindow.total_iron_recruitment.Foreground = defaultBrush;
            if (totalUnitCost.Iron > totalRessources.IronQty)
            {
                _canRecruit = false;
                mainWindow.total_iron_recruitment.Foreground = redbrush;
            }

            mainWindow.total_gold_recruitment.Content    = totalUnitCost.Gold;
            mainWindow.total_gold_recruitment.Foreground = defaultBrush;
            if (totalUnitCost.Gold > totalRessources.GoldQty)
            {
                _canRecruit = false;
                mainWindow.total_gold_recruitment.Foreground = redbrush;
            }

            mainWindow.total_space_recruitment.Content    = totalSpaceNeeded + "/" + remaining;
            mainWindow.total_space_recruitment.Foreground = defaultBrush;
            if (totalSpaceNeeded > remaining)
            {
                _canRecruit = false;
                mainWindow.total_space_recruitment.Foreground = redbrush;
            }
        }