///// <summary> ///// Set up a new game between two players. Will return the id of the created game. ///// </summary> ///// <param name="config">The parameters necessary to set up the game.</param> ///// <returns></returns> //public int ConfigureGame(GameConfiguration config) //{ // return ConfigureGame(config, null, true, true); //} public int ConfigureGame(int matchId) { using (IGameDataService gameDataService = new GameDataService()) { //Create a game, as well as a match in case the players play multiple games in a row. Models.Match match = gameDataService.GetMatch(matchId, null); if (match == null) throw new InvalidOperationException("A match is required for game play."); Models.Player playerOne = gameDataService.GetPlayer(match.PlayerOneId); Models.Player playerTwo = gameDataService.GetPlayer(match.PlayerTwoId); Models.Game game = gameDataService.CreateGame(playerOne, playerTwo, match); GameConfiguration config = GameConfigCache.Instance.GetConfig(matchId); //Make an entry in the table for AI to track the game. Models.AIGame aiPlayerOne; if (config.PlayerOne.PlayerType == PlayerType.AI) aiPlayerOne = gameDataService.CreateAIGame(playerOne, game, match); //We only want to be responsible for managing local AIs. //If it's networked, don't record it. Models.AIGame aiPlayerTwo; if (config.PlayerTwo.PlayerType == PlayerType.AI && config.GameType != GameType.Network) aiPlayerTwo = gameDataService.CreateAIGame(playerTwo, game, match); gameDataService.Attach(match); match.CurrentGameId = game.GameId; match.StateDate = game.StateDate; gameDataService.Save(); return game.GameId; } }