/// <summary> /// Ctor of game loop /// </summary> /// <param name="clients">Reference to clients on hub</param> private GameLoop(IHubConnectionContext<dynamic> clients) { Clients = clients; _engine = new Engine(); _rng = new Random(); }
/// <summary> /// Move a player between grids /// </summary> /// <param name="playerId">PlayerId</param> /// <param name="destinationGrid">Destination grid where the player moves to</param> public void MovePlayer(int playerId, int destinationGrid, Engine engine) { var player = db.Players.FirstOrDefault(x => x.PlayerId == playerId); // Get Engine defaults for moves int maxGrids = 3; int maxTime = 1200; if(engine != null) { maxGrids = engine.MaxPlayingGrids; maxTime = engine.MaxPlayingTime; } if (player != null) { // If players have reached maximum number of grids to play if ((player.PlayedMGames+player.PlayedTGames) >= maxGrids) destinationGrid = 3; // If players have reached maximum time on platform if ((DateTime.Now - player.StartTime).TotalSeconds >= maxTime) destinationGrid = 3; // If destination grid is lobby or siding, set startlobby if(destinationGrid == 1 | destinationGrid == 2) { player.StartLobby = DateTime.Now; } // Set the destination grid player.GridId = destinationGrid; db.Save(); } }
/// <summary> /// Gets a copy of the engine settings from database. /// </summary> public void SetEngine() { using (var db = new PersistedRepository()) { _engine = db.Engine.GetCurrentEngine(MachineName, VirtualPath); } }
/// <summary> /// Returns the urls of grids /// </summary> /// <param name="gridId">Grid Id</param> /// <returns>Url where clients can navigate to</returns> public string GetUrl(Engine engine, int gridId) { string url; switch (gridId) { case 1: url = "~/lobby"; break; case 2: url = "~/waiting"; break; case 3: url = "~/checkout"; break; default: var grid = db.Grids.FirstOrDefault(g => g.GridId == gridId); if (grid != null) { switch (grid.GameTypeId) { case 1: url = "~/mgame/" + grid.GridGuid; break; case 2: url = "~/tgame/" + grid.GridGuid; break; //case 3: // url = "~/rmgame/" + grid.GridGuid; // break; //case 4: // url = "~/rtgame/" + grid.GridGuid; // break; default: url = "~/waiting"; break; } } else { url = "~/waiting"; } break; } // Reformat Url if (url.IndexOf("~/") >= 0) url = url.Replace("~", engine.Endpoint); return url; }