コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OptionsViewModel"/> class.
        /// </summary>
        public OptionsViewModel()
        {
            try
            {
                errorLogViewModel = new ErrorLogViewModel();
                OptionModel = new Options();
                optionsXmlAccess = new OptionsXmlAccess();
                OptionModel = optionsXmlAccess.LoadOptions();

                switch (OptionModel.Resolution)
                {
                    case "580x420":
                        HorizontalScaleNumber = 580;
                        VerticalScaleNumber = 420;
                        break;
                    case "640x480":
                        HorizontalScaleNumber = 640;
                        VerticalScaleNumber = 480;
                        break;
                    case "800x600":
                        HorizontalScaleNumber = 800;
                        VerticalScaleNumber = 600;
                        break;
                }
            }
            catch
            { }
        }
コード例 #2
0
        /// <summary>
        /// Loads the items from the options xml file.
        /// </summary>
        /// <returns>The list of highscore items or null.</returns>
        public Options LoadOptions()
        {
            try
            {
                if (FileExists(PathString))
                {
                    // Open the options xml file.
                    XDocument highscoresFromXml = XDocument.Load(PathString);
                    var readDataFromXml = highscoresFromXml.Descendants("option");

                    // Get the items from the options xml file.
                    Options returnValue = new Options();
                    var fromXml = from x in readDataFromXml
                                  select x;

                    // Store the items in an Options object.
                    foreach (var oneElement in fromXml)
                    {
                        returnValue.Resolution = (string)oneElement.Element("resolution");
                        returnValue.LeftMove = (string)oneElement.Element("leftkey");
                        returnValue.PauseButton = (string)oneElement.Element("pausekey");
                        returnValue.FireButton = (string)oneElement.Element("firekey");
                        returnValue.IsMouseEnabled = (bool)oneElement.Element("mouse");
                        returnValue.RightMove = (string)oneElement.Element("rightkey");
                        returnValue.IsKeyboardEnabled = (bool)oneElement.Element("keyboard");
                        returnValue.IsSoundEnabled = (bool)oneElement.Element("sound");
                        returnValue.MapNumber = (int)oneElement.Element("map");
                        returnValue.Difficulty = (int)oneElement.Element("difficulty");
                    }

                    return returnValue;
                }

                return null;
            }
            catch
            {
                return null;
            }
        }
コード例 #3
0
        /// <summary>
        /// Updates the items in the options xml file.
        /// </summary>
        /// <param name="options">The options.</param>
        public void SaveOptions(Options options)
        {
            try
            {
                if (options != null && FileExists(PathString))
                {
                    // Open the options xml file.
                    XDocument settingsFromXml = XDocument.Load(PathString);
                    var readDataFromXml = settingsFromXml.Descendants("option");

                    // Get the items from the options xml file.
                    var fromXml = from x in readDataFromXml
                                  select x;

                    // Update the values in the options xml file.
                    foreach (var oneElement in fromXml)
                    {
                        fromXml.Single().Element("leftkey").Value = options.LeftMove;
                        fromXml.Single().Element("rightkey").Value = options.RightMove;
                        fromXml.Single().Element("pausekey").Value = options.PauseButton;
                        fromXml.Single().Element("resolution").Value = options.Resolution;
                        fromXml.Single().Element("firekey").Value = options.FireButton;
                        fromXml.Single().Element("mouse").Value = options.IsMouseEnabled.ToString();
                        fromXml.Single().Element("keyboard").Value = options.IsKeyboardEnabled.ToString();
                        fromXml.Single().Element("sound").Value = options.IsSoundEnabled.ToString();
                        fromXml.Single().Element("map").Value = options.MapNumber.ToString();
                        fromXml.Single().Element("difficulty").Value = options.Difficulty.ToString();
                    }

                    // Update the items in the options xml file.
                    settingsFromXml.Save(PathString);
                }
            }
            catch
            { }
        }