예제 #1
0
        /// <summary>
        /// Activate the Play of the game
        /// </summary>
        /// <returns>Winner</returns>
        public Player Play()
        {
            //DONE: Complete this method and utilize the rest of the class structure to play the game.
            Player currentPlayer = PlayerOne;
            int    turnNumber    = 1;

            Board.DisplayBoard();

            Console.WriteLine();

            while (Winner == null && turnNumber < 10)
            {
                turnNumber++;

                if (PlayerOne.IsTurn)
                {
                    currentPlayer = PlayerOne;
                    PlayerOne.TakeTurn(Board);
                }
                if (PlayerTwo.IsTurn)
                {
                    currentPlayer = PlayerTwo;
                    PlayerTwo.TakeTurn(Board);
                }
                Board.DisplayBoard();
                Console.WriteLine();
                bool winningTurn = CheckForWinner(Board);
                if (winningTurn)
                {
                    Winner = currentPlayer;
                }
                if (currentPlayer.Equals(PlayerOne))
                {
                    currentPlayer = PlayerTwo;
                }
                else
                {
                    currentPlayer = PlayerOne;
                }
                SwitchPlayer();
            }

            Board.DisplayBoard();
            Console.WriteLine();
            return(Winner);

            /*
             * Complete this method by constructing the logic for the actual playing of Tic Tac Toe.
             *
             * A few things to get you started:
             * 1. A turn consists of a player picking a position on the board with their designated marker.
             * 2. Display the board after every turn to show the most up to date state of the game
             * 3. Once a Winner is determined, display the board one final time and return a winner
             *
             * Few additional hints:
             *  Be sure to keep track of the number of turns that have been taken to determine if a draw is required
             *  and make sure that the game continues while there are unmarked spots on the board.
             *
             * Use any and all pre-existing methods in this program to help construct the method logic.
             */
        }