예제 #1
0
        // make the player move
        private void playerMove(ref Player i_currentlyPlaying)
        {
            const int k_WaitingSeconds = 2000;  // delay time

            Console.WriteLine("Player: " + i_currentlyPlaying.UserName);

            char sign1, sign2;
            byte firstWantedRow, firstWantedColumn, secondWantedRow, secondWantedcolumn;
            bool k_Exposed = true;

            // get the first choice , the sign , expose and print
            getCellFromUser(out firstWantedRow, out firstWantedColumn);
            sign1 = m_boardGame.CellMatrix[firstWantedRow, firstWantedColumn].CellSign;
            m_boardGame.CellMatrix[firstWantedRow, firstWantedColumn].IsExposed = k_Exposed;
            Ex02.ConsoleUtils.Screen.Clear();
            printBoard();

            Console.WriteLine("Player: " + i_currentlyPlaying.UserName);

            // get the second choice , the sign , expose and print
            getCellFromUser(out secondWantedRow, out secondWantedcolumn);
            sign2 = m_boardGame.CellMatrix[secondWantedRow, secondWantedcolumn].CellSign;
            m_boardGame.CellMatrix[secondWantedRow, secondWantedcolumn].IsExposed = k_Exposed;
            Ex02.ConsoleUtils.Screen.Clear();
            printBoard();

            if (sign1 != sign2)     // if the player didnt found a pair
            {
                Console.WriteLine(i_currentlyPlaying.UserName + " turn has ended");
                System.Threading.Thread.Sleep(k_WaitingSeconds);
                m_boardGame.CellMatrix[firstWantedRow, firstWantedColumn].IsExposed   = !k_Exposed;
                m_boardGame.CellMatrix[secondWantedRow, secondWantedcolumn].IsExposed = !k_Exposed;
                Ex02.ConsoleUtils.Screen.Clear();
                printBoard();
                m_player1.MyTurn = !m_player1.MyTurn;
            }
            else        // if the player found a pair
            {
                i_currentlyPlaying.AddPoint();
                m_boardGame.PairFound();

                if (i_currentlyPlaying.Score > 1)
                {
                    Console.WriteLine("Nice choice! " + i_currentlyPlaying.UserName + " have " + i_currentlyPlaying.Score + " points");
                }
                else
                {
                    Console.WriteLine("Nice choice! " + i_currentlyPlaying.UserName + " have " + i_currentlyPlaying.Score + " point");
                }
            }

            // if we are playing against the computer we need to update the player moves to the memory of the computer
            if (m_FormatGame == eGameFormat.AgainstComputer)
            {
                m_computerPlayer.UpDateComputerMemory(firstWantedRow, firstWantedColumn, secondWantedRow, secondWantedcolumn, sign1, sign2);
            }
        }