public static void Verify(ChalLine line, Button btn_verify, Button btn_next)
        {
            line.Chal.Cb_Answer.IsEnabled = false;

            int  score     = 0;
            bool isCorrect = false;

            if (line.Quest.Type == Model.Voc)
            {
                isCorrect = line.Chal.Cb_Answer.IsCorrect();
            }
            else if (line.Quest.Type == Model.Spell)
            {
                isCorrect = line.Chal.Txt_Spell.Text.ContainsInsensitive(line.Quest.Text);
            }

            if (isCorrect)
            {
                line.Chal.Grid_chal.Background = UtilWPF.Colour_Correct;
                score = 10;
            }
            else
            {
                line.Chal.Grid_chal.Background = UtilWPF.Colour_Incorrect;
            }

            var att = new AttemptVM(line.Quest.Id, score, DateTime.Now, line.Quest.Type);

            AttemptsControl.Insert(att);

            var updated_quest = QuestControl.Get(line.Quest.Type).First(x => x.Id == line.Quest.Id);

            line.Chal.Avg_w.Content   = updated_quest.Avg_week + "% (w)";
            line.Chal.Avg_m.Content   = updated_quest.Avg_month + "% (m)";
            line.Chal.Avg_all.Content = updated_quest.Avg_all + "% (all)";
            line.Chal.Tries.Content   = updated_quest.Tries.Count + " tries";

            foreach (var lbl in line.Chal.Quest_words)
            {
                if (line.Quest.Text.SplitSentence().Contains(lbl.Content.ToString()))
                {
                    lbl.FontWeight = FontWeights.Bold;
                }
            }

            TurnElemsVisible(line);
            btn_next.IsEnabled   = true;
            btn_verify.IsEnabled = false;
        }
Exemplo n.º 2
0
        public static (string, int) CheckAnswers(List <CellTemplate> cellList)
        {
            var total    = 0;
            var corrects = 0;

            foreach (var item in cellList)
            {
                if (item.Txt != null)
                {
                    item.Txt.IsReadOnly = true;
                    var answer = string.Empty;

                    if (!item.Txt.IsEmpty())
                    {
                        answer = item.Txt.Text;
                    }

                    var isCorrect = answer.Equals(item.Quest.Text, StringComparison.OrdinalIgnoreCase);
                    var score     = 0;

                    if (isCorrect)
                    {
                        score = 10;
                        item.Txt.Background = Brushes.LightGreen;
                        corrects            = corrects + 1;
                    }
                    else
                    {
                        item.Txt.Background = Brushes.LightSalmon;
                        item.Txt.ToolTip    = item.Quest.Text;
                    }

                    var vm = new AttemptVM(item.Quest.Id, score, DateTime.Now, item.Quest.Type);
                    AttemptsControl.Insert(vm);
                    total = total + 1;
                }
            }

            var percent_corrects = 0;

            if (corrects != 0)
            {
                percent_corrects = (int)Math.Round((double)(100 * corrects) / total);
            }

            return(percent_corrects + "% (" + corrects + " corrects)", percent_corrects);
        }