public MapView(Game game) : base(game) { PlayerList players = ((XnaUITestGame)game).Model.GetScenario().GetGameWorld().GetPlayerList(); foreach (PlayerComponent player in players.GetChildren()) { UnitList unitList = player.GetUnitList(); unitList.UnitAddedEvent += onUnitAdded; unitList.UnitRemovedEvent += onUnitRemoved; ZRTSCompositeViewUIFactory factory = ZRTSCompositeViewUIFactory.Instance; foreach (UnitComponent unit in unitList.GetChildren()) { UnitUI unitUI = factory.BuildUnitUI(unit); unitUI.DrawBox = new Rectangle((int)(unit.PointLocation.X * cellDimension), (int)(unit.PointLocation.Y * cellDimension), unitUI.DrawBox.Width, unitUI.DrawBox.Height); AddChild(unitUI); componentToUI.Add(unit, unitUI); unit.MovedEventHandlers += updateLocationOfUnit; unit.HPChangedEventHandlers += killUnit; } BuildingList buildingList = player.BuildingList; foreach (Building b in buildingList.GetChildren()) { BuildingUI buildingUI = factory.BuildBuildingUI(b); buildingUI.DrawBox = new Rectangle((int)b.PointLocation.X * cellDimension, (int)b.PointLocation.Y * cellDimension, buildingUI.DrawBox.Width, buildingUI.DrawBox.Height); AddChild(buildingUI); } buildingList.BuildingAddedEventHandlers += this.onBuildingAdded; } leftButtonStrategy = new DrawSelectionBoxStrategy(this); OnClick += moveSelectedUnits; }
/// <summary> /// Trigger funciton in the event of a new building being added /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void onBuildingAdded(Object sender, BuildingAddedEventArgs e) { ZRTSCompositeViewUIFactory factory = ZRTSCompositeViewUIFactory.Instance; BuildingUI buildingUI = factory.BuildBuildingUI(e.Building); buildingUI.DrawBox = new Rectangle((int)e.Building.PointLocation.X * cellDimension, (int)e.Building.PointLocation.Y * cellDimension, buildingUI.DrawBox.Width, buildingUI.DrawBox.Height); AddChild(buildingUI); }
/// <summary> /// Trigger fucntion in the event of new unit being added /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void onUnitAdded(object sender, UnitAddedEventArgs e) { ZRTSCompositeViewUIFactory factory = ZRTSCompositeViewUIFactory.Instance; UnitUI unitUI = factory.BuildUnitUI(e.Unit); unitUI.DrawBox = new Rectangle((int)(e.Unit.PointLocation.X * cellDimension), (int)(e.Unit.PointLocation.Y * cellDimension), unitUI.DrawBox.Width, unitUI.DrawBox.Height); AddChild(unitUI); componentToUI.Add(e.Unit, unitUI); e.Unit.MovedEventHandlers += updateLocationOfUnit; e.Unit.HPChangedEventHandlers += killUnit; }
/// <summary> /// Load information from the map file /// </summary> /// <param name="filename"></param> protected void LoadModelFromFile(string filename) { // Create or load the model. model = new GameModel(); ZRTSCompositeViewUIFactory.Initialize(this); FileStream mapFile = File.OpenRead(filename); //tryit.map ScenarioXMLReader reader = new ScenarioXMLReader(mapFile); ScenarioComponent scenario = reader.GenerateScenarioFromXML(); model.AddChild(scenario); model.PlayerInContext = (PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[0]; //model.PlayerInContext.EnemyList.Add((PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[1]); foreach (PlayerComponent p in scenario.GetGameWorld().GetPlayerList().GetChildren()) { foreach (PlayerComponent po in scenario.GetGameWorld().GetPlayerList().GetChildren()) { if (p != po) { p.EnemyList.Add(po); } } } Console.WriteLine(ZRTSModel.Factories.BuildingFactory.Instance.getBuildingTypes()[0]); // Create the controller, Remove the old one if it exists. if (this.controller != null) { Components.Remove(this.controller); } controller = new ZRTSController(this); Components.Add(controller); // Set the mouse visible this.IsMouseVisible = true; PlayerComponent player = model.PlayerInContext; foreach (PlayerComponent enemy in player.EnemyList) { WinWhenAllEnemyUnitsDead win = new WinWhenAllEnemyUnitsDead(enemy, scenario); scenario.triggers.Add(win); } LoseWhenAllPlayersUnitsAreDead lose = new LoseWhenAllPlayersUnitsAreDead(player, scenario); scenario.triggers.Add(lose); }
public override void Visit(Building building) { ZRTSCompositeViewUIFactory factory = ZRTSCompositeViewUIFactory.Instance; ui = factory.BuildSelectedEntityUI(building); }
public override void Visit(UnitComponent unit) { ZRTSCompositeViewUIFactory factory = ZRTSCompositeViewUIFactory.Instance; ui = factory.BuildSelectedEntityUI(unit); }