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); } }
private void LoadGameObject(IMapObject o) { IGameEntityFactory gameFactory = (IGameEntityFactory)EntityFactory; var goldValue = 0; if (o.Properties.ContainsKey("goldValue")) { goldValue = int.Parse(o.Properties["goldValue"]); } switch (o.Name.ToLower()) { case "army": switch (int.Parse(o.Properties["type"])) { case 0: gameFactory.CreateArcher(new Vector2(o.X, o.Y), int.Parse(o.Properties["owner"]), goldValue); break; case 1: gameFactory.CreateKnight(new Vector2(o.X, o.Y), int.Parse(o.Properties["owner"]), goldValue); break; case 2: gameFactory.CreateCatapult(new Vector2(o.X, o.Y), int.Parse(o.Properties["owner"]), goldValue); break; default: break; } break; case "tower": gameFactory.CreateTower(new Vector2(o.X, o.Y), int.Parse(o.Properties["owner"]), goldValue); break; case "fortress": gameFactory.CreateFortress(new Vector2(o.X, o.Y), int.Parse(o.Properties["owner"]), goldValue); break; case "spawnpoint": gameFactory.CreateSpawnpoint(new Vector2(o.X, o.Y), int.Parse(o.Properties["owner"])); break; default: break; } }