Пример #1
0
        /// <summary>
        /// Updates score, stack and promotes or demotes the card.
        /// </summary>
        /// <param name="promote">if set to <c>true</c> [promote].</param>
        /// <param name="result">The result.</param>
        /// <remarks>Documented by Dev02, 2008-04-23</remarks>
        private void PromoteDemoteCard(ref bool promote, AnswerResult result, string answer, int correctSynonyms, bool overrideSynonyms, bool overrideTyping)
        {
            if (currentCardID >= 0)
            {
                int old_box, new_box;       //Important for the DB-LogEntry
                bool canceledDemote = overrideSynonyms;
                new_box = old_box = user.Dictionary.Cards.GetCardByID(currentCardID).BaseCard.Box;

                if (user.Dictionary.LearningBox == 0) //grade card
                {
                    //show confirm demote dialog
                    if (!promote && user.Dictionary.Settings.ConfirmDemote.GetValueOrDefault())
                    {
                        UserGradingDialogEventArgs args = new UserGradingDialogEventArgs(user.Dictionary, currentCardID, UserGradingDialogEventArgs.GradingDialogKind.ConfirmDemote);
                        OnUserDialog(args);
                        promote = args.promote;

                        if (promote)
                            canceledDemote = true;
                    }

                    if (overrideTyping)
                        canceledDemote = true;

                    //promote/demote card
                    if (promote)
                    {
                        user.Dictionary.PromoteCard(currentCardID);
                        new_box = user.Dictionary.Cards.GetCardByID(currentCardID).BaseCard.Box;
                    }
                    else
                    {
                        user.Dictionary.DemoteCard(currentCardID);
                        new_box = user.Dictionary.Cards.GetCardByID(currentCardID).BaseCard.Box;
                    }

                    if (user.Dictionary.Score > user.Dictionary.Highscore)
                        user.Dictionary.Highscore = user.Dictionary.Score;
                }
                else
                    user.Dictionary.CardUsed(currentCardID);    //only set the card used timestamp

                //add card to stack (important to be the last step since it triggers the cardstack_changed event)
                cardStack.Push(new StackCard(
                    user.Dictionary.Cards.GetCardByID(currentCardID).BaseCard,
                    result,
                    promote,
                    user.Dictionary.CurrentQueryDirection,
                    user.Dictionary.LearnMode,
                    currentCardAsked,
                    currentCardAnswered,
                    user.Dictionary.Cards.GetCardByID(currentCardID).BaseCard.Question.Culture,
                    user.Dictionary.Cards.GetCardByID(currentCardID).BaseCard.Answer.Culture,
                    answer, old_box, new_box, canceledDemote, user.Dictionary, correctSynonyms));
            }
        }
Пример #2
0
        /// <summary>
        /// Grades the Text answer.
        /// </summary>
        /// <param name="args">The <see cref="MLifter.BusinessLayer.UserInputSubmitTextEventArgs"/> instance containing the event data.</param>
        /// <param name="result">The result (optional).</param>
        /// <returns>Promote or Demote.</returns>
        /// <remarks>Documented by Dev02, 2008-04-23</remarks>
        private bool GradeTextAnswer(UserInputSubmitTextEventArgs args, out AnswerResult result, out bool overrideSynonyms, out bool overrideTyping)
        {
            bool correct = args.correctsynonyms > 0;
            result = correct ? AnswerResult.Correct : AnswerResult.Wrong;

            overrideSynonyms = overrideTyping = false;

            //[ML-1331] Textbox counts synonyms somethimes wrong: following lines were wrong:
            //  else if (user.Dictionary.Settings.GradeSynonyms.FirstKnown.Value)  promotesynonyms = args.correctsynonyms >= 1;
            //  else if (user.Dictionary.Settings.GradeSynonyms.OneKnown.Value)   promotesynonyms = args.correctfirstsynonym;
            // ... were wrong

            // Grade Synonyms
            bool promotesynonyms = true;
            if (args.synonyms > 1 && args.correctsynonyms < args.synonyms)
            {
                if (user.Dictionary.Settings.GradeSynonyms.AllKnown.Value)
                    promotesynonyms = args.synonyms == args.correctsynonyms;
                else if (user.Dictionary.Settings.GradeSynonyms.HalfKnown.Value)
                    promotesynonyms = args.synonyms > 0 ? 2 * args.correctsynonyms >= args.synonyms : false;
                else if (user.Dictionary.Settings.GradeSynonyms.FirstKnown.Value)
                    promotesynonyms = args.correctfirstsynonym;
                else if (user.Dictionary.Settings.GradeSynonyms.OneKnown.Value)
                    promotesynonyms = args.correctsynonyms >= 1;
                else if (user.Dictionary.Settings.GradeSynonyms.Prompt.Value)
                {
                    UserGradingDialogEventArgs e = new UserGradingDialogEventArgs(user.Dictionary, currentCardID, UserGradingDialogEventArgs.GradingDialogKind.GradeSynonym);
                    OnUserDialog(e);
                    overrideSynonyms = promotesynonyms = e.promote;
                }
            }

            // Grade Typing
            bool promotetyping = true;
            if (args.typingerrors > 0 && !overrideSynonyms)
            {
                if (user.Dictionary.Settings.GradeTyping.AllCorrect.Value)
                    promotetyping = false;
                else if (user.Dictionary.Settings.GradeTyping.HalfCorrect.Value)
                    promotetyping = args.answer.Length > 0 ? 2 * args.typingerrors < args.answer.Length : false;
                else if (user.Dictionary.Settings.GradeTyping.NoneCorrect.Value)
                    promotetyping = true;
                else if (user.Dictionary.Settings.GradeTyping.Prompt.Value)
                {
                    UserGradingDialogEventArgs e = new UserGradingDialogEventArgs(user.Dictionary, currentCardID, UserGradingDialogEventArgs.GradingDialogKind.GradeTypo);
                    OnUserDialog(e);
                    overrideTyping = promotetyping = e.promote;
                }
            }

            //final decision about promoting
            bool promote = correct && promotesynonyms && promotetyping;
            if (overrideSynonyms)
                promote = promotesynonyms;
            if (overrideTyping)
                promote = promotetyping;

            if (correct && !promote)
                result = AnswerResult.Almost;

            return promote;
        }