Ejemplo n.º 1
0
        public void StartHangMan()
        {
            bool replay = true;

            while (replay)
            {
                Console.Clear();

                var topic = TopicSelection();

                var word = _manageDb.SelectWordsListToRandom(topic, topicNumber);
                if (word == null)
                {
                    _messagesRepository.NoWordLeftMessage();
                }
                else
                {
                    _hiddenWordManager = new HiddenWordManager(ltName, ltCity, country, furniture);
                    bool guessingAllowed = true;
                    _messagesRepository.HangmanPictureMessage(beginLives);
                    Console.WriteLine();
                    Console.WriteLine(_hiddenWordManager.GetHiddedWordStructure());

                    while (guessingAllowed)
                    {
                        _guess = new Guess(_messagesRepository.WordInputMessage(), _hiddenWordManager);

                        if (_guess.IsWordGuessed)
                        {
                            SelectedWordGuessMechanics(topicNumber);
                            guessingAllowed = false;
                        }
                        else
                        {
                            _guess.CheckSelectedWordIsCorrect(topicNumber);

                            if (_hiddenWordManager.IncorrectGuesesCount == maxLives)
                            {
                                _messagesRepository.HangmanPictureMessage(maxLives);
                                _messagesRepository.LostGameMessage(word.Text);
                                guessingAllowed = false;
                            }
                            else
                            {
                                Console.Clear();
                                _messagesRepository.HangmanPictureMessage(_hiddenWordManager.IncorrectGuesesCount);
                                _messagesRepository.IncorrectLettersListMessage(_hiddenWordManager.HiddenWord.IncorrectGueses);

                                Console.WriteLine(_hiddenWordManager.GetHiddedWordStructure());
                                if (!_hiddenWordManager.HasHiddenLetters)
                                {
                                    _messagesRepository.WinGameMessage(word.Text);
                                    guessingAllowed = false;
                                }
                            }
                        }
                    }
                }
                _manageDb.RemoveWordFromSeletedWordsList(topicNumber);
                SelectPlayerScoreBoard(topicNumber);
                _playerManager.AddPlayerScore(SelectPlayerScoreBoard(topicNumber));
                replay = _messagesRepository.RepeatGameMessage();
            }
        }