示例#1
0
        public void Begin()
        {
            Clear();

            _uiMessageFactory.InputNameMessage();

            User user = new User();

            user.Name = Console.ReadLine();
            _playerManager.CreateUser(user.Name);

            selectedSubject      = SelectSubjectFromList();
            _wordListWithSubject = _wordManager.GetWordsWithSubject(selectedSubject);

            Word selectedWord = _randomUtils.SelectRandomWordFromList(_wordListWithSubject);

            _wordManager.IncreaseWordPlayed(selectedWord.Name);

            CreateHiddenWordInstance(selectedWord);
            _wordManager.AddWordToPlayedList(selectedWord);

            _uiMessageFactory.FirstGuessMessage();

            StringBuilder stringBuild = new StringBuilder();

            for (int i = 0; i < selectedWord.Name.Length; i++)
            {
                stringBuild.Append('_');
            }
            _uiMessageFactory.DisplayHangman(
                incorrectGuess,
                selectedWord.Name,
                _hiddenWordManager.GetGuessedLettersList(),
                _hiddenWordManager.GetCorrectLettersList());

            while (incorrectGuess < maxGuess && !isWordGuessedCorrectly)
            {
                string input = Console.ReadLine().ToUpper();
                foreach (var item in input)
                {
                    GuessLetter(item);
                }

                _uiMessageFactory.DisplayHangman(
                    incorrectGuess,
                    selectedWord.Name,
                    _hiddenWordManager.GetGuessedLettersList(),
                    _hiddenWordManager.GetCorrectLettersList());

                isWordGuessedCorrectly = CheckIfWordIsGuessedCorrectly(selectedWord.Name, stringBuild);
            }

            if (isWordGuessedCorrectly)
            {
                _uiMessageFactory.VictoryMessage();
            }
            else
            {
                _uiMessageFactory.DefeatMessage();
                _wordManager.IncreaseIncorrectCount(selectedWord.Name);
            }

            RemoveWordFromList(selectedWord);
            SaveScoreBoard(user, selectedWord);
        }