Example #1
0
 public void PlayTurn(string i_GuessFromUser)
 {
     if (m_NumOfLeftGuesses <= 0)
     {
         m_GameResult = eGameResult.Loss;
     }
     else if (!VerifyInputFromUser(i_GuessFromUser))
     {
         throw new ArgumentException();
     }
     else
     {
         m_GameResult = eGameResult.StillPlaying;
         eGuessLetter[] currentGuess         = StringToEGuessLetterArrayFormat(i_GuessFromUser);
         Turn           currentTurn          = new Turn(m_ComputerAnswer, currentGuess);
         int            cellToAddCurrentTurn = m_NumberOfTotalGuesses - m_NumOfLeftGuesses;
         m_TurnArray[cellToAddCurrentTurn] = currentTurn;
         m_NumOfLeftGuesses--;
         if (currentTurn.IsCorrect())
         {
             m_GameResult = eGameResult.Win;
         }
         else if (m_NumOfLeftGuesses == 0)
         {
             m_GameResult = eGameResult.Loss;
         }
     }
 }
Example #2
0
        public void GetBullsAndCows(List <T> i_Pins, out int o_Bulls, out int o_Cows)
        {
            o_Bulls = 0;
            o_Cows  = 0;

            for (int i = 0; i < k_LengthOfTheCombination; i++)
            {
                if (List <T> .Equals(i_Pins[i], m_SecretSequence[i]))
                {
                    o_Bulls++;
                }
                else if (m_SecretSequence.Contains(i_Pins[i]))
                {
                    o_Cows++;
                }
            }

            m_CurrentGuess++;
            if (m_CurrentGuess == m_TotalGuessesToPlay)
            {
                m_CurrentGameStatus = eGameStatus.Off;
            }

            if (o_Bulls == k_LengthOfTheCombination)
            {
                m_CurrentGameStatus = eGameStatus.Off;
                m_IsWin             = eGameResult.Win;
            }
        }
        public void GameOver(eGameResult i_Result)
        {
            DialogResult dialogResult;

            if (i_Result == eGameResult.Player1Win)
            {
                dialogResult = MessageBox.Show($@"{m_Player1.Name} Won! {Environment.NewLine} Another Round?", "Checker", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            }
            else if (i_Result == eGameResult.Player2Win)
            {
                dialogResult = MessageBox.Show($@"{m_Player2.Name} Won! {Environment.NewLine} Another Round?", "Checker", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            }
            else
            {
                dialogResult = MessageBox.Show($@"Tie! {Environment.NewLine} Another Round?", "Checker", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            }

            if (dialogResult == DialogResult.Yes)
            {
                calculateSumOfPointsForPlayers(ref m_Player1, ref m_Player2);
                m_MyChecker.ScorePlayer1 = m_Player1.NumOfPoints;
                m_MyChecker.ScorePlayer2 = m_Player2.NumOfPoints;

                OnAnotherRound?.Invoke(true, EventArgs.Empty);
            }
            else
            {
                m_MyChecker.Close();
            }
        }
Example #4
0
        public void Run()
        {
            Ex02.ConsoleUtils.Screen.Clear();
            Board.PrintBoard(null, r_LengthOfGuess, m_NumberOfTotalGuesses);
            m_GameResult = eGameResult.StillPlaying;
            while (m_NumOfLeftGuesses > 0)
            {
                string verifiedInputString = VerifyInputFromUser();

                if (verifiedInputString.Equals("Q"))
                {
                    m_GameResult = eGameResult.Abort;
                    break;
                }

                eGuessLetter[] currentGuess = getVerifyInputFromUser(verifiedInputString);

                Turn currentTurn          = new Turn(m_ComputerAnswer, currentGuess);
                int  cellToAddCurrentTurn = m_NumberOfTotalGuesses - m_NumOfLeftGuesses;
                m_TurnArray[cellToAddCurrentTurn] = currentTurn;
                Ex02.ConsoleUtils.Screen.Clear();
                Board.PrintBoard(m_TurnArray, r_LengthOfGuess, m_NumberOfTotalGuesses);
                if (currentTurn.IsCorrect())
                {
                    m_GameResult = eGameResult.Win;
                    break;
                }

                m_NumOfLeftGuesses--;
            }

            if (m_NumOfLeftGuesses == 0)
            {
                m_GameResult = eGameResult.Loss;
                Board.WriteLine(string.Format("The real soultion was {0} , sorry maybe next time.", m_ComputerAnswerStringFormat));
            }
        }