Example #1
0
        // Play one turn
        // First choose a valid cell to expose, then choose another valid cell to expose
        // if the cells are equals return value of 1 else return 0
        // at any time that 'Q' is pressed the function stops its action
        private int playOneTurn()
        {
            string           nameOfPlayer = m_PlayerTurn ? m_PlayerName : m_OpponentName;
            int              retVal       = 1;
            Tuple <int, int> firstChoice  = GameUserInterface.PlayerTurn(nameOfPlayer, m_Game, ref m_WantsToQuit);

            if (!m_WantsToQuit)
            {
                m_Game.ExposeCell(firstChoice.Item1, firstChoice.Item2);
                clearAndPrint();
                Tuple <int, int> secondChoice = GameUserInterface.PlayerTurn(nameOfPlayer, m_Game, ref m_WantsToQuit);

                if (!m_WantsToQuit)
                {
                    m_Game.ExposeCell(secondChoice.Item1, secondChoice.Item2);
                    clearAndPrint();

                    if (!m_Game.CellsAreEquals(firstChoice.Item1, firstChoice.Item2, secondChoice.Item1, secondChoice.Item2))
                    {
                        retVal = 0;
                        m_Game.UnExposeCell(firstChoice.Item1, firstChoice.Item2);
                        m_Game.UnExposeCell(secondChoice.Item1, secondChoice.Item2);
                        System.Threading.Thread.Sleep(k_TwoSeconds);
                        clearAndPrint();
                    }
                }
            }

            return(retVal);
        }
Example #2
0
        // recieve player's name, who is the opponent and if the opponent is another player
        // then recieve also his name
        internal void StartGame()
        {
            m_PlayerName = GameUserInterface.GetNameFromUser();
            // if true the game is between 2 players
            if (GameUserInterface.CheckOponent())
            {
                m_OpponentName    = GameUserInterface.GetNameFromUser();
                m_AgainstComputer = !m_AgainstComputer;
            }

            gameFlow();
        }
Example #3
0
        // initialize game score and give the turn to player for next round
        private void initializeGame()
        {
            m_PlayerTurn      = true;
            m_IsFirstTurn     = true;
            m_ScoreOfOpponent = 0;
            m_ScoreOfPlayer   = 0;
            m_TotalScore      = 0;
            // this part is in charge of getting the board size from the user
            int numOfRows    = 0;
            int numOfColumns = 0;

            GameUserInterface.SetBoardSize(ref numOfRows, ref numOfColumns);
            m_Game = new MemoryGameLogic(numOfRows, numOfColumns, m_AgainstComputer);
            m_Game.GenerateRandomizedBoard();
            clearAndPrint();
        }
Example #4
0
 private void msgAtStartOfTurn()
 {
     if (!m_PlayerTurn && m_AgainstComputer)
     {
         GameUserInterface.PrintMsgOnceTurn(m_OpponentName);
         System.Threading.Thread.Sleep(k_TwoSeconds);
     }
     else if (m_PlayerTurn && m_IsFirstTurn)
     {
         GameUserInterface.PrintMsgOnceTurn(m_PlayerName);
         m_IsFirstTurn = !m_IsFirstTurn;
     }
     else if (!m_PlayerTurn && m_IsFirstTurn)
     {
         GameUserInterface.PrintMsgOnceTurn(m_OpponentName);
         m_IsFirstTurn = !m_IsFirstTurn;
     }
     else
     {
         Console.WriteLine("Great guess, you have another turn.");
     }
 }
Example #5
0
        private void endGame()
        {
            if (m_WantsToQuit)
            {
                Console.WriteLine("You have given up, exiting the game.");
                System.Threading.Thread.Sleep(k_TwoSeconds);
            }
            else
            {
                StringBuilder msgToPrint = new StringBuilder(string.Format(@"The game is over, the results are:
{0}'s score is: {1}
{2}'s score is: {3}", m_PlayerName, m_ScoreOfPlayer, m_OpponentName, m_ScoreOfOpponent));
                msgToPrint.Append(Environment.NewLine);

                if (m_ScoreOfPlayer > m_ScoreOfOpponent)
                {
                    msgToPrint.Append(string.Format("The winner is {0}", m_PlayerName));
                }
                else if (m_ScoreOfPlayer < m_ScoreOfOpponent)
                {
                    msgToPrint.Append(string.Format("The winner is {0}", m_OpponentName));
                }
                else
                {
                    msgToPrint.Append("You managed to score the same points, It's a tie!");
                }

                msgToPrint.Append(Environment.NewLine);
                bool wantToPlayAgain = GameUserInterface.PrintRoundFinalMsg(msgToPrint);

                if (wantToPlayAgain)
                {
                    gameFlow();
                }
            }
        }
Example #6
0
 private void clearAndPrint()
 {
     Ex02.ConsoleUtils.Screen.Clear();
     GameUserInterface.printBoardToScreen(m_Game.GetBoard);
 }