Ejemplo n.º 1
0
        public void MainMethod()
        {
            board = new TicTacToeBoard();
            Console.WriteLine("Hello! To play tic tac toe, when it is your turn, enter the index of where you want to play (0-8)");
            Console.Read();

            while (!board.IsFull() && !board.IsWinner(SquareType.X) && !board.IsWinner(SquareType.O))
            {
                DisplayBoardGrid();

                Console.WriteLine("It is {0} turn.", currentTurn);
                int move = promptForInt("Enter your index: ");
                if (board.IsLegalMove(move))
                    board.MakeMove(move, currentTurn);
                else
                {
                    Console.WriteLine("Illegal Move! Press enter!");
                    Console.Read();
                    continue;
                }
                // Swap the turn
                currentTurn = currentTurn == SquareType.X ? SquareType.O : SquareType.X;
            }

            DisplayBoardGrid();

            if (board.IsFull())
                Console.WriteLine("Tie! Board is full!");
            else if (board.IsWinner(SquareType.X))
                AccounceWinner(SquareType.X);
            else if (board.IsWinner(SquareType.O))
                AccounceWinner(SquareType.O);
            else
                Console.WriteLine("Something has gone wrong!");
        }