Esempio n. 1
0
        private void accpetButton_Click(object sender, EventArgs e)
        {
            byte o_PerefctHits;
            byte o_AlmostHIts;

            m_LogicManger.CountHitsOfGuess(out o_PerefctHits, out o_AlmostHIts, currentGameRow.GuessesList);
            getFedbackResult(o_PerefctHits, o_AlmostHIts);
            m_LogicManger.CheckGameStatus(out m_GameOver, m_CurrentTurn, m_NumberOfGuesses);
            enableCurrentGuessRow(currentGameRow.GuessesList, false);
            (sender as Button).Enabled = false;
            if (!m_GameOver)
            {
                m_CurrentTurn++;
                m_LogicManger.ColorsToPickWindow.PickedColoreSet.Clear();
                playNextStep();
            }
            else
            {
                exposeCoumputerRandomColors();
            }
        }
Esempio n. 2
0
        internal void RunGame()
        {
            bool   gameIsOn = true;
            string userInput;

            while (gameIsOn)
            {
                if (m_eGameStatus == eGameStatus.NewGame)
                {
                    Ex02.ConsoleUtils.Screen.Clear();
                    m_BullsAndCowsUI.WellcomeMsg();
                    m_BullsAndCowsUI.GetNumberOfGuesses();
                    m_BullsAndCowsUI.initialTable(m_NumberOfGuesses);
                    m_eGameStatus = eGameStatus.Play;
                    m_CurrentTurn = 0;
                }

                else if (m_eGameStatus == eGameStatus.Play)
                {
                    Ex02.ConsoleUtils.Screen.Clear();
                    m_BullsAndCowsUI.printTable();
                    if (m_eErrorStatus == eErrorStatus.FormatError)
                    {
                        m_BullsAndCowsUI.formatErrorMsg();
                    }
                    else if (m_eErrorStatus == eErrorStatus.syntaxError)
                    {
                        m_BullsAndCowsUI.syntaxErrorMsg();
                    }
                    else if (m_eErrorStatus == eErrorStatus.LogicError)
                    {
                        m_BullsAndCowsUI.LogicErrorMsg();
                    }

                    m_BullsAndCowsUI.PlayMsg();
                    m_eErrorStatus = eErrorStatus.NoError;
                    bool o_GuessIsVaild;
                    bool o_GuessInFormat;
                    userInput = m_BullsAndCowsUI.GetUserGuess(out o_GuessInFormat);
                    //inputIsVaildv put ture in o_guessIsVAILD if the input logic vaild, change game status otherwise
                    if (o_GuessInFormat)
                    {
                        m_BullsAndCowsLogic.inputIsVaild(m_ShrinkInput, out o_GuessIsVaild);

                        if (o_GuessIsVaild & o_GuessInFormat)
                        {
                            byte o_PerfectHits;
                            byte o_AlmostHits;
                            m_BullsAndCowsUI.storeToPinsColumn = userInput;
                            m_BullsAndCowsLogic.CountHitsOfGuess(out o_PerfectHits, out o_AlmostHits, m_ShrinkInput);
                            m_BullsAndCowsUI.storeToResultColumn(o_PerfectHits, o_AlmostHits);
                            m_CurrentTurn++;

                            //after storing the guess need to check if I won, or lost,or keep playing
                            m_BullsAndCowsLogic.checkGameStatus();
                        }
                    }
                }

                else if (m_eGameStatus == eGameStatus.QuitStatus)
                {
                    m_BullsAndCowsUI.GoodByeMsg();
                    gameIsOn = false;
                }

                else if (m_eGameStatus == eGameStatus.LoseStatus)
                {
                    m_BullsAndCowsUI.exposeComputerGuess();
                    Ex02.ConsoleUtils.Screen.Clear();
                    m_BullsAndCowsUI.printTable();
                    if (m_eErrorStatus == eErrorStatus.quitError)
                    {
                        Ex02.ConsoleUtils.Screen.Clear();
                        m_BullsAndCowsUI.printTable();
                        m_BullsAndCowsUI.quitErrorMsg();
                    }
                    else
                    {
                        m_BullsAndCowsUI.loseMsg();
                    }

                    //change status to new game or quit (N BUTTON)
                    m_BullsAndCowsUI.askToPlayAgain();
                }

                else if (m_eGameStatus == eGameStatus.WinStatus)
                {
                    Ex02.ConsoleUtils.Screen.Clear();
                    m_BullsAndCowsUI.printTable();

                    if (m_eErrorStatus == eErrorStatus.quitError)
                    {
                        Ex02.ConsoleUtils.Screen.Clear();
                        m_BullsAndCowsUI.printTable();
                        m_BullsAndCowsUI.quitErrorMsg();
                    }
                    else
                    {
                        m_BullsAndCowsUI.winMsg();
                    }
                    m_BullsAndCowsUI.askToPlayAgain();
                }
            }
        }