public int StartMatch(GameConfiguration config) { return this.host.InitiateChallenge(config); }
public void CacheConfig(int matchId, GameConfiguration config) { this.Cache.CacheConfig(matchId, config); }
public int InitiateChallenge(GameConfiguration config) { using (IGameDataService gameDataService = new GameDataService()) { Models.Player playerOne = gameDataService.GetOrCreatePlayer(config.PlayerOne.Name); Models.Player playerTwo = gameDataService.GetOrCreatePlayer(config.PlayerTwo.Name); Models.Match match = gameDataService.CreateMatch(playerOne, playerTwo); match.StateDate = DateTime.Now; match.NumberOfRounds = config.MatchRounds; GameConfigCache.Instance.CacheConfig(match.MatchId, config); string serializedConfig = JsonSerializer.SerializeToJSON(config); IEnumerable<string> configSections = StringSplitter.SplitString(serializedConfig, 500); List<ConfigSection> dbConfigSections = new List<ConfigSection>(); foreach(var section in configSections) { dbConfigSections.Add(gameDataService.CreateConfigSection(match.MatchId, section)); } if (config.PlayerTwo.PlayerType == PlayerType.AI && config.GameType == GameType.Local) match.PlayerTwoAccepted = true; gameDataService.Save(); int gameId = ConfigureGame(match.MatchId); //Contact the central server //In this case, we are just handling data validation, and game rules. //We will let the server response tell us who goes first. if (config.GameType == GameType.Network) { this.PlayerChallenge(this, new ChallengeEventArgs() { MatchId = match.MatchId, PlayerOneId = playerOne.PlayerId, PlayerTwoId = playerTwo.PlayerId }); } return match.MatchId; } }