Пример #1
0
 private void initGame(int i_NumberOfGuesses)
 {
     m_Board = new Board(i_NumberOfGuesses);
     m_Board.PrintBoard();
     m_Letters = new RangeOfLetters();
     setRandomSolution();
     m_NewUserGuess = new UserGuess(k_SizeOfGuesses, m_Letters.m_ListOfLetterToChoose);
 }
Пример #2
0
        private void runGame()
        {
            bool needToCheckDesireOfUserForExitStatus = false;

            Console.WriteLine("Please type your next guess <A B C D> or 'Q' to quit");
            for (int theCurrentGuess = 0; theCurrentGuess <= m_NumberOfGuesses; theCurrentGuess++)
            {
                bool theUserLose = (theCurrentGuess == m_NumberOfGuesses);
                if (theUserLose)
                {
                    Console.WriteLine("No more Guesses allowed. You Lost.");
                    needToCheckDesireOfUserForExitStatus = true;
                    break;
                }

                m_NewUserGuess.UpdateGuessFromUser(m_NewUserGuess, m_RandomSolution);
                if (m_NewUserGuess.WishToQuit)
                {
                    Console.WriteLine("You choose to quit the game, thanks for participate, Bye Bye!");
                    break;
                }

                m_Board.AddNewBoardLine(m_NewUserGuess.GetGuess(), m_NewUserGuess.GetFeedBack());
                m_Board.PrintBoard();

                if (m_NewUserGuess.Win)
                {
                    StringBuilder winMessege = new StringBuilder("You guessed after ");
                    winMessege.Append(theCurrentGuess);
                    winMessege.Append(" steps!");
                    Console.WriteLine(winMessege);
                    needToCheckDesireOfUserForExitStatus = true;
                    break;
                }

                bool keepOnPlaying = theCurrentGuess + 1 < m_NumberOfGuesses;
                if (keepOnPlaying)
                {
                    Console.WriteLine("Please type your next guess <A B C D> or 'Q' to quit");
                }
            }

            if (needToCheckDesireOfUserForExitStatus)
            {
                bool userWantstoPlay = checkTheDesireOfTheUserForNext();
                if (!userWantstoPlay)
                {
                    Console.WriteLine("You choose to end the game, thanks for participate, Bye Bye!");
                    Console.ReadLine();
                }

                else
                {
                    StartGame();
                }
            }
        }