private async Task HandleActionButtonAsync()
        {
            if (currentAction == CurrentAction.ShowingRoundResult)
            {
                if (++currentRound >= TotalRounds)
                { //Showing final result
                    var dlg = new ResultDlg(answers)
                    {
                        Owner = this
                    };

                    if (dlg.ShowDialog() == true)
                    {
                        await RefreshAllWords();

                        //Update the list of clauses
                        clausesForTrainingList = clausesForTrainingList
                                                 .Union(dlg.Answers.Where(o => !String.IsNullOrEmpty(o.Word.Sound))
                                                        .Select(o => o.Word.Id))                                   //In case of new words (wrong answers)
                                                 .Except(dlg.Answers.Where(o => o.Deleted).Select(o => o.Word.Id)) //Deleted words
                                                 .ToList();

                        await StartTrainingAsync();
                    }
                    else
                    {
                        GoToStatistic = dlg.GoToStatistic; //"Command" retranslation
                        Close();
                    }
                }
                else
                {
                    await NextRoundAsync();
                }

                return;
            }

            Debug.Assert(currentAction == CurrentAction.WaitingForUserAnswer);

            if (IsAnswerCorrect() == AnswerCheckResult.Incorrect &&
                PrgSettings.Default.ListeningAllowOneMistake &&
                triesWereMade < 1)
            { //Give a second chance
                triesWereMade++;
                PlayErrorSound();

                return;
            }

            await ShowRoundResultAsync();
        }
Beispiel #2
0
        private async Task HandleActionButtonAsync()
        {
            if (currentAction == CurrentAction.ShowingRoundResult)
            {
                if (++currentRound >= TotalRounds)
                { //Showing final result
                    var dlg = new ResultDlg(answers)
                    {
                        Owner = this
                    };

                    if (dlg.ShowDialog() == true)
                    {
                        await RefreshAllWords();

                        //Update the list of clauses
                        clausesForTrainingList = clausesForTrainingList
                                                 .Except(dlg.Answers.Where(o => o.Deleted).Select(o => o.Word.Id)) //Deleted words
                                                 .ToList();

                        await StartTrainingAsync();
                    }
                    else
                    {
                        GoToStatistic = dlg.GoToStatistic;
                        Close();
                    }
                }
                else
                {
                    await NextRoundAsync();
                }

                return;
            }

            Debug.Assert(currentAction == CurrentAction.WaitingForUserAnswer);
            await ShowRoundResultAsync();
        }
Beispiel #3
0
        private async Task NextRoundAsync()
        {
            if (currentRound == TotalRounds)
            { //The training is over
                //Showing final result
                var dlg = new ResultDlg(answers)
                {
                    Owner = this
                };

                if (dlg.ShowDialog() == true)
                {
                    await RefreshAllWords();

                    //Update the list of clauses
                    clausesForTrainingList = clausesForTrainingList
                                             .Union(dlg.Answers.Select(o => o.Word.Id))                        //In case of new words (wrong answers)
                                             .Except(dlg.Answers.Where(o => o.Deleted).Select(o => o.Word.Id)) //Deleted words
                                             .ToList();

                    await StartTrainingAsync();
                }
                else
                {
                    GoToStatistic = dlg.GoToStatistic; //"Command" retranslation
                    Close();
                }

                return;
            }

            //Preparations for the round
            currentAction = CurrentAction.WaitingForUserAnswer;

            translationLbl.Visibility = yesNoBtnPanel.Visibility = Visibility.Visible;
            actionBtnPanel.Visibility = Visibility.Hidden;

            rightAnswerForRound = await dbFacade.GetClauseByIdAsync(wordsForTraining[currentRound]);

            answerTime = DateTime.UtcNow;

            Clause wrongAnswerForRound = await GetWrongAnswerForWordAsync(rightAnswerForRound);

            bool showWrongAnswer = (random.Next(100) < 50);

            //Set up the controls
            counterLbl.Text = $"{currentRound + 1}/{TotalRounds}";

            wordLbl.Text = rightAnswerForRound.Word;

            translationLbl.Text = showWrongAnswer ? MakeTranslationsString(wrongAnswerForRound.Translations)
                                                  : MakeTranslationsString(rightAnswerForRound.Translations);

            yesBtn.Tag = showWrongAnswer ? wrongAnswerForRound : rightAnswerForRound;
            noBtn.Tag  = showWrongAnswer ? rightAnswerForRound : wrongAnswerForRound;

            DecorateButton(yesBtn, ButtonDecoration.ResetDecoration);
            DecorateButton(noBtn, ButtonDecoration.ResetDecoration);

            yesBtn.IsEnabled = noBtn.IsEnabled = true;

            mainPBar.Value = 0;

            await PlaySoundAsync(rightAnswerForRound); //Auto play sound

            answerTimer.Start();
        }
Beispiel #4
0
        /// <summary>
        /// React on the given answer (considering <see cref="currentAction"/>).
        /// </summary>
        protected virtual async Task HandleAnswerAsync(int?answerId)
        {
            if (currentAction == CurrentAction.HidingAnswers)
            {
                if (answerId is null)
                { //Space button was pressed
                    currentAction = CurrentAction.WaitingForUserAnswer;
                    UpdateActionButtons();
                }

                return;
            }
            else if (currentAction == CurrentAction.ShowingRoundResult)
            {
                if (answerId is null)
                {     //Space button was pressed
                    if (++currentRound >= TotalRounds)
                    { //Showing final result
                        var dlg = new ResultDlg(answers)
                        {
                            Owner = this
                        };

                        if (dlg.ShowDialog() == true)
                        {
                            await RefreshAllWords();

                            //Update the list of clauses
                            clausesForTrainingList = clausesForTrainingList
                                                     .Union(dlg.Answers.Select(o => o.Word.Id))                        //In case of new words (wrong answers)
                                                     .Except(dlg.Answers.Where(o => o.Deleted).Select(o => o.Word.Id)) //Deleted words
                                                     .ToList();

                            await StartTrainingAsync();
                        }
                        else
                        {
                            GoToStatistic = dlg.GoToStatistic; //"Command" retranslation
                            Close();
                        }
                    }
                    else
                    {
                        await NextRoundAsync();
                    }
                }
                else //An answer button
                {
                    await PlaySoundAsync(Enumerable.Range(0, AnswersPerRound)
                                         .Select(o => (Clause)GetAnswerButton(o).Tag)
                                         .Single(o => o.Id == answerId));
                }

                return;
            }

            Clause givenAnswer = null;

            //Showing result
            foreach (Button btn in Enumerable.Range(0, AnswersPerRound).Select(o => GetAnswerButton(o)))
            {
                var clause = (Clause)btn.Tag;

                if (clause.Id == answerId)
                { //The pressed by the user button
                    givenAnswer = clause;

                    if (answerId == rightAnswerForRound.Id)
                    {
                        DecorateButton(btn, ButtonDecoration.UserRightAnswer);
                    }
                    else
                    {
                        DecorateButton(btn, ButtonDecoration.UserWrongAnswer);
                    }
                }
                else if (clause.Id == rightAnswerForRound.Id)
                {
                    DecorateButton(btn, ButtonDecoration.RightAnswer);
                }
                else
                {
                    DecorateButton(btn, ButtonDecoration.ResetDecoration);
                }
            }

            if (answerId is null)
            {
                DecorateButton(actionButton, ButtonDecoration.UserWrongAnswer);
            }

            //Collect answer info
            await SaveAnswerAsync(new TestAnswer {
                Word        = rightAnswerForRound,
                GivenAnswer = givenAnswer,
                Correct     = (answerId == rightAnswerForRound.Id),
                Time        = DateTime.UtcNow - answerTime
            });

            currentAction = CurrentAction.ShowingRoundResult;
            UpdateActionButtons();

            ShowRightAnswerData();

            //Capture the value for this method cuz rightAnswerForRound could be changed while the method running
            Clause rightAnswerForRoundCaptured = rightAnswerForRound;

            if (answerId != null && answerId != rightAnswerForRoundCaptured.Id)
            {
                PlayErrorSound();
                await Task.Delay(500);
            }

            await PlaySoundAsync(rightAnswerForRoundCaptured);
        }