Exemplo n.º 1
0
        private void ConfirmAnswer()
        {
            var history = _wordUserHistories.FirstOrDefault(x => x.Language == SelectedDictionaryQuestion.Language &&
                                                            x.Word == CurrentQuestionWord.Text && x.UserId == _currentUser.Id);

            if (history == null)
            {
                history                  = _dao.CreateWordUserHistory();
                history.Language         = SelectedDictionaryQuestion.Language;
                history.Word             = CurrentQuestionWord.Text;
                history.UserId           = _currentUser.Id;
                history.TimesEncountered = 0;
                history.TimesRight       = 0;
            }
            if (_correctAnswers.Contains(SelectedAnswerWord))
            {
                CorrectAnswers      = _answeredCorrectly + 1;
                AnswerResultMessage = "Correct!\n";
                history.TimesRight++;
            }
            else
            {
                AnswerResultMessage = "Wrong!\n";
                foreach (var word in _correctAnswers)
                {
                    if (CurrentAnswerWords.Contains(word))
                    {
                        AnswerResultMessage += "Correct answer: '" + word.Text + "'.\n";
                        break;
                    }
                }
            }
            if (_currentQuestionSet.Count == 0)
            {
                AnswerResultMessage += "No more questions!";
            }
            Tries = _tries + 1;
            history.TimesEncountered++;
            _dao.SaveWordUserHistory(history);
            _answeredThisQuestion = true;
        }
Exemplo n.º 2
0
        private void NextQuestion()
        {
            AnswerResultMessage = "";
            CurrentQuestionWord = _currentQuestionSet.First();
            _currentQuestionSet.Remove(CurrentQuestionWord);
            _correctAnswers = SelectedDictionaryAnswer.Words.Where(x => AreWordsConnected(x, SelectedDictionaryAnswer.Language, CurrentQuestionWord, SelectedDictionaryQuestion.Language));
            CurrentAnswerWords.Clear();
            int  n = _answersPerQuestion;
            bool insertedCorrectAnswer = false;

            while (n > 0)
            {
                if ((!insertedCorrectAnswer && _random.Next(_answersPerQuestion) == 0) ||
                    (!insertedCorrectAnswer && n == 1))
                {
                    CurrentAnswerWords.Add(_correctAnswers.ElementAt(_random.Next(_correctAnswers.Count())));
                    insertedCorrectAnswer = true;
                    n--;
                }
                else
                {
                    IWord word;
                    do
                    {
                        word = SelectedDictionaryAnswer.Words.ElementAt(_random.Next(SelectedDictionaryAnswer.Words.Count));
                    } while (CurrentAnswerWords.Contains(word));
                    if (_correctAnswers.Contains(word))
                    {
                        insertedCorrectAnswer = true;
                    }
                    CurrentAnswerWords.Add(word);
                    n--;
                }
            }
            SelectedAnswerWord    = null;
            _answeredThisQuestion = false;
        }