Esempio n. 1
0
        static void EnterPosition(char side)
        {
            char previousside = '1';
            bool enteredwrong = false;

            while (true)
            {
                Console.Write("\n\n{0}'s turn:your move:", side);
                String input = Console.ReadLine().ToString();
                if (side == previousside && enteredwrong != true)
                {
                    Console.Write("Not your Turn!!");
                    continue;
                }
                input = input.ToUpper();

                previousside = side;
                if (IsBoardFull() != true)
                {
                    System.Collections.Hashtable tableMapping = TicTacToe.GetHashTable();
                    String position = (String)tableMapping[input];
                    if (position == null)
                    {
                        Console.WriteLine("Invalid Input please re enter");
                        enteredwrong = true;
                        continue;
                    }
                    String[] arrayposition = position.Split(',');

                    Int16 row    = Int16.Parse(arrayposition[0]);
                    Int16 column = Int16.Parse(arrayposition[1]);

                    if (m_board[row, column] == ' ')
                    {
                        m_board[row, column] = (side == 1 ? 'o' : 'x');
                        TicTacToe.DisplayBoard();
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Invalid Input please re enter");
                    }
                }
                else
                {
                    Console.WriteLine("Game Over NoBody Wins!!");
                }
            }
        }
Esempio n. 2
0
        static void Main()
        {
            TicTacToe.DisplayBoard();
            byte yside = 1;

            while (true)
            {
                yside = (byte)~yside;
                char side = Convert.ToChar(yside);
                TicTacToe.EnterPosition(side);
                if (TicTacToe.CheckWinning() == true)
                {
                    break;
                }
            }

            Console.ReadKey();
        }