Ejemplo n.º 1
0
        public void Begin()
        {
            var userName = _messageFactory.LoginMessage();
            var user     = _playerManager.GetByUserName(userName);

            if (user == null)
            {
                var key = _playerManager.Add(new Player {
                    Name = userName
                });
                user = _playerManager.Get(key);
            }
            _messageFactory.PlayerStatisticsMessage(user);
            bool         kartoti          = true;
            List <Words> PanaudotiZodziai = new List <Words>()
            {
                null
            };

            while (kartoti)
            {
                Console.Clear();
                var tema  = RenkuosiTema();
                var zodis = RandomZodzioParinkimas(tema, PanaudotiZodziai);
                if (zodis == null)
                {
                    Console.WriteLine("Temoje nebera zodziu, ar norite rinktis kita tema t/n");
                }
                else
                {
                    _hiddenWordManager = new HiddenWordManager(zodis);
                    bool leidziamaSpeti = true;
                    panaudotiZodziai.Add(zodis);
                    _messageFactory.KartuvesPictureMessage(0);
                    Console.WriteLine();
                    Console.WriteLine(_hiddenWordManager.GetHiddenWordsStructure());
                    while (leidziamaSpeti)
                    {
                        string spejimas      = _messageFactory.WordInputMessage();
                        bool   arSpetasZodis = ArSpetasZodis(spejimas);
                        if (arSpetasZodis)
                        {
                            bool arTeisinga = ArZodisTeisingas(zodis.Text, spejimas);

                            if (arTeisinga)
                            {
                                _messageFactory.WinMessage(zodis.Text);
                                guessWholeWord = _hiddenWordManager.HiddenWords.HiddenLetterCount;
                            }
                            else
                            {
                                _messageFactory.KartuvesPictureMessage(gyvybiuKiekis);
                                _messageFactory.LostMessage(zodis.Text);
                            }
                            leidziamaSpeti = false;
                        }
                        else
                        {
                            bool arBuvoSpeta = _hiddenWordManager.HiddenWords.IncorrectGuesses.Contains(spejimas);
                            if (!arBuvoSpeta)
                            {
                                _hiddenWordManager.CheckLetter(spejimas);
                            }
                            if (_hiddenWordManager.HiddenWords.IncorrectGuesses.Count == gyvybiuKiekis)
                            {
                                _messageFactory.KartuvesPictureMessage(gyvybiuKiekis);
                                _messageFactory.LostMessage(zodis.Text);
                                leidziamaSpeti = false;
                            }
                            else
                            {
                                Console.Clear();
                                _messageFactory.KartuvesPictureMessage(_hiddenWordManager.HiddenWords.IncorrectGuesses.Count);
                                _messageFactory.IncorrectLettersListMessage(_hiddenWordManager.HiddenWords.IncorrectGuesses);
                                Console.WriteLine(_hiddenWordManager.GetHiddenWordsStructure());
                                if (_hiddenWordManager.HiddenWords.HiddenLetterCount == 0)
                                {
                                    _messageFactory.WinMessage(zodis.Text);
                                    _messageFactory.PlayerStatisticsMessage(user);
                                    leidziamaSpeti = false;
                                }
                            }
                        }
                    }
                    _playerManager.AddScoreBoards(GetScoreBoard(zodis, user.PlayerId));
                    //nors ir atnaujinu duomenu baze cia
                }
                guessWholeWord = 0;
                //bet visada atspauzdina senos duomenu bazes duomenis, neissiaiskinau kodel taip yra
                _messageFactory.PlayerStatisticsMessage(user);
                kartoti = _messageFactory.RepeatGameMessage();
            }
        }
Ejemplo n.º 2
0
        public void Begin()
        {
            var userName = _massageFactory.LoginMesage();
            var user     = _playerManager.GetByUserName(userName);

            if (user == null)
            {
                var key = _playerManager.Add(new Player {
                    Name = userName
                });
                user = _playerManager.Get(key);
            }
            _massageFactory.PlayerStatisticsMessage(user);

            bool kartoti = true;

            while (kartoti)
            {
                Console.Clear();
                var tema  = SelectSubject();
                var zodis = AtsitiktinisZodzioPasirinkimas(tema);
                if (zodis == null)
                {
                    Console.WriteLine("Temoje nebėra žodžiu, ar norite rinktis kitą temą T/N");
                }
                else
                {
                    _hiddenWordManager = new HiddenWordManager(zodis);
                    bool leidziamaSpeti = true;
                    panaudotiZodziai.Add(zodis);
                    _massageFactory.HangmanPictureMessage(0);
                    Console.WriteLine();
                    Console.WriteLine(_hiddenWordManager.GetHiddedWordStructure());
                    while (leidziamaSpeti)
                    {
                        string spejimas      = _massageFactory.WordInputMessage();
                        bool   arSpetasZodis = ArSpetasZodis(spejimas);
                        if (arSpetasZodis)
                        {
                            bool arTeisinga = ArZodisTeisingas(zodis.Text, spejimas);
                            if (arTeisinga)
                            {
                                _massageFactory.WinGameMessage(zodis.Text);
                            }
                            else
                            {
                                _massageFactory.HangmanPictureMessage(gyvybiuKiekis);
                                _massageFactory.LostGameMessage(zodis.Text);
                            }
                            leidziamaSpeti = false;
                        }
                        else
                        {
                            bool arBuvoSpeta = _hiddenWordManager.HiddenWord.IncorrectGuesses.Contains(spejimas);
                            if (!arBuvoSpeta)
                            {
                                _hiddenWordManager.CheckLetter(spejimas);
                            }
                            if (_hiddenWordManager.HiddenWord.IncorrectGuesses.Count == gyvybiuKiekis)
                            {
                                _massageFactory.HangmanPictureMessage(gyvybiuKiekis);
                                _massageFactory.LostGameMessage(zodis.Text);
                                leidziamaSpeti = false;
                            }
                            else
                            {
                                Console.Clear();
                                _massageFactory.HangmanPictureMessage(_hiddenWordManager.HiddenWord.IncorrectGuesses.Count);
                                _massageFactory.IncorrectLettersListMessage(_hiddenWordManager.HiddenWord.IncorrectGuesses);
                                Console.WriteLine(_hiddenWordManager.GetHiddedWordStructure());
                                if (_hiddenWordManager.HiddenWord.HiddenLetterCount == 0)
                                {
                                    _massageFactory.WinGameMessage(zodis.Text);
                                    leidziamaSpeti = false;
                                }
                            }
                        }
                    }
                }
                _playerManager.AddScoreBoard(GetScoreBoard(zodis, user.PlayerId));

                kartoti = _massageFactory.RepeatGameMessage();
            }
        }