Esempio n. 1
0
        // Refactor here, this method is new to avoid replicating work
        private void PlayerTurn(char[] arr, TTTGameRefactor g, string playerNumber, char choice)
        {
            Console.WriteLine($"Player {playerNumber} choose a number.");
            string input = Console.ReadLine();

            int numInput = int.Parse(input);

            arr[numInput - 1] = choice;

            g.DisplayBoard(arr);
        }
Esempio n. 2
0
        public void Run()
        {
            Console.WriteLine("Let's play Tic Tac Toe!");
            char[] arr = new char[9]
            {
                '1', '2', '3', '4', '5', '6', '7', '8', '9'
            };
            TTTGameRefactor g = new TTTGameRefactor();

            g.DisplayBoard(arr);

            bool isPlayerOne = true;
            bool isDraw      = false;
            bool isWin       = false;

            while (!isWin && !isDraw)
            {
                if (isPlayerOne == true)
                {
                    // Refactor here
                    PlayerTurn(arr, g, "1", 'o');
                    isPlayerOne = false;
                }
                else
                {
                    // Refactor here
                    PlayerTurn(arr, g, "2", 'x');
                    isPlayerOne = true;
                }

                isWin  = g.CheckForDraw(arr);
                isDraw = g.CheckForWin(arr);
            }
            Console.WriteLine("Game over. Would you like to play again?");
            Console.ReadLine();
        }