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.3 kB

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