コード例 #1
0
 private void PickQuestions()
 {
     CurrentQuestionGroup.Clear();
     while (CurrentQuestionGroup.Count < EachTimeQuestionsCount)
     {
         Random        random = new Random();
         QuestionModel temp   = AllQustions[random.Next(0, AllQustions.Count)];
         if (!CurrentQuestionGroup.Contains(temp))
         {
             CurrentQuestionGroup.Add(temp);
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Submits the current answer.
        /// </summary>
        private void SubmitAnswer()
        {
            if (string.IsNullOrEmpty(CurrentAnswer) ||
                CurrentQuestion == null)
            {
                // Do not evaluate an empty answer.
                return;
            }

            // Convert the answer to kana if necessary.
            if (CurrentQuestion.Question == SrsQuestionEnum.Reading)
            {
                CurrentAnswer = KanaHelper.RomajiToKana(CurrentAnswer);
            }

            // Determine if the answer is correct.
            bool success = IsAnswerCorrect();

            // Set the review state accordingly.
            // Other operations will be executed when we move on to another question.
            ReviewState = success ? SrsReviewStateEnum.Success : SrsReviewStateEnum.Failure;

            // Play audio if auto play enabled.
            if (CurrentQuestion.Question == SrsQuestionEnum.Reading &&
                CurrentQuestionGroup.IsVocab &&
                ((success && Properties.Settings.Default.AudioAutoplayMode.ShouldPlayOnSuccess()) ||
                 (!success && Properties.Settings.Default.AudioAutoplayMode.ShouldPlayOnFailure())))
            {
                AudioBusiness.PlayVocabAudio(CurrentQuestionGroup.Audio);
            }

            // If we have a failure: trigger the timer.
            if (ReviewState == SrsReviewStateEnum.Failure)
            {
                _canSubmit = false;
                DispatcherTimer timer = new DispatcherTimer();
                timer.Interval = FailureSubmitDelay;
                timer.Tick    += OnFailureSubmitTimerTick;
                timer.Start();
            }
            // If it was a success on the last question of the group, allow level up/down preview.
            else if (CurrentQuestionGroup.GetUnansweredQuestions().Count() == 1)
            {
                SrsLevelStore.Instance.IssueWhenLoaded(
                    () => {
                    DispatcherHelper.Invoke(() => {
                        PreviewNextLevel = GetUpdatedLevel(CurrentQuestionGroup);
                    });
                });
            }
        }
コード例 #3
0
        /// <summary>
        /// Processes the success/failure logic for the last answered question.
        /// Executed before getting to the next question.
        /// </summary>
        private void ProcessLastSubmission()
        {
            if (ReviewState == SrsReviewStateEnum.Success)
            {
                // Success. Set the question as answered.
                CurrentQuestion.IsAnswered = true;

                // If both questions of the group have been answered.
                if (!CurrentQuestionGroup.GetUnansweredQuestions().Any())
                {
                    SrsQuestionGroup group = CurrentQuestionGroup;

                    // Remove the group from the batch.
                    _currentBatch.Remove(group);

                    // Start the update group method after making sure the
                    // level store is finished loading.
                    SrsLevelStore.Instance.IssueWhenLoaded(
                        () => {
                        UpdateAnsweredGroup(group);
                    });

                    // Update the answered reviews count.
                    AnsweredReviewsCount++;

                    // Fill the batch to compensate for the removed group.
                    if (!IsWrappingUp)
                    {
                        FillCurrentBatch();
                    }
                    else if (_currentBatch.Count == 0)
                    {
                        StopSessionCommand.Execute(null);
                    }
                }
            }
            else if (ReviewState == SrsReviewStateEnum.Failure)
            {
                // Wrong answer.
                // Don't set the question as answered.
                // Set the group as wrong.
                CurrentQuestion.ParentGroup.IsWrong = true;
            }
        }