From e8ee7b69663a95d97b226266ebe3ccc95e13c309 Mon Sep 17 00:00:00 2001 From: "ivaylo.zhelev" Date: Sun, 31 Jan 2021 16:42:30 +0200 Subject: Major Business Logic Implementation * Added GameHub * Added Back-End Game Loop and Game Mechanics * Added End Game and Result message --- src/Web/PUSG.Web/Services/GameLoopService.cs | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/Web/PUSG.Web/Services/GameLoopService.cs (limited to 'src/Web/PUSG.Web/Services/GameLoopService.cs') diff --git a/src/Web/PUSG.Web/Services/GameLoopService.cs b/src/Web/PUSG.Web/Services/GameLoopService.cs new file mode 100644 index 0000000..9ddbb20 --- /dev/null +++ b/src/Web/PUSG.Web/Services/GameLoopService.cs @@ -0,0 +1,38 @@ +using PUSG.Web.Models; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace PUSG.Web.Static +{ + public class GameLoopService : IGameLoopService + { + private Timer timer; + + public GameSession GameSession { get; set; } + + private void Step(object state) + { + this.GameSession?.Update(); + } + + public Task StartAsync(CancellationToken cancellationToken) + { + this.timer = new Timer(Step, null, TimeSpan.Zero, TimeSpan.FromMilliseconds(17)); + + return Task.CompletedTask; + } + + public Task StopAsync(CancellationToken cancellationToken) + { + this.timer?.Change(Timeout.Infinite, 0); + + return Task.CompletedTask; + } + + public void Dispose() + { + this.timer?.Dispose(); + } + } +} -- cgit v1.3.1-26-gb76a