Exemplo n.º 1
0
        public void MakeComputerMove(int gameId)
        {
            var currentGame = _gameRepository.GetWithPlayer(gameId);

            if (currentGame.EndDateTime != null)
            {
                return;
            }
            ISelectorStrategy strategy = currentGame.LevelId == (int)LevelEnum.Easy ?
                                         new EasySelectorStrategy()
                : (ISelectorStrategy) new HardSelectorStrategy();

            var cell = _gameCellSelectorService.Execute(currentGame.Id, (GameSideEnum)currentGame.ComputerPlayer.GameSideId, strategy);

            #region Computer move

            _moveRepository.Add(new Move
            {
                CellId     = cell.CellId,
                GameId     = gameId,
                PlayerId   = currentGame.ComputerPlayerId,
                MoveNumber = _moveRepository.ExistsCount(gameId, currentGame.ComputerPlayerId) + 1
            });
            _moveRepository.SaveChanges();
            #endregion
            CheckWin(currentGame);
        }
Exemplo n.º 2
0
        public GameCell Execute(int currentGameId, GameSideEnum computerGameSide, ISelectorStrategy selectorStrategy)
        {
            var cells = _gameCellService.GetAll(currentGameId).ToArray();

            GameCell gameCell = selectorStrategy.GetCell(cells, computerGameSide);

            return(gameCell);
        }