/// <summary>
        /// Attempt to get a valid player move.
        /// If the player chooses a location that is taken, the CurrentRoundState remains unchanged,
        /// the player is given a message indicating so, and the game loop is cycled to allow the player
        /// to make a new choice.
        /// </summary>
        /// <param name="currentPlayerPiece">identify as either the X or O player</param>
        private void ManagePlayerTurn(Gameboard.PlayerPiece currentPlayerPiece)
        {
            GameboardPosition gameboardPosition = _gameView.GetPlayerPositionChoice();

            if (_gameView.CurrentViewState != ConsoleView.ViewState.PlayerUsedMaxAttempts)
            {
                try
                {
                    //
                    // player chose an open position on the game board, add it to the game board
                    //
                    if (_gameboard.GameboardPositionAvailable(gameboardPosition))
                    {
                        _gameboard.SetPlayerPiece(gameboardPosition, currentPlayerPiece);
                    }
                    //
                    // player chose a taken position on the game board
                    //
                    else
                    {
                        _gameView.DisplayGamePositionChoiceNotAvailableScreen();
                    }
                }
                catch (Gameboard.GamePositionException pe)
                {
                    _gameView.DisplayGamePositionChoiceNotAvailableScreen();
                    Console.WriteLine(pe.Message);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Attempt to get a valid player move.
        /// If the player chooses a location that is taken, the CurrentRoundState remains unchanged,
        /// the player is given a message indicating so, and the game loop is cycled to allow the player
        /// to make a new choice.
        /// </summary>
        /// <param name="currentPlayerPiece">identify as either the X or O player</param>
        private void ManagePlayerTurn(PlayerPiece currentPlayerPiece)
        {
            int gameboardColumn = _gameView.GetPlayerPositionChoice();

            if (gameboardColumn == -2)
            {
                //Quit Game here.
                _playingRound = false;
            }

            if (_gameView.CurrentViewState != ConsoleView.ViewState.PlayerUsedMaxAttempts && gameboardColumn > -1)
            {
                //
                // player chose an open position on the game board, add it to the game board
                //
                int row = _gameboard.GameboardPositionAvailable(gameboardColumn);
                if (row > -1)
                {
                    _gameView.DisplayPieceDrop(row, gameboardColumn);
                    _gameboard._board[row, gameboardColumn].Status = currentPlayerPiece;
                    if (_gameboard.WinCheckFourInARow(row, gameboardColumn, currentPlayerPiece))
                    {
                        if (currentPlayerPiece == PlayerPiece.X)
                        {
                            _gameboard._currentRoundState = Gameboard.GameboardState.PlayerXWin;
                        }
                        else
                        {
                            _gameboard._currentRoundState = Gameboard.GameboardState.PlayerOWin;
                        }
                        return;
                    }
                    _gameboard.SetNextPlayer();
                    ClearBuffer();
                }
                //
                // player chose a taken position on the game board
                //
                else
                {
                    _gameView.DisplayGamePositionChoiceNotAvailableScreen();
                }
            }
        }
        /// <summary>
        /// Attempt to get a valid player move.
        /// If the player chooses a location that is taken, the CurrentRoundState remains unchanged,
        /// the player is given a message indicating so, and the game loop is cycled to allow the player
        /// to make a new choice.
        /// </summary>
        /// <param name="currentPlayerPiece">identify as either the X or O player</param>
        private void ManagePlayerTurn(Gameboard.PlayerPiece currentPlayerPiece)
        {
            GameboardPosition gameboardPosition = _gameView.GetPlayerPositionChoice();

            if (_gameView.CurrentViewState == ConsoleView.ViewState.ViewCurrentStats)
            {
                _gameView.DisplayCurrentGameStatus(_roundNumber, _playerXNumberOfWins, _playerONumberOfWins, _numberOfCatsGames);
                _gameView.CurrentViewState = ConsoleView.ViewState.Active;
                _gameView.DisplayGameArea();
                gameboardPosition = _gameView.GetPlayerPositionChoice();
            }

            if (_gameView.CurrentViewState != ConsoleView.ViewState.ResetCurrentRound)
            {
                //
                //Proceed with turn as normal.
                //
                if (_gameView.CurrentViewState != ConsoleView.ViewState.PlayerUsedMaxAttempts)
                {
                    //
                    // player chose an open position on the game board, add it to the game board
                    //
                    if (_gameboard.GameboardPositionAvailable(gameboardPosition))
                    {
                        _gameboard.SetPlayerPiece(gameboardPosition, currentPlayerPiece);
                    }
                    //
                    // player chose a taken position on the game board
                    //
                    else
                    {
                        _gameView.DisplayGamePositionChoiceNotAvailableScreen();
                    }
                }
            }
        }