ConfigurationManager.cs 3.4 KB

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