/// <summary> /// Initialize necessary components /// </summary> private void initialize() { game = new XnaUITestGame(); ZRTSController controller = new ZRTSController(game); game.Components.Add(controller); model = new GameModel(); ScenarioComponent scenario = new ScenarioComponent(50, 50); player1 = new PlayerComponent(); player2 = new PlayerComponent(); player1.Name = "Nate"; player2.Name = "Smith"; // Add sand 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); game.Model = model; game.Model.PlayerInContext = player1; // Set a main Player //Create two players and set them to be enemies. game.Model.GetScenario().GetGameWorld().GetPlayerList().AddChild(player1); game.Model.GetScenario().GetGameWorld().GetPlayerList().AddChild(player2); // Set target enemy player1.EnemyList.Add(player2); player2.EnemyList.Add(player1); game.Controller = controller; // Add worker to player unitList = new List <ModelComponent>(); unitList.Add(new UnitComponent()); ((UnitComponent)unitList[0]).CanBuild = true; ((UnitComponent)unitList[0]).Type = "worker"; ((UnitComponent)unitList[0]).PointLocation = new PointF(20, 20); //(1) Get Player#1 currentPlayer1 = (PlayerComponent)((XnaUITestGame)game).Model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[0]; // check if fetch the correct player Assert.AreEqual("Nate", currentPlayer1.Name); // (2) Add the actual player's unit list currentPlayer1.GetUnitList().AddChild(unitList[0]); }
/// <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); }
/// <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); ScenarioXMLReader reader = new ScenarioXMLReader(mapFile); ScenarioComponent scenario = reader.GenerateScenarioFromXML(); model.AddChild(scenario); model.PlayerInContext = (PlayerComponent)model.GetScenario().GetGameWorld().GetPlayerList().GetChildren()[0]; 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); }