private void CreateBuyButton(Vector2 position, string texture, ArmyPrice armyPrice) { IGameEntityFactory factory = (IGameEntityFactory)Parent.Scene.EntityFactory; IMapService mapService = Parent.Scene.ServiceProvider.GetService <IMapService>(); var buyButton = factory.CreateBuyButton(position, new Vector2(mapService.Width * 0.085f), texture, () => BuyArmy(armyPrice)); buyButton.AddChild(factory.CreateIngot(buyButton.Position - new Vector2(mapService.Width * 0.02f, mapService.Height * -0.1f), new Vector2(mapService.Width * 0.035f))); buyButton.AddChild(factory.CreateTextDisplay(buyButton.Position - new Vector2(mapService.Width * -0.01f, mapService.Height * -0.1f), new Vector2(mapService.Width * 0.035f), (int)armyPrice + string.Empty, Color.Black)); buyButtons.Add(buyButton); }
public void BuyArmy(ArmyPrice armyPrice) { if (Parent.GetComponent <OwnerComponent>().Owner == 0) { Parent.GetComponent <SelectComponent>().Selected = true; } int owner = Parent.GetComponent <OwnerComponent>().Owner; IGoldService goldService = Parent.Scene.ServiceProvider.GetService <IGoldService>(); int gold = goldService.GetGold(owner); if (gold < (int)armyPrice) { return; } goldService.RemoveGold(owner, (int)armyPrice); IGameEntityFactory factory = (IGameEntityFactory)Parent.Scene.EntityFactory; IEntity entity = null; switch (armyPrice) { case ArmyPrice.Archer: if (Parent.GetComponent <OwnerComponent>().Owner == 0) { Parent.Scene.ServiceProvider.GetService <IAudioService>().PlaySound("intro"); } entity = factory.CreateArcher(Parent.Position, owner, 0); break; case ArmyPrice.Knight: if (Parent.GetComponent <OwnerComponent>().Owner == 0) { Parent.Scene.ServiceProvider.GetService <IAudioService>().PlaySound("intro"); } entity = factory.CreateKnight(Parent.Position, owner, 0); break; case ArmyPrice.Catapult: if (Parent.GetComponent <OwnerComponent>().Owner == 0) { Parent.Scene.ServiceProvider.GetService <IAudioService>().PlaySound("intro"); } entity = factory.CreateCatapult(Parent.Position, owner, 0); break; } if (entity != null) { new MoveRandomComponent(entity); } }