public Planet(string newName, UserInterface thisUI, int thisNumber, Form1 thisForm) { IsSelected = false; Name = newName; _formUI = thisUI; Number = thisNumber; Form = thisForm; SelectedColony = -1; colonies = new List <Colony>(); Random random = new Random(); Radius = random.Next(MinRadius, MaxRadius); planetResources = new ResourceBox( Radius / random.Next(MinGoldCoef, MaxGoldCoef), Radius / random.Next(MinWoodCoef, MaxWoodCoef), _formUI); coordinates = new Coordinates( random.Next(-CoordinatesLimit, CoordinatesLimit), random.Next(-CoordinatesLimit, CoordinatesLimit)); _colonyCost = new ResourceBox(500, 500, _formUI); Storage = new ResourceBox(InitialGold, InitialWood, _formUI); }
protected void GetResourcesInner(ResourceBox extraction) { bool enoughResources = true; foreach (KeyValuePair <Type, Resource> currentResource in extraction.resources) { if (currentResource.Value.Amount > Planet.planetResources.resources[currentResource.Key].Amount) { enoughResources = false; } } if (enoughResources) { Planet.Storage.Earn(extraction); Planet.ExtractResources(extraction); if (Planet.IsSelected) { FormUI.ShowResources(Planet.Storage.resources); FormUI.ShowPlanetResources(Planet.planetResources.resources); } } }
public void CreateBuilding <T>(ResourceBox value) where T : Building, new() { bool enoughMoney = true; foreach (KeyValuePair <Type, Resource> currentResource in value.resources) { if (currentResource.Value.Amount > Planet.Storage.resources[currentResource.Key].Amount) { enoughMoney = false; } } if (enoughMoney) { T newBuilding = new T { Planet = Planet, Number = _buildings.Count, FormUI = _formUI }; _buildings.Add(newBuilding); Planet.Storage.Pay(value); _formUI.OnCreateBuilding(newBuilding); } }
public void Earn(ResourceBox value) { foreach (KeyValuePair <Type, Resource> currentResource in value.resources) { resources[currentResource.Key].Amount += currentResource.Value.Amount; } }
public void ExtractResources(ResourceBox value) { foreach (KeyValuePair <Type, Resource> currentResource in value.resources) { planetResources.resources[currentResource.Key].Amount -= currentResource.Value.Amount; } }
public void Pay(ResourceBox value) { foreach (KeyValuePair <Type, Resource> currentResource in value.resources) { resources[currentResource.Key].Amount -= currentResource.Value.Amount; } _formUI.ShowResources(resources); }