Esempio n. 1
0
 private void showComputerPicks()
 {
     m_DataBoard.AddSignToRealTimeBoard(m_FirstSquareChoice);
     MessageOrganizer.ShowBoard(m_DataBoard.RealTimeBoard);
     m_DataBoard.AddSignToRealTimeBoard(m_SecondSquareChoice);
     MessageOrganizer.ShowBoard(m_DataBoard.RealTimeBoard);
 }
Esempio n. 2
0
        private void playerSquarePick(Position io_SquareChoice)
        {
            StringBuilder squareToRevelaStr = new StringBuilder(MessageOrganizer.ChooseSquareToReveal(m_DataBoard.BoardHeight, m_DataBoard.BoardWidth));

            squareStrToCoordinates(squareToRevelaStr.ToString(), io_SquareChoice);

            // checks if the choosen square is taken
            while (!m_DataBoard.IsSquareAvailable(io_SquareChoice))
            {
                MessageOrganizer.TakenSquareMsg();
                squareToRevelaStr.Replace(squareToRevelaStr.ToString(), MessageOrganizer.ChooseSquareToReveal(m_DataBoard.BoardHeight, m_DataBoard.BoardWidth));
                squareStrToCoordinates(squareToRevelaStr.ToString(), io_SquareChoice);
            }

            m_DataBoard.AddSignToRealTimeBoard(io_SquareChoice);
            MessageOrganizer.ShowBoard(m_DataBoard.RealTimeBoard);
        }
Esempio n. 3
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)
                    }
                }
            }
        }
Esempio n. 4
0
        private void playerVsComputer()
        {
            while (m_GameStillRuning)
            {
                m_MainPlayer.Score = 0;
                bool isMainPlayerTurn = true;
                m_IsRoundRuning = true;
                Computer aiComputer;

                startRound();
                aiComputer = new Computer(m_DataBoard.BoardHeight, m_DataBoard.BoardWidth);

                // turns start:
                while (m_IsRoundRuning)
                {
                    if (isMainPlayerTurn)
                    {
                        MessageOrganizer.TurnMsg(m_MainPlayer.Name);
                    }
                    else
                    {
                        MessageOrganizer.TurnMsg();
                    }

                    MessageOrganizer.ShowBoard(m_DataBoard.RealTimeBoard);

                    if (isMainPlayerTurn)
                    {
                        playerPairPick();
                    }
                    else // COMPUTER AI PICK
                    {
                        aiComputer.PickPair(m_DataBoard, m_FirstSquareChoice, m_SecondSquareChoice);
                        showComputerPicks();
                    }

                    if (m_DataBoard.IsIdenticalPair(m_FirstSquareChoice, m_SecondSquareChoice))
                    {
                        if (isMainPlayerTurn)
                        {
                            aiComputer.UpdateMemory(m_DataBoard, m_FirstSquareChoice, m_SecondSquareChoice, true);
                            m_MainPlayer.Score++;
                        }
                        else
                        {
                            aiComputer.Score++;
                        }

                        if (checkFullBoard(m_MainPlayer.Score, aiComputer.Score))
                        {
                            string winnerName = gameWinner(string.Empty, aiComputer.Score);
                            endRound(winnerName);
                        }
                    }
                    else
                    {
                        aiComputer.UpdateMemory(m_DataBoard, m_FirstSquareChoice, m_SecondSquareChoice, false);
                        m_DataBoard.RemovePairFromRealTimeBoard(m_FirstSquareChoice, m_SecondSquareChoice);

                        isMainPlayerTurn = !(isMainPlayerTurn);

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