예제 #1
0
        static void Main(string[] args)
        {
            TicTacToeGame call = new TicTacToeGame();

            Console.WriteLine("Welcome to the Tic Tac Toe Game");
            char userInput     = call.ZeroOrCross();
            char computerInput = call.ComputerInput(userInput);

            for (; ;)
            {
                char   toss         = call.Toss();
                int    noOfTurns    = 0;
                bool   flag         = false;
                char[] currentBoard = call.CreateBoard();
                switch (toss)
                {
                case 'W':
                    for (; ;)
                    {
                        currentBoard = Player(currentBoard, userInput);
                        flag         = call.resultCheck(currentBoard);
                        noOfTurns   += 1;
                        if (flag == true)
                        {
                            Console.WriteLine("You Won");
                            break;
                        }
                        if (noOfTurns == 9)
                        {
                            Console.WriteLine("Match Drawn");
                            break;
                        }
                        currentBoard = Computer(currentBoard, computerInput, userInput);
                        flag         = call.resultCheck(currentBoard);
                        noOfTurns   += 1;
                        if (flag == true)
                        {
                            Console.WriteLine("Take the L");
                            break;
                        }
                        if (noOfTurns == 9)
                        {
                            Console.WriteLine("Match Drawn");
                            break;
                        }
                    }
                    break;

                case 'L':
                    for (; ;)
                    {
                        currentBoard = Computer(currentBoard, computerInput, userInput);
                        flag         = call.resultCheck(currentBoard);
                        noOfTurns   += 1;
                        if (flag == true)
                        {
                            Console.WriteLine("Take the L");
                            break;
                        }
                        if (noOfTurns == 9)
                        {
                            Console.WriteLine("Match Drawn");
                            break;
                        }
                        currentBoard = Player(currentBoard, userInput);
                        flag         = call.resultCheck(currentBoard);
                        noOfTurns   += 1;
                        if (flag == true)
                        {
                            Console.WriteLine("You Won");
                            break;
                        }
                        if (noOfTurns == 9)
                        {
                            Console.WriteLine("Match Drawn");
                            break;
                        }
                    }
                    break;
                }
                Console.ReadLine();
                Console.Clear();
                Console.WriteLine("Would You like to play another game Y/N :");
                char choice = Convert.ToChar(Console.ReadLine().ToLower());
                if (choice == 'n')
                {
                    break;
                }
            }
        }