Exemple #1
0
        public void Play()
        {
            InitializeGame();

            while (_gameResult == GameResult.None)
            {
                _print.PrintWhichPlayerShouldPlay(_currentPlayer);
                string position       = Console.ReadLine();
                int    choiceOfPlayer = _board.GetArrayIndex(position);

                _board.CheckIfPositionIsValid(position, _currentPlayer);

                if (_board.CheckIfPlaceIsTaken(choiceOfPlayer))
                {
                    _currentPlayer = _currentPlayer == Player.X ? Player.X : Player.O;
                }

                _board.UpdateBoardArray(choiceOfPlayer, _currentPlayer);
                _board.PrintBoard();
                _gameResult    = _gameRules.CheckIfThePlayerWin(_board.GetBoardArray());
                _currentPlayer = _currentPlayer == Player.X ? Player.O : Player.X;
            }

            PrintWiningMessage();
        }