Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, Welcome to TicTacToeGame");
            TicTacToe t = new TicTacToe();

            char[] board   = t.CreateBoard();
            char   pLetter = t.ChooseLetter();
            char   cLetter = 'X';

            if (pLetter.Equals('X'))
            {
                cLetter = 'O';
            }
            Console.WriteLine("Player's Letter = " + pLetter);
            Console.WriteLine("Computer's Letter = " + cLetter);
            t.PrintBoard(board);
            bool playVal = true;

            while (playVal)
            {
                Console.WriteLine("Choose a position among 1 to 9");
                int  choice         = Convert.ToInt32(Console.ReadLine());
                bool check_if_empty = t.check_Availability(board, choice);
                if (check_if_empty == false)
                {
                    Console.WriteLine("The position you chose is full, Please choose another position");
                }
                else
                {
                    board[choice] = pLetter;
                    t.PrintBoard(board);
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var t = new TicTacToe();

            char[] board  = t.CreateBoard();
            char   letter = t.ChooseLetter();

            t.Toss();
            t.Play();
            Console.WriteLine("\nCheck if won : " + t.CheckWinner(letter));
        }
Пример #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Tic Tac Toe Game");
            TicTacToe tic = new TicTacToe();

            // To create a new board
            char [] board = tic.CreateBoard();
            // To show board
            tic.ShowBoard(board);
            tic.Toss();
            // To choose a letter by a user
            char userLetter     = tic.ChooseLetter();
            char computerLetter = (userLetter == 'X') ? 'O' : 'X';
            // To move desired location
            int userMove = tic.getUserMove(board);

            tic.makeMove(board, userMove, userLetter);
            tic.ShowBoard(board);
            //Computer Move
            int computerMove = tic.getComputerMove(board, computerLetter, userLetter);

            Console.WriteLine("Check if Won: " + tic.isWinner(board, userLetter));
        }
Пример #4
0
        static void Main(string[] args)
        {
            char[] board          = TicTacToe.CreateBoard();
            char   userLetter     = TicTacToe.chooseUserLetter();
            char   computerLetter = (userLetter == 'X') ? 'O' : 'X';

            TicTacToe.Player player        = TicTacToe.getWhoStartsFirst();
            bool             gameIsPlaying = true;

            TicTacToe.GameStatus gameStatus;
            while (gameIsPlaying)
            {
                //players turn
                if (player.Equals(TicTacToe.Player.USER))
                {
                    TicTacToe.showBoard(board);
                    int    userMove   = TicTacToe.getUserMove(board);
                    String WonMessage = "Hooray! you won";
                    gameStatus = TicTacToe.getGameStatus(board, userMove, userLetter, WonMessage);
                    player     = TicTacToe.Player.COMPUTER;
                }
                else
                {
                    // computer turn
                    String WonMessage   = "The computer has beaten you";
                    int    computerMove = TicTacToe.getComputerMove(board, computerLetter, userLetter);
                    gameStatus = TicTacToe.getGameStatus(board, computerMove, computerLetter, WonMessage);
                    player     = TicTacToe.Player.USER;
                }
                if (gameStatus.Equals(TicTacToe.GameStatus.CONTINUE))
                {
                    continue;
                }
                TicTacToe.playAgain();
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, Welcome to TicTacToeGame");
            TicTacToe t         = new TicTacToe();
            bool      playAgain = true;

            while (playAgain)
            {
                char[] board   = t.CreateBoard();
                char   pLetter = t.ChooseLetter();
                char   cLetter = 'X';
                if (pLetter.Equals('X'))
                {
                    cLetter = 'O';
                }
                Console.WriteLine("Player's Letter = " + pLetter);
                Console.WriteLine("Computer's Letter = " + cLetter);
                t.PrintBoard(board);

                Player p = t.FirstPlayToss();

                bool       gameOver = false;
                GameStatus gstatus  = t.CheckCurrentStatus(board, pLetter, cLetter);

                while (!gameOver)
                {
                    if (p == Player.USER)
                    {
                        t.MakePlayerMove(board, pLetter);
                        gstatus = t.CheckCurrentStatus(board, pLetter, cLetter);
                        p       = Player.COMPUTER;
                    }
                    else
                    {
                        t.MakeComputerMove(board, cLetter, pLetter);
                        gstatus = t.CheckCurrentStatus(board, pLetter, cLetter);
                        p       = Player.USER;
                    }

                    if (gstatus != GameStatus.CONTINUE)
                    {
                        gameOver = true;
                    }
                }

                if (gstatus == GameStatus.WON)
                {
                    Player k = t.WhoWon(board, pLetter, cLetter);
                }

                Console.WriteLine("Do you want to play again(Y/N)");
                string a = Console.ReadLine();
                if (a[0] == 'Y')
                {
                    playAgain = true;
                }
                else
                {
                    playAgain = false;
                }
            }
        }