Beispiel #1
0
        /// <summary>
        ///     Инициализирует экземпляр класса звездной системы
        /// </summary>
        /// <param name="name"></param>
        /// <param name="systemStars"></param>
        /// <param name="planets"></param>
        public StarSystem(string name, IList <Star> stars, IList <Planet> planets)
        {
            this.Name        = name ?? throw new ArgumentNullException(nameof(name));
            this.systemStars = new List <Star>(stars) ?? throw new ArgumentNullException(nameof(stars));

            if (planets.Count > 255)
            {
                throw new ArgumentOutOfRangeException(nameof(planets), "Count can't be greater than 255");
            }

            this.systemPlanets = new List <Planet>(planets) ?? throw new ArgumentNullException(nameof(planets));

            this.Buildings = new SystemBuildings();

            this.systemMiners = new MinerFleet();

            foreach (var planet in this.SystemPlanets)
            {
                planet.PropertyChanged += this.Planet_PropertyChanged;
            }

            this.SetSystemPopulation();

            this.ColonizedCount = this.SetColonizedPlantes();

            SetMiners();
            this.SystemResources = new StarSystemResourceGenerator().GenerateResources();
        }
Beispiel #2
0
        public static void SustainPopulationNeeds(long population, IMutableResources from)
        {
            if (from == null)
            {
                throw new ArgumentNullException(nameof(from));
            }

            if (population <= 0)
            {
                return;
            }

            IBasicResources neededResources = CalculatePopulationNeeds(population);

            if (from.CanSubtract(neededResources))
            {
                from.Subtract(neededResources);
                PreviousTurnUsedResources = neededResources;
            }
            else
            {
                PreviousTurnUsedResources = new ReadOnlyResources(from);
                from.SetToZero();
            }
        }
Beispiel #3
0
        public void NextTurn(IMutableResources resources)
        {
            if (inConstruction.Count <= 0)
            {
                return;
            }

            foreach (var building in inConstruction.ToArray())
            {
                building.OneTurnProgress(resources);
            }
        }
Beispiel #4
0
        public void OneTurnProgress(IMutableResources resources)
        {
            if (resources.CanSubtract(this.CostPerTurn) && this.BuildingProgress < BuildingDuration)
            {
                resources.Subtract(this.CostPerTurn);
                this.BuildingProgress++;
            }

            if (this.BuildingProgress == BuildingDuration)
            {
                this.OnCompleted();
            }
        }
Beispiel #5
0
        public void OneTurnProgress(IMutableResources from)
        {
            if (from == null)
            {
                throw new ArgumentNullException(nameof(from));
            }

            if (from.CanSubtract(this.CostPerTurn))
            {
                from.Subtract(this.CostPerTurn);
                this.ResearchProgress++;
            }

            if (this.ResearchProgress == this.ResearchDuration)
            {
                OnResearchCompleted();
            }
        }
Beispiel #6
0
        public void Mine(IMutableResources from, IMutableResources to)
        {
            IMutableResources extracted = new Resources(OneMinerExtractsPerTurn);

            extracted.Multiply(this.MinersCount);

            if (from.IsEqual(Resources.Zero))
            {
                return;
            }

            if (from.CanSubtract(extracted))
            {
                from.Subtract(extracted);
                to.Add(extracted);
            }
            else
            {
                to.Add(from);
                from.SetToZero();
            }
        }
Beispiel #7
0
 public Stockpile(double money, IMutableResources playerResources)
 {
     this.Money           = money;
     this.PlayerResources = playerResources ?? throw new ArgumentNullException(nameof(playerResources));
 }
Beispiel #8
0
 public Stockpile()
 {
     this.Money           = 111_222_333_444;
     this.PlayerResources = new Resources(0, 0, 0);
 }
 public StockpileChangedEventArgs(double money, IMutableResources argResources)
 {
     this.money        = money;
     this.argResources = argResources ?? throw new ArgumentNullException(nameof(argResources));
 }
Beispiel #10
0
 public ShipsFactory(IMutableResources resources)
 {
     storage = resources;
 }