Esempio n. 1
0
        /// <summary>
        /// Loads a scenario from disc by deserializing.  Generates empty observer lists for each model component.
        /// </summary>
        public void loadScenario()
        {
            if (model.GetScenario() != null)
            {
                // TODO: Ask if the user wants to discard the current scenario.
            }

            // Displays an OpenFileDialog so the user can select a Map.
            OpenFileDialog openMapDialog = new OpenFileDialog();

            openMapDialog.InitialDirectory = Application.StartupPath + "\\Maps\\";
            openMapDialog.Filter           = "Map Files|*.map";
            openMapDialog.Title            = "Select a Map File";

            if (openMapDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Stream            mapFile  = openMapDialog.OpenFile();
                ScenarioXMLReader reader   = new ScenarioXMLReader(mapFile);
                ScenarioComponent scenario = reader.GenerateScenarioFromXML();
                mapFile.Close();
                model.AddChild(scenario);

                // Clear the stack because we now have a new scenario in context.
                model.GetCommandStack().EmptyStacks();
                // TODO: Update the SaveInfo state.
            }
        }
        /// <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);
        }