2
0

CountDown.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. namespace OpenVIII
  3. {
  4. /// <summary>
  5. /// Countdown from a set value based on game elapsed time
  6. /// </summary>
  7. /// <see cref="https://www.dreamincode.net/forums/topic/175513-countdown-timer/"/>
  8. public class CountDown
  9. {
  10. #region Constructors
  11. public CountDown(TimeSpan timeSpan) => TS = timeSpan;
  12. public CountDown(double ms) => MS = ms;
  13. #endregion Constructors
  14. #region Properties
  15. public bool Done => TS <= TimeSpan.Zero;
  16. public double MS
  17. {
  18. get => TS.TotalMilliseconds;
  19. set => TS = TimeSpan.FromMilliseconds(value);
  20. }
  21. public TimeSpan TS { get; set; }
  22. #endregion Properties
  23. #region Methods
  24. /// <summary>
  25. /// Run Update() to pass time; To "pause" don't run update
  26. /// </summary>
  27. public bool Update()
  28. {
  29. if (!Done)
  30. {
  31. TS -= Memory.ElapsedGameTime;
  32. }
  33. return Done;
  34. }
  35. #endregion Methods
  36. }
  37. }