Esempio n. 1
0
        private void gameLoop()
        {
            string currentGuessStr = string.Empty;
            bool   shouldRunLoop   = true;
            bool   winning         = false;

            while (Guess.m_NumberOfGuesses < m_Board.Length)
            {
                Printer.PrintBoard(m_Board, m_ComputerLuckyPattern.Length);
                Printer.PrintMessage(0);
                while (shouldRunLoop)
                {
                    try
                    {
                        currentGuessStr = Console.ReadLine().Replace(" ", string.Empty).ToUpper();
                        shouldRunLoop   = !Guess.GuessValidation(currentGuessStr);
                    }
                    catch (Exception e)
                    {
                        Printer.PrintErrorMessage(e.Message + Messages.GetMessage(1));
                    }
                }

                if (currentGuessStr.ToUpper().Equals("Q"))
                {
                    Printer.EndOfGame();
                    Console.ReadLine();
                    break;
                }
                else
                {
                    shouldRunLoop = true;
                    m_Board[Guess.m_NumberOfGuesses] = new Guess(currentGuessStr);
                    Guess.m_NumberOfGuesses++;

                    if (currentGuessStr == m_ComputerLuckyPattern)
                    {
                        winning = true;
                        Printer.SuccessMode();
                        Printer.PrintBoard(m_Board, m_ComputerLuckyPattern.Length);
                        if (Guess.m_NumberOfGuesses > 1)
                        {
                            Printer.PrintFormatMessage(4, new List <string>()
                            {
                                Guess.m_NumberOfGuesses.ToString()
                            });
                        }
                        else
                        {
                            Printer.PrintBoard(m_Board, m_ComputerLuckyPattern.Length);
                            Printer.PrintMessage(10);
                        }

                        restart();
                        break;
                    }
                }
            }

            if (Guess.m_NumberOfGuesses == m_Board.Length && !winning)
            {
                Printer.FailureMode();
                Printer.PrintBoard(m_Board, m_ComputerLuckyPattern.Length);
                Printer.PrintErrorMessage(5);
                restart();
            }
        }