/// <summary> /// Submits the hand. /// </summary> /// <param name="hand">The hand.</param> /// <param name="teamId">The team identifier.</param> /// <param name="gameId">The game identifier.</param> /// <returns></returns> public OperationOutcome SumbitHand(Hand hand, Guid teamId, Guid gameId) { var gameAdapter = AdapterFactory.GetGameAdapter(); var game = gameAdapter.GetGameById(gameId); if (game == null) { throw new BadRequestException(); } var response = this.SubmitHandGeneric(hand, teamId, game); if (!game.IsSimulatedGame) { return(response); } gameAdapter = AdapterFactory.GetGameAdapter(); game = gameAdapter.GetGameById(gameId); if (!game.IsComplete) { this.SumbitSimulatedHand(game); } return(response); }
/// <summary> /// Gets all games for dashboard games. /// </summary> /// <param name="numberOfGames">The number of games.</param> /// <returns>DashboardGames</returns> public IEnumerable <Game> GetAllGamesForDashboardGames(int?numberOfGames = null) { numberOfGames = numberOfGames ?? Properties.Settings.Default.DefaultMaxDashboardGames; var adapter = AdapterFactory.GetGameAdapter(); return(adapter.GetGamesForDashbaord(numberOfGames.Value)); }
/// <summary> /// Gets the simulated game. /// </summary> /// <param name="team">The team.</param> /// <returns>The simulated team</returns> protected Guid GetSimulatedGame(Team team) { var gameAdapter = AdapterFactory.GetGameAdapter(); var game = gameAdapter.RegisiterSimulatorGame(Properties.Settings.Default.SimulatorTeamName); gameAdapter.SaveChanges(); return(game.Id); }
/// <summary> /// Determines the winner. /// </summary> /// <param name="gameId">The game identifier.</param> public void CompleteRound(Guid gameId) { var numberOfRounds = Properties.Settings.Default.BestOutOf; var roundsAdapter = AdapterFactory.GetRoundAdapter(); var gameAdapter = AdapterFactory.GetGameAdapter(); var completedRounds = roundsAdapter.GetCompletedRoundByGameId(gameId); if (completedRounds.Count() == numberOfRounds) { gameAdapter.UpdateGameState(GameState.Complete, gameId); } gameAdapter.SaveChanges(); }
public void RegisterSimnulatedGameAndPlayOneHand() { var gameProvider = ProviderFactory.GetGameProvider(); var roundProvider = ProviderFactory.GetRoundProvider(); var gameAdapter = AdapterFactory.GetGameAdapter(); var myTeamId = ObjectMother.TeamTestData.Team1Id; var gameId = gameProvider.GetNextAvailableGame(myTeamId, true); Assert.IsTrue(gameProvider.IsItMyTurn(gameId, myTeamId)); roundProvider.SumbitHand(Hand.Paper, myTeamId, gameId); var game = gameAdapter.GetGameById(gameId); Assert.AreEqual(GameState.Player2Hand, game.GameState); }
/// <summary> /// Finds a game. /// </summary> /// <param name="teamId">The team identifier.</param> /// <param name="playAgainstSimulator">if set to <c>true</c> [play against simulator].</param> /// <returns>The Game Id</returns> public Guid GetNextAvailableGame(Guid teamId, bool playAgainstSimulator = false) { var gameAdapter = AdapterFactory.GetGameAdapter(); var teamAdapter = AdapterFactory.GetTeamAdapter(); var gameId = Guid.Empty; var team = teamAdapter.GetTeamById(teamId); if (playAgainstSimulator) { gameId = GetSimulatedGame(team); } else { gameId = (gameAdapter.FindAvailableGame() ?? gameAdapter.RegisiterNewGame()).Id; } gameAdapter.SaveChanges(); gameAdapter.JoinExistingGame(team, gameId); gameAdapter.SaveChanges(); if (!playAgainstSimulator) { return(gameId); } gameAdapter = AdapterFactory.GetGameAdapter(); var game = gameAdapter.GetGameById(gameId); if (game.IsComplete) { return(gameId); } var roundProvider = ProviderFactory.GetRoundProvider(); roundProvider.SumbitSimulatedHand(game); return(gameId); }
/// <summary> /// Gets the game by identifier. /// </summary> /// <param name="gameId">The game identifier.</param> /// <returns></returns> public Game GetGameById(Guid gameId) { var adapter = AdapterFactory.GetGameAdapter(); return(adapter.GetGameById(gameId)); }