Ejemplo n.º 1
0
        private void CheckWin(Game currentGame)
        {
            var winner         = _victoryCheckService.GetWinner(currentGame);
            var availableCells = _gameCellService.GetAllAvailable(currentGame.Id);

            if (winner != null || availableCells.Count == 0)
            {
                EndGame(currentGame, winner);
            }
        }
Ejemplo n.º 2
0
        private void EndGame(Game game, GameSideEnum?winnerGameSideEnum)
        {
            var currentGame = _gameRepository.GetWithPlayer(game.Id);

            currentGame.EndDateTime = DateTime.Now;
            if (winnerGameSideEnum != null)
            {
                currentGame.WinnerPlayerId = game.Player.GameSideId == (int)winnerGameSideEnum ?
                                             game.PlayerId :
                                             game.ComputerPlayerId;
                currentGame.LoserPlayerId = game.Player.GameSideId != (int)winnerGameSideEnum ?
                                            game.PlayerId :
                                            game.ComputerPlayerId;
            }
            _gameRepository.Update(currentGame);
            _gameRepository.SaveChanges();
        }