Esempio n. 1
0
        private void LoadData()
        {
            string filePath = DataFilePath;
            if (File.Exists(filePath) == false)
                throw new FileNotFoundException(string.Format("Le fichier de données\r\n{0}'\r\nest introuvable!", filePath));

            IniFileReader iniFile = new IniFileReader();

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

            if (iniFile.Sections.ContainsKey("Vehicles") == false)
                throw new Exception(string.Format("Il manque la section 'Vehicles' dans le fichier de configuration\r\n{0}", filePath));

            IniSection sectionVehicles = iniFile.Sections["Vehicles"];
            this.vehicleData.FuelCost = Double.Parse(sectionVehicles.KeyValues["FuelCost"], CultureInfo.InvariantCulture);

            IniSection sectionJobs = iniFile.Sections["Jobs"];
            this.jobData.MaxWorkingRound = Int32.Parse(sectionJobs.KeyValues["MaxWorkingRound"], CultureInfo.InvariantCulture);
            this.jobData.SalaryFactor = Int32.Parse(sectionJobs.KeyValues["SalaryFactor"], CultureInfo.InvariantCulture);

            IniSection sectionPlayers = iniFile.Sections["Players"];
            this.playerData.DefaultCapital = Int32.Parse(sectionPlayers.KeyValues["DefaultCapital"], CultureInfo.InvariantCulture);
        }
Esempio n. 2
0
        private void LoadGrads()
        {
            string filePath = DefaultValuesFilePath;
            if (File.Exists(filePath) == false)
                throw new FileNotFoundException(string.Format("Le fichier de données\r\n{0}'\r\nest introuvable!", filePath));

            IniFileReader iniFile = new IniFileReader();

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

            if (iniFile.Sections.ContainsKey(this.name) == false)
                throw new Exception(string.Format("Il manque la section '{0}' dans le fichier de configuration\r\n{0}", this.name, filePath));

            IniSection section = iniFile.Sections[this.name];
            List<Grade> tmpGrades = new List<Grade>();

            foreach (string keyName in section.KeyValues.Keys)
            {
                string value = section.KeyValues[keyName];
                if (string.IsNullOrWhiteSpace(value))
                    throw new Exception(string.Format("Valeur incorrecte dans le fichier de configuration\r\n{0}\r\npour la clef '{1}' dans la section '{2}'.", filePath, keyName, this.name));

                string[] values = value.Split(new char[] { ',' });
                if (values.Length != 12)
                    throw new Exception(string.Format("Nombre de valeurs incorrect dans le fichier de configuration\r\n{0}\r\npour la clef '{1}' dans la section '{2}'.", filePath, keyName, this.name));

                Grade grade = new Grade()
                {
                    Name = keyName,
                    MinimalExperiences = new LPExperiences()
                    {
                        Scientific = Convert.ToInt32(values[0]),
                        PhysicalFitness = Convert.ToInt32(values[1]),
                        ManagerialSkills = Convert.ToInt32(values[2]),
                        Creativity = Convert.ToInt32(values[3]),
                        Empathy = Convert.ToInt32(values[4])
                    },
                    MaxExperiencesGainPerRound = new LPExperiences()
                    {
                        Scientific = Convert.ToInt32(values[5]),
                        PhysicalFitness = Convert.ToInt32(values[6]),
                        ManagerialSkills = Convert.ToInt32(values[7]),
                        Creativity = Convert.ToInt32(values[8]),
                        Empathy = Convert.ToInt32(values[9])
                    },
                    SalaryPerRound = Convert.ToInt32(values[10]),
                    Level = Convert.ToInt32(values[11])
                };
                tmpGrades.Add(grade);
            }

            this.grades = tmpGrades.ToArray<Grade>();
        }