Exemplo n.º 1
0
        public IActionResult Index(string wordGuess)
        {
            var str = HttpContext.Session.GetString(key);

            _game = JsonConvert.DeserializeObject <HackingGameViewModel>(str);
            int correctLetters;

            _guess = wordGuess.ToUpper();

            if (_game.WinningWord == _guess)
            {
                return(RedirectToAction("Won"));
            }
            else
            {
                _game.GuessesLeft -= 1;
                str = JsonConvert.SerializeObject(_game);
                HttpContext.Session.SetString(key, str);

                var wordChecker = new WordChecker();
                correctLetters       = wordChecker.GetCorrectLetters(_guess, _game);
                _game.CorrectLetters = correctLetters;

                if (_game.GuessesLeft > 0)
                {
                    return(View(_game));
                }
                else
                {
                    return(RedirectToAction("Lost"));
                }
            }
        }