You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

MapGameTimer.cs 1.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Threading;
  2. using Preparation.Interface;
  3. namespace GameClass.GameObj
  4. {
  5. public partial class Map
  6. {
  7. // xfgg说:爱因斯坦说,每个坐标系都有与之绑定的时钟,(x, y, z, ict) 构成四维时空坐标,在洛伦兹变换下满足矢量性(狗头)
  8. private readonly GameTimer timer = new();
  9. public ITimer Timer => timer;
  10. public class GameTimer : ITimer
  11. {
  12. private bool isGaming = false;
  13. public bool IsGaming
  14. {
  15. get => isGaming;
  16. set
  17. {
  18. lock (isGamingLock)
  19. isGaming = value;
  20. }
  21. }
  22. readonly object isGamingLock = new();
  23. public bool StartGame(int timeInMilliseconds)
  24. {
  25. lock (isGamingLock)
  26. {
  27. if (isGaming)
  28. return false;
  29. isGaming = true;
  30. }
  31. Thread.Sleep(timeInMilliseconds);
  32. isGaming = false;
  33. return true;
  34. }
  35. }
  36. }
  37. }