public FormMission(Mission mission, Player player, Game game)
        {
            this.mission = mission;
            this.player = player;
            this.game = game;
            this.roundLeft = game.GetRandomNumber(this.mission.MinRounds, this.mission.MaxRounds);

            InitializeComponent();
            InitializeFormContent();
        }
Example #2
0
        private void LoadMissions()
        {
            string filePath = MissionValuesFilePath;
            if (File.Exists(filePath) == false)
                throw new FileNotFoundException(string.Format("Le fichier de données\r\n{0}'\r\nest introuvable!", filePath));

            XDocument document = null;

            try
            {
                document = XDocument.Load(filePath);
            }
            catch (Exception exp)
            {
                throw new Exception(string.Format("Erreur lors du chargement du fichier de configuration\r\n{0}", filePath), exp);
            }

            XElement xroot = document.Root;
            XElement xjobRootElement = xroot.XPathSelectElement(this.Name);
            if (xjobRootElement == null)
                return; // No corresponding job entry

            XElement xmissionRoot = xjobRootElement.XPathSelectElement("Missions");
            if (xmissionRoot == null)
                return;

            IEnumerable<XElement> xmissions = xmissionRoot.Elements(); // XPathSelectElements("Mission");
            if (xmissions == null || xmissions.Count<XElement>() == 0)
                return;

            foreach (XElement xmission in xmissions)
            {
                Mission mission = new Mission();

                XElement xdescription = xmission.XPathSelectElement("Description");
                mission.Description = xdescription.Value;

                XElement xminRounds = xmission.XPathSelectElement("MinRounds");
                mission.MinRounds = Int32.Parse(xminRounds.Value);
                XElement xmaxRounds = xmission.XPathSelectElement("MaxRounds");
                mission.MaxRounds = Int32.Parse(xmaxRounds.Value);
                XElement xgain = xmission.XPathSelectElement("Gain");
                mission.Gain = Int32.Parse(xgain.Value);

                this.missions.Add(mission);
            }
        }