Esempio n. 1
0
        public void PlayGame()
        {
            // Start of the game
            m_GameStillRuning  = true;
            m_MainPlayer       = new Player(MessageOrganizer.EnterName());
            m_IsVersusComputer = (MessageOrganizer.ChooseOpponent() == 2); // checks which opponent is selected

            // starts the game that's fit for the choosen opponent:
            if (m_IsVersusComputer)
            {
                playerVsComputer();
            }
            else
            {
                playerVsPlayer();
            }

            MessageOrganizer.exitGame();
        }
Esempio n. 2
0
        private void playerVsPlayer()
        {
            Player secondPlayer = new Player(MessageOrganizer.EnterName());

            while (m_GameStillRuning)
            {
                Player currentPlayer = m_MainPlayer;
                m_IsRoundRuning    = true;
                m_MainPlayer.Score = secondPlayer.Score = 0;

                startRound();

                while (m_IsRoundRuning)
                {
                    MessageOrganizer.TurnMsg(currentPlayer.Name);
                    MessageOrganizer.ShowBoard(m_DataBoard.RealTimeBoard);

                    playerPairPick();

                    if (m_DataBoard.IsIdenticalPair(m_FirstSquareChoice, m_SecondSquareChoice))
                    {
                        currentPlayer.Score++;

                        if (checkFullBoard(m_MainPlayer.Score, secondPlayer.Score))
                        {
                            string winnerName = gameWinner(secondPlayer.Name, secondPlayer.Score);
                            endRound(winnerName);
                        }
                    }
                    else
                    {
                        m_DataBoard.RemovePairFromRealTimeBoard(m_FirstSquareChoice, m_SecondSquareChoice);

                        currentPlayer = currentPlayer == m_MainPlayer ? secondPlayer : m_MainPlayer;

                        System.Threading.Thread.Sleep(2000); // if its not a matched pair let the viewers see the board for additonal  second(2 second total)
                    }
                }
            }
        }