Exemple #1
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;
        }
Exemple #2
0
 public void OnEntry()
 {
     Tries                      = 0;
     CorrectAnswers             = 0;
     AnswersPerQuestion         = 4;
     QuestionsPerSet            = 2;
     SelectedDictionaryAnswer   = null;
     SelectedDictionaryQuestion = null;
     CurrentQuestionWord        = null;
     CurrentAnswerWords.Clear();
     _dictionaries         = _dao.GetAllDictionaries();
     _dictionariesQuestion = new CollectionViewSource()
     {
         Source = _dictionaries
     }.View;
     _dictionariesAnswer = new CollectionViewSource()
     {
         Source = _dictionaries
     }.View;
     _wordConnections    = _dao.GetAllWordConnections();
     _wordUserHistories  = _dao.GetAllHistoriesForUser(_currentUser);
     _availableQuestions = new List <IWord>();
     _currentQuestionSet = new List <IWord>();
 }