Beispiel #1
0
        /// <summary>
        /// Activate the Play of the game
        /// </summary>
        /// <returns>Winner</returns>
        public Player Play()
        {
            int    turns         = 0;
            Player currentPlayer = NextPlayer();

            while (CheckForWinner(Board) == false && turns < 10)
            {
                if (turns == 9)
                {
                    currentPlayer.Name = "Draw";
                    break;
                }

                Board.DisplayBoard();

                bool fairPlay = currentPlayer.TakeTurn(Board);

                if (!fairPlay && currentPlayer.Name != "Draw")
                {
                    Play();
                }

                SwitchPlayer();
                turns++;
                currentPlayer = NextPlayer();

                Console.Clear();
            }

            Board.DisplayBoard();
            return(currentPlayer);
        }
Beispiel #2
0
        /// <summary>
        /// Activate the Play of the game
        /// </summary>
        /// <returns>Winner</returns>
        public Player Play()
        {
            //TODO: Complete this method and utilize the rest of the class structure to play the game.

            /*
             * 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.
             */
            bool   winner        = CheckForWinner(Board);
            Player currentPlayer = NextPlayer();
            int    turns         = 0;

            while (winner == false && turns != 10)
            {
                Board.DisplayBoard();
                currentPlayer.TakeTurn(Board);
                winner = CheckForWinner(Board);
                SwitchPlayer();
                currentPlayer = NextPlayer();
                turns++;
                if (turns == 9)
                {
                    currentPlayer.Name = "Draw";
                    turns++;
                }
                Console.Clear();
            }
            Board.DisplayBoard();
            return(currentPlayer);
        }