public LoseWhenAllPlayersUnitsAreDead(PlayerComponent player, ScenarioComponent scenario) { condition = new ConditionAllPlayerUnitsDead(this,player); this.scenario = scenario; action = new PlayerLoseAction(this, scenario); }
private void ChangeScenario(object sender, EventArgs e) { if (sender is MapEditorFullModel) // sanity check { context = ((MapEditorFullModel)sender).GetScenario(); } }
public void Visit(ScenarioComponent scenario) { if (ScenarioVisitor != null) { scenario.Accept(ScenarioVisitor); } }
public void createNewScenario() { /******************** // TODO Extract this logic with loadscenario. if (model.scenario != null) { // TODO: Ask if the user wants to discard the current scenario. } model.scenario = new ZRTSModel.Scenario.Scenario(20, 20); // Since this is a new scenario, it has not been saved and does not have a filename model.filename = null; model.saved = false; //The model has changed, so notify all views of the change. model.notifyAll(); *************/ if (improvedModel.GetScenario() != null) { // TODO: Ask if the user wants to discard the current scenario or save it. } ScenarioComponent scenario = new ScenarioComponent(20, 20); // TODO: Update SaveInfo model to change filename and UpToDate flag. // Automatically discards old scenario, by overloaded AddChild function. improvedModel.AddChild(scenario); }
public void Init(MapEditorController controller, MapEditorFullModel model) { this.controller = controller; context = model.GetScenario(); model.ScenarioChangedEvent += this.ChangeScenario; }
/// <summary> /// Called when the scenario has changed. Unregisters the map view with all pieces of model it was associated with, and registers with /// the new scenario. /// </summary> /// <param name="scenario"></param> public void SetScenario(ScenarioComponent scenario) { context = scenario; // Empty the view. this.mapPanel.Hide(); foreach (Control c in mapPanel.Controls) { c.AllowDrop = false; if (c is TileUI) ((TileUI)c).UnregisterFromEvents(); } mapPanel.Controls.Clear(); realizedComponents.Clear(); this.mapPanel.Show(); if (scenario != null) { ZRTSModel.Map map = scenario.GetGameWorld().GetMap(); this.mapPanel.Size = new System.Drawing.Size(map.GetWidth() * PIXELS_PER_COORDINATE, map.GetHeight() * PIXELS_PER_COORDINATE); // Location of the map panel int xLoc, yLoc; if (this.mapPanel.Size.Width > this.Size.Width) { xLoc = 0; } else { // Place the panel in the center. xLoc = (this.Size.Width - this.mapPanel.Size.Width) / 2; } if (this.mapPanel.Size.Height > this.Size.Height) { yLoc = 0; } else { // Place the panel in the center. yLoc = (this.Size.Height - this.mapPanel.Size.Height) / 2; } this.mapPanel.Location = new System.Drawing.Point(xLoc, yLoc); this.RealizeView(); if (scenario.GetGameWorld().GetPlayerList() != null) { scenario.GetGameWorld().GetPlayerList().PlayerAddedEvent += this.PlayerAdded; scenario.GetGameWorld().GetPlayerList().PlayerRemovedEvent += this.PlayerRemoved; foreach (PlayerComponent p in scenario.GetGameWorld().GetPlayerList().GetChildren()) { p.BuildingList.BuildingAddedEventHandlers += this.BuildingAdded; p.BuildingList.BuildingRemovedEventHandlers += this.BuildingRemoved; } } } }
public override void Visit(MapEditorFullModel model) { scenario = model.GetScenario(); if (scenario != prevScenario) { scenarioChanged = true; } base.Visit(model); }
public void SetScenario(ScenarioComponent scenario) { if (gameworld != null) { gameworld.UnregisterObserver(this); } context = scenario; if (scenario != null) { gameworld = scenario.GetGameWorld(); if (gameworld != null) { gameworld.RegisterObserver(this); } } }
/// <summary> /// Creates a CreateNewScenario dialog and uses it to determine the name and size of the new scenario. Then, generates a /// new scenario of the appropriate size. /// </summary> public void createNewScenario() { if (model.GetScenario() != null) { model.GetScenario().RemoveChild(model.GetScenario().GetGameWorld()); // TODO: Ask if the user wants to discard the current scenario or save it. } CreateNewScenarioDialog dialog = new CreateNewScenarioDialog(); dialog.ShowDialog(); if (dialog.ExitWithCreate) { // Create a scenario with a map of the appropriate size ScenarioComponent scenario = new ScenarioComponent(dialog.ScenarioWidth, dialog.ScenarioHeight); // Add grass cells at each cell. ZRTSModel.Map map = scenario.GetGameWorld().GetMap(); for (int i = 0; i < map.GetWidth(); i++) { for (int j = 0; j < map.GetHeight(); j++) { CellComponent cell = new CellComponent(); cell.AddChild(new Grass()); cell.X = i; cell.Y = j; map.AddChild(cell); } } // TODO: Update SaveInfo model to change filename and UpToDate flag. // Automatically discards old scenario, by overloaded AddChild function. model.AddChild(scenario); // Empty the command queue model.GetCommandStack().EmptyStacks(); // We may have just destroyed a large scenario, so collect that garbage. // Commented out - only used for testing purposes. The C# garbage collector takes a LONG time to be activated if this call is not made, // but if the call is made, it disrupts UI. // GC.Collect(); } }
private void setupModel() { model = new GameModel(); ScenarioComponent scenario = new ScenarioComponent(20, 20); // 20 x 20 Gameworld. // Add grass cells at each cell. ZRTSModel.Map map = scenario.GetGameWorld().GetMap(); for (int i = 0; i < map.GetWidth(); i++) { for (int j = 0; j < map.GetHeight(); j++) { CellComponent cell = new CellComponent(); cell.AddChild(new Sand()); cell.X = i; cell.Y = j; map.AddChild(cell); } } model.AddChild(scenario); //Create two players and set them to be enemies. model.GetScenario().GetGameWorld().GetPlayerList().AddChild(new PlayerComponent()); model.GetScenario().GetGameWorld().GetPlayerList().AddChild(new PlayerComponent()); PlayerComponent player1 = (PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[0]; PlayerComponent player2 = (PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[1]; player1.EnemyList.Add(player2); player2.EnemyList.Add(player1); }
public PlayerWinAction(Trigger decorated, ScenarioComponent scenario) : base(decorated) { this.scenario = scenario; }
public virtual void Visit(ScenarioComponent scenario) { Visit((ModelComponent)scenario); }
/// <summary> /// Loading game scenario object for process /// </summary> /// <param name="scene"></param> public void LoadScenario(ScenarioComponent scene) { // Need not to load this scenario into View // Basically just return a command corresponding to the clicked icon // i.e. click at attack icon, will return attack command and then process the game logic in the gameloop inside ZRTS update(); this.scenario = scene; }
public ScenarioComponent GenerateScenarioFromXML() { ScenarioComponent scenario = null; if (reader.Read()) { // Go to the Scenario (skip the XML line) reader.Read(); scenario = new ScenarioComponent(); ModelComponent currentComponent = scenario; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.Name) { case "Gameworld": Gameworld gameworld = new Gameworld(); currentComponent.AddChild(gameworld); if (!reader.IsEmptyElement) { currentComponent = gameworld; } break; case "Map": int width = Int32.Parse(reader.GetAttribute("Width")); int height = Int32.Parse(reader.GetAttribute("Height")); Map map = new Map(width, height); currentComponent.AddChild(map); if (!reader.IsEmptyElement) { currentComponent = map; } break; case "Cell": int x = Int32.Parse(reader.GetAttribute("X")); int y = Int32.Parse(reader.GetAttribute("Y")); CellComponent cell = new CellComponent(); cell.X = x; cell.Y = y; currentComponent.AddChild(cell); if (!reader.IsEmptyElement) { currentComponent = cell; } break; case "PlayerList": PlayerList playerList = new PlayerList(); currentComponent.AddChild(playerList); if (!reader.IsEmptyElement) { currentComponent = playerList; } break; case "Player": PlayerComponent player = new PlayerComponent(); player.Name = reader.GetAttribute("Name"); player.Race = reader.GetAttribute("Race"); player.Gold = Int32.Parse(reader.GetAttribute("Gold")); player.Metal = Int32.Parse(reader.GetAttribute("Metal")); player.Wood = Int32.Parse(reader.GetAttribute("Wood")); currentComponent.AddChild(player); if (!reader.IsEmptyElement) { currentComponent = player; } break; case "BuildingList": if (!reader.IsEmptyElement) { currentComponent = ((PlayerComponent)currentComponent).BuildingList; } break; case "UnitList": if (!reader.IsEmptyElement) { currentComponent = ((PlayerComponent)currentComponent).GetUnitList(); } break; case "Sand": Sand sand = new Sand(); currentComponent.AddChild(sand); if (!reader.IsEmptyElement) { currentComponent = sand; } break; case "Mountain": Mountain mountain = new Mountain(); currentComponent.AddChild(mountain); if (!reader.IsEmptyElement) { currentComponent = mountain; } break; case "Grass": Grass grass = new Grass(); currentComponent.AddChild(grass); if (!reader.IsEmptyElement) { currentComponent = grass; } break; case "Unit": UnitComponent unit = new UnitComponent(); currentComponent.AddChild(unit); float unitX = float.Parse(reader.GetAttribute("X")); float unitY = float.Parse(reader.GetAttribute("Y")); unit.PointLocation = new PointF(unitX, unitY); unit.Type = reader.GetAttribute("Type"); unit.MaxHealth = short.Parse(reader.GetAttribute("MaxHealth")); unit.CurrentHealth = short.Parse(reader.GetAttribute("CurrentHealth")); unit.CanHarvest = bool.Parse(reader.GetAttribute("CanHarvest")); unit.CanAttack = bool.Parse(reader.GetAttribute("CanAttack")); unit.Attack = short.Parse(reader.GetAttribute("Attack")); unit.AttackRange = float.Parse(reader.GetAttribute("AttackRange")); unit.AttackTicks = byte.Parse(reader.GetAttribute("AttackTicks")); unit.CanBuild = bool.Parse(reader.GetAttribute("CanBuild")); unit.BuildSpeed = byte.Parse(reader.GetAttribute("BuildSpeed")); unit.Speed = float.Parse(reader.GetAttribute("Speed")); /* * Type="zombie" CanAttack="True" * Attack="20" AttackRange="4" AttackTicks="10" * BuildSpeed="30" CanBuild="True" CanHarvest="False" * CurrentHealth="100" MaxHealth="100" X="12" Y="13" * Speed="0.1" */ if (!reader.IsEmptyElement) { currentComponent = unit; } break; case "Building": Building building = new Building(); currentComponent.AddChild(building); building.Width = Int32.Parse(reader.GetAttribute("Width")); building.Height = Int32.Parse(reader.GetAttribute("Height")); building.PointLocation = new PointF(float.Parse(reader.GetAttribute("X")), float.Parse(reader.GetAttribute("Y"))); building.Type = reader.GetAttribute("Type"); building.CanProduce = bool.Parse(reader.GetAttribute("CanProduce")); if (!reader.IsEmptyElement) { currentComponent = building; } break; default: break; } break; case XmlNodeType.EndElement: if (currentComponent != null) { currentComponent = currentComponent.Parent; } break; } } Console.WriteLine("XmlTextReader Properties Test"); Console.WriteLine("==================="); // Read this element's properties and display them on console Console.WriteLine("Name:" + reader.Name); Console.WriteLine("Base URI:" + reader.BaseURI); Console.WriteLine("Local Name:" + reader.LocalName); Console.WriteLine("Attribute Count:" + reader.AttributeCount.ToString()); Console.WriteLine("Depth:" + reader.Depth.ToString()); Console.WriteLine("Node Type:" + reader.NodeType.ToString()); Console.WriteLine("Attribute Count:" + reader.Value.ToString()); } return(scenario); }
public void SetPrevScenario(ScenarioComponent scenario) { prevScenario = scenario; }
public ScenarioComponent GenerateScenarioFromXML() { ScenarioComponent scenario = null; if (reader.Read()) { // Go to the Scenario (skip the XML line) reader.Read(); scenario = new ScenarioComponent(); ModelComponent currentComponent = scenario; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.Name) { case "Gameworld": Gameworld gameworld = new Gameworld(); currentComponent.AddChild(gameworld); if (!reader.IsEmptyElement) currentComponent = gameworld; break; case "Map": int width = Int32.Parse(reader.GetAttribute("Width")); int height = Int32.Parse(reader.GetAttribute("Height")); Map map = new Map(width, height); currentComponent.AddChild(map); if (!reader.IsEmptyElement) currentComponent = map; break; case "Cell": int x = Int32.Parse(reader.GetAttribute("X")); int y = Int32.Parse(reader.GetAttribute("Y")); CellComponent cell = new CellComponent(); cell.X = x; cell.Y = y; currentComponent.AddChild(cell); if (!reader.IsEmptyElement) currentComponent = cell; break; case "PlayerList": PlayerList playerList = new PlayerList(); currentComponent.AddChild(playerList); if (!reader.IsEmptyElement) currentComponent = playerList; break; case "Player": PlayerComponent player = new PlayerComponent(); player.Name = reader.GetAttribute("Name"); player.Race = reader.GetAttribute("Race"); player.Gold = Int32.Parse(reader.GetAttribute("Gold")); player.Metal = Int32.Parse(reader.GetAttribute("Metal")); player.Wood = Int32.Parse(reader.GetAttribute("Wood")); currentComponent.AddChild(player); if (!reader.IsEmptyElement) currentComponent = player; break; case "BuildingList": if (!reader.IsEmptyElement) currentComponent = ((PlayerComponent)currentComponent).BuildingList; break; case "UnitList": if (!reader.IsEmptyElement) currentComponent = ((PlayerComponent)currentComponent).GetUnitList(); break; case "Sand": Sand sand = new Sand(); currentComponent.AddChild(sand); if (!reader.IsEmptyElement) currentComponent = sand; break; case "Mountain": Mountain mountain = new Mountain(); currentComponent.AddChild(mountain); if (!reader.IsEmptyElement) currentComponent = mountain; break; case "Grass": Grass grass = new Grass(); currentComponent.AddChild(grass); if (!reader.IsEmptyElement) currentComponent = grass; break; case "Unit": UnitComponent unit = new UnitComponent(); currentComponent.AddChild(unit); float unitX = float.Parse(reader.GetAttribute("X")); float unitY = float.Parse(reader.GetAttribute("Y")); unit.PointLocation = new PointF(unitX, unitY); unit.Type = reader.GetAttribute("Type"); unit.MaxHealth = short.Parse(reader.GetAttribute("MaxHealth")); unit.CurrentHealth = short.Parse(reader.GetAttribute("CurrentHealth")); unit.CanHarvest = bool.Parse(reader.GetAttribute("CanHarvest")); unit.CanAttack = bool.Parse(reader.GetAttribute("CanAttack")); unit.Attack = short.Parse(reader.GetAttribute("Attack")); unit.AttackRange = float.Parse(reader.GetAttribute("AttackRange")); unit.AttackTicks = byte.Parse(reader.GetAttribute("AttackTicks")); unit.CanBuild = bool.Parse(reader.GetAttribute("CanBuild")); unit.BuildSpeed = byte.Parse(reader.GetAttribute("BuildSpeed")); unit.Speed = float.Parse(reader.GetAttribute("Speed")); /* * Type="zombie" CanAttack="True" * Attack="20" AttackRange="4" AttackTicks="10" * BuildSpeed="30" CanBuild="True" CanHarvest="False" * CurrentHealth="100" MaxHealth="100" X="12" Y="13" * Speed="0.1" */ if (!reader.IsEmptyElement) currentComponent = unit; break; case "Building": Building building = new Building(); currentComponent.AddChild(building); building.Width = Int32.Parse(reader.GetAttribute("Width")); building.Height = Int32.Parse(reader.GetAttribute("Height")); building.PointLocation = new PointF(float.Parse(reader.GetAttribute("X")), float.Parse(reader.GetAttribute("Y"))); building.Type = reader.GetAttribute("Type"); building.CanProduce = bool.Parse(reader.GetAttribute("CanProduce")); if (!reader.IsEmptyElement) currentComponent = building; break; default: break; } break; case XmlNodeType.EndElement: if (currentComponent != null) currentComponent = currentComponent.Parent; break; } } Console.WriteLine("XmlTextReader Properties Test"); Console.WriteLine("==================="); // Read this element's properties and display them on console Console.WriteLine("Name:" + reader.Name); Console.WriteLine("Base URI:" + reader.BaseURI); Console.WriteLine("Local Name:" + reader.LocalName); Console.WriteLine("Attribute Count:" + reader.AttributeCount.ToString()); Console.WriteLine("Depth:" + reader.Depth.ToString()); Console.WriteLine("Node Type:" + reader.NodeType.ToString()); Console.WriteLine("Attribute Count:" + reader.Value.ToString()); } return scenario; }
public void Visit(ScenarioComponent scenario) { if (ScenarioVisitor != null) scenario.Accept(ScenarioVisitor); }
public void Visit(ScenarioComponent scenario) { output.WriteStartElement("Scenario"); VisitChildren(scenario); output.WriteEndElement(); }
private void setUpModel() { model = new GameModel(); ScenarioComponent scenario = new ScenarioComponent(20, 20); // 20 x 20 Gameworld. Building obstruction = new Building(); // Add grass cells at each cell. ZRTSModel.Map map = scenario.GetGameWorld().GetMap(); for (int i = 0; i < map.GetWidth(); i++) { for (int j = 0; j < map.GetHeight(); j++) { CellComponent cell = new CellComponent(); cell.AddChild(new Sand()); cell.X = i; cell.Y = j; if (i >= 2 && i <= 10 && j >= 2 && j <= 10) cell.AddEntity(obstruction); if (i >= 15 && i <= 18 && j >= 15 && j <= 18) cell.AddEntity(obstruction); if (i == 16 && j == 16) cell.RemoveEntity(obstruction); map.AddChild(cell); } } model.AddChild(scenario); }