示例#1
0
        public IActionResult NewGame()
        {
            GameOptionsViewModel gameOptions = new GameOptionsViewModel();

            gameOptions.Difficulties = _difficultyRepository.AllDifficulties;
            gameOptions.Types        = _typeRepository.AllTypes;
            gameOptions.Categories   = WebService.GetCategories();

            return(View(gameOptions));
        }
示例#2
0
 private void CreatingQuizFromOptions(GameOptionsViewModel gameOptions, out Difficulty d, out Models.Type t)
 {
     d = _difficultyRepository.GetDifficultyById(System.Int32.Parse(gameOptions.SelectedDifficulty));
     t = _typeRepository.GetTypeById(System.Int32.Parse(gameOptions.SelectedType));
 }
示例#3
0
        public IActionResult PlayGame(GameOptionsViewModel gameOptions, bool newGame, int currentQuestion, int quizId, string response, string move, string responses)
        {
            if (newGame)
            {
                Difficulty  difficulty;
                Models.Type type;
                CreatingQuizFromOptions(gameOptions, out difficulty, out type);

                string apiUrl = WebService.CreateApiUrl(gameOptions.Count, difficulty, type, System.Int32.Parse(gameOptions.SelectedCategory));

                JsonQuiz jsonQuiz = WebService.GetQuizFromUrl(apiUrl);

                if (jsonQuiz == null)
                {
                    //return ErrorPageView(); NOT IMPLEMENTED YET
                    return(NotFound());
                }
                if (jsonQuiz.ResponseCode != 0)
                {
                    return(RedirectToAction("NewGame"));
                }

                Quiz quiz = CreateQuizModel(jsonQuiz);
                _quizRepository.InsertQuiz(quiz);

                Question question = quiz.Questions[0];

                QuizViewModel quizViewModel = new QuizViewModel()
                {
                    QuizId            = quiz.QuizId,
                    CurrentQuestion   = 0,
                    QuestionStatement = question.QuestionStatement,
                    Answers           = SortAllAnswers(question.IncorrectAnswers, question.CorrectAnswer),
                    Responses         = CreateEmptyList(quiz.Questions.Count()),
                    Category          = question.Category1,
                    Difficulty        = question.Difficulty.DifficultyName
                };

                return(View(quizViewModel));
            }
            else
            {
                Quiz quiz = _quizRepository.GetQuizById(quizId);

                List <string> tmpResponses = QuizViewModel.ResponsesFromJson(responses);
                tmpResponses[currentQuestion] = response;

                if (move == "next")
                {
                    if (currentQuestion < quiz.Questions.Count() - 1)
                    {
                        currentQuestion++;
                    }
                }
                if (move == "previous")
                {
                    if (currentQuestion > 0)
                    {
                        currentQuestion--;
                    }
                }

                Question      question      = quiz.Questions[currentQuestion];
                QuizViewModel quizViewModel = new QuizViewModel()
                {
                    QuizId            = quiz.QuizId,
                    CurrentQuestion   = currentQuestion,
                    QuestionStatement = question.QuestionStatement,
                    Answers           = SortAllAnswers(question.IncorrectAnswers, question.CorrectAnswer),
                    Responses         = tmpResponses,
                    Category          = question.Category1,
                    Difficulty        = question.Difficulty.DifficultyName
                };

                return(View(quizViewModel));
            }
        }