ConfigurationManager.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // GameScreen.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Xml.Linq;
  13. #endregion
  14. namespace HoneycombRush
  15. {
  16. /// <summary>
  17. /// Repesent the difficulty mode of the game.
  18. /// </summary>
  19. public enum DifficultyMode
  20. {
  21. Easy = 1,
  22. Medium = 2,
  23. Hard = 3
  24. }
  25. /// <summary>
  26. /// Supplies access to configuration data.
  27. /// </summary>
  28. public static class ConfigurationManager
  29. {
  30. #region Fields
  31. static Dictionary<DifficultyMode, Configuration> modesConfiguration;
  32. public static Dictionary<DifficultyMode, Configuration> ModesConfiguration
  33. {
  34. get
  35. {
  36. return modesConfiguration;
  37. }
  38. }
  39. static bool isLoaded = false;
  40. public static bool IsLoaded
  41. {
  42. get
  43. {
  44. return isLoaded;
  45. }
  46. }
  47. public static DifficultyMode? DifficultyMode { get; set; }
  48. #endregion
  49. #region Public Static Methods
  50. /// <summary>
  51. /// Load configuration from an XML document.
  52. /// </summary>
  53. /// <param name="doc">The XML document containing configuration.</param>
  54. public static void LoadConfiguration(XDocument doc)
  55. {
  56. modesConfiguration = new Dictionary<DifficultyMode, Configuration>();
  57. foreach (XElement element in doc.Element("Difficulties").Elements("Difficulty"))
  58. {
  59. modesConfiguration.Add((DifficultyMode)Enum.Parse(typeof(DifficultyMode),
  60. element.Attribute("ID").Value, true),
  61. new Configuration()
  62. {
  63. DecreaseAmountSpeed = int.Parse(element.Element("DecreaseAmountSpeed").Value),
  64. GameElapsed = TimeSpan.Parse(element.Element("GameElapsed").Value),
  65. IncreaseAmountSpeed = int.Parse(element.Element("IncreaseAmountSpeed").Value),
  66. MaxSoldierBeeVelocity = int.Parse(element.Element("MaxSoldierBeeVelocity").Value),
  67. MaxWorkerBeeVelocity = int.Parse(element.Element("MaxWorkerBeeVelocity").Value),
  68. MinSoldierBeeVelocity = int.Parse(element.Element("MinSoldierBeeVelocity").Value),
  69. MinWorkerBeeVelocity = int.Parse(element.Element("MinWorkerBeeVelocity").Value),
  70. TotalSmokeAmount = int.Parse(element.Element("TotalSmokeAmount").Value),
  71. HighScoreFactor = int.Parse(element.Element("HighScoreFactor").Value)
  72. });
  73. }
  74. isLoaded = true;
  75. }
  76. #endregion
  77. }
  78. /// <summary>
  79. /// Contains all configuration memebers.
  80. /// </summary>
  81. public struct Configuration
  82. {
  83. public TimeSpan GameElapsed { get; set; }
  84. public float MinWorkerBeeVelocity { get; set; }
  85. public float MaxWorkerBeeVelocity { get; set; }
  86. public float MinSoldierBeeVelocity { get; set; }
  87. public float MaxSoldierBeeVelocity { get; set; }
  88. public int TotalSmokeAmount { get; set; }
  89. public int DecreaseAmountSpeed { get; set; }
  90. public int IncreaseAmountSpeed { get; set; }
  91. public int HighScoreFactor { get; set; }
  92. }
  93. }