Exemplo n.º 1
0
        public ActionResult GameRound(GameRoundViewModel viewModel)
        {
            var game = gameRepository.Find(viewModel.Id);

            if (game == null || !game.HasPlayer(User.Identity.Name))
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                foreach (var playerScore in viewModel.PlayerScores)
                {
                    game.SetRoundScore(viewModel.Number, playerScore.UserName, playerScore.Score);
                }

                gameRepository.Update(game);
                gameRepository.Save();

                if (viewModel.Number < game.GetHoleCount())
                {
                    return(RedirectToAction("GameRound", new { id = viewModel.Id, number = viewModel.Number + 1 }));
                }
                return(RedirectToAction("Details", new { id = viewModel.Id }));
            }

            return(View(viewModel));
        }
Exemplo n.º 2
0
        public IActionResult StartGameRound(CategoriesViewModel categories)
        {
            if (categories.AllCategories.TrueForAll(a => !a.Chosen))
            {
                categories.ErrorMessage = "Wählen Sie mindestens eine Kategorie aus.";
                return(View("ChooseCategories", categories));
            }

            var categoryIds        = categories.AllCategories.Where(a => a.Chosen).Select(a => a.CategoryId);
            var questions          = _gameHelper.GetQuestions(categoryIds);
            var questionsViewModel = questions.Select(a => new QuestionViewModel
            {
                QuestionId = a.QuestionId,
                Question   = a.Question,
                Answers    = _gameHelper.GetAnswers(a.QuestionId).ToList(),
                PercentageOfCorrectlyAnswered = a.AnsweredCorrectlyPercentage
            });

            var gameRound = new GameRoundViewModel
            {
                Categories      = categories.AllCategories.Where(a => a.Chosen).ToList(),
                GameBegin       = DateTime.Now,
                Score           = 0,
                QuestionsToPlay = questionsViewModel.ToList()
            };

            _gameHelper.SetNextQuestion(gameRound);

            return(View("GameRound", gameRound));
        }
Exemplo n.º 3
0
        private static GameRoundViewModel GetGameRoundViewModel(Game game, int number)
        {
            var gameRoundViewModel = new GameRoundViewModel()
            {
                Id     = game.Id,
                Number = number
            };

            foreach (var scorecard in game.Scorecards)
            {
                var round = scorecard.GetRound(number);
                gameRoundViewModel.AddPlayer(scorecard.GetUserName(), round.Score);
            }
            return(gameRoundViewModel);
        }
Exemplo n.º 4
0
        public bool SaveGame(GameRoundViewModel viewModel)
        {
            var requestModel = new SaveGameRequestModel
            {
                Score      = viewModel.Score,
                GameEnd    = viewModel.GameEnd,
                PlayerName = viewModel.PlayerName,
                GameBegin  = viewModel.GameBegin,
                Categories = viewModel.Categories.Select(a => new CategoryModel
                {
                    CategoryId = a.CategoryId
                }).ToList()
            };
            var content = JsonConvert.SerializeObject(requestModel);

            return(_webserviceProvider.PostDataFromWebService <bool>(Controllers.WhoWantsToBeAMillionaire.ToString(), "SaveGame", content));
        }
Exemplo n.º 5
0
        public IActionResult GameRound(GameRoundViewModel gameRoundViewModel)
        {
            ModelState.Clear();
            var index = gameRoundViewModel.IndexOfSelectedAnswer;

            if (!gameRoundViewModel.QuestionForTheRound.Answers[index].Correct)
            {
                return(RedirectToAction("Home"));
            }

            if (gameRoundViewModel.QuestionsToPlay.Count == 0 || !string.IsNullOrEmpty(Request.Form["End"]))
            {
                gameRoundViewModel.GameEnd = DateTime.Now;
                return(View("Winner", gameRoundViewModel));
            }
            _gameHelper.SetNextQuestion(gameRoundViewModel);

            return(View(gameRoundViewModel));
        }
Exemplo n.º 6
0
        public GameRoundViewModel FiftyFiftyJoker(GameRoundViewModel viewModel)
        {
            var answers = _gameHelper.Joker(viewModel.QuestionForTheRound.QuestionId);

            viewModel.JokerUsed = true;

            var newAnswers = viewModel.QuestionForTheRound.Answers.Select(a => new AnswerModel
            {
                AnswerId      = a.AnswerId,
                Answer        = a.Answer,
                Correct       = a.Correct,
                QuestionId    = a.QuestionId,
                DisableAnswer = answers.Any(b => b.AnswerId == a.AnswerId)
            });

            viewModel.QuestionForTheRound.Answers = newAnswers.ToList();

            return(viewModel);
        }
Exemplo n.º 7
0
        public IActionResult ShowResults(GameRoundViewModel viewModel)
        {
            ModelState.Clear();
            if (!string.IsNullOrEmpty(Request.Form["Joker"]))
            {
                viewModel = FiftyFiftyJoker(viewModel);
                return(View("GameRound", viewModel));
            }

            var index = viewModel.IndexOfSelectedAnswer;

            var correct = viewModel.QuestionForTheRound.Answers[index].Correct;

            _gameHelper.SaveQuestionAnswer(correct, viewModel.QuestionForTheRound.QuestionId);
            if (correct)
            {
                viewModel.Score += 30;
            }

            return(View(viewModel));
        }
Exemplo n.º 8
0
 public IActionResult SaveGame(GameRoundViewModel viewModel)
 {
     _gameHelper.SaveGame(viewModel);
     return(RedirectToAction("Home"));
 }
Exemplo n.º 9
0
 public void SetNextQuestion(GameRoundViewModel gameRound)
 {
     gameRound.QuestionForTheRound = gameRound.QuestionsToPlay.First();
     gameRound.QuestionsToPlay.Remove(gameRound.QuestionForTheRound);
 }