Пример #1
0
        // make the computer move
        private void computerMove()
        {
            const int  k_WaitingSeconds = 2000;     // the delay time
            const bool v_Expose         = true;

            Console.WriteLine("Computer turn \ncomputer is choosing his first place to reveal");

            Tuple <Tuple <byte, byte>, Tuple <byte, byte> > computerMove = m_computerPlayer.PlayComputersTurn(); // the two moves
            Tuple <byte, byte> firstComputerMove  = computerMove.Item1;                                          // first move add for readability
            Tuple <byte, byte> secondComputerMove = computerMove.Item2;                                          // second move add for readability
            char sign1 = m_boardGame.CellMatrix[firstComputerMove.Item1, firstComputerMove.Item2].CellSign;      // first sign
            char sign2 = m_boardGame.CellMatrix[secondComputerMove.Item1, secondComputerMove.Item2].CellSign;    // second sign

            // expose and print the first choice
            m_boardGame.CellMatrix[firstComputerMove.Item1, firstComputerMove.Item2].IsExposed = v_Expose;
            System.Threading.Thread.Sleep(k_WaitingSeconds);
            Ex02.ConsoleUtils.Screen.Clear();
            printBoard();

            Console.WriteLine("Computer turn \ncomputer is choosing his second place to reveal");

            // expose and print the second choice
            m_boardGame.CellMatrix[secondComputerMove.Item1, secondComputerMove.Item2].IsExposed = v_Expose;
            System.Threading.Thread.Sleep(k_WaitingSeconds);
            Ex02.ConsoleUtils.Screen.Clear();
            printBoard();

            System.Threading.Thread.Sleep(k_WaitingSeconds);

            if (sign1 != sign2)     // if the computer didnt found a pair
            {
                Console.WriteLine("computer had his turn");
                System.Threading.Thread.Sleep(k_WaitingSeconds);
                m_boardGame.CellMatrix[firstComputerMove.Item1, firstComputerMove.Item2].IsExposed   = !v_Expose;
                m_boardGame.CellMatrix[secondComputerMove.Item1, secondComputerMove.Item2].IsExposed = !v_Expose;
                Ex02.ConsoleUtils.Screen.Clear();
                printBoard();
                m_player1.MyTurn = !m_player1.MyTurn; // make the next turn will be the player turn
            }
            else                                      // if the computer found a pair
            {
                Console.WriteLine("computer has found a pair and gets a point");
                m_computerPlayer.AddPointToScore();
                m_boardGame.PairFound();
                System.Threading.Thread.Sleep(k_WaitingSeconds); // we use sleep function here to make it more reality for the user
            }
        }