Exemple #1
0
        private async void Answer(object sender, EventArgs args, RecyclerView QuestionsRecView)
        {
            //if correct
            var userAns = Tickets.ElementAt(Position).Answers.FirstOrDefault(o => o.Ans == (sender as TextView).Text);

            (sender as TextView).SetBackgroundColor(userAns.Correct ? Color.Green : Color.Red);

            //if not correct
            QuestionsRecView.GetChildAt(Tickets.ElementAt(Position).Answers.IndexOf(Tickets.ElementAt(Position).Answers.First(o => o.Correct))).FindViewById <TextView>(Resource.Id.AnsTxt).SetBackgroundColor(Color.Green);

            //add user answer
            Answers.Add(userAns.Ans);

            //if not correct
            //correct or incorect count detect
            _ = Tickets.ElementAt(Position).Answers.FirstOrDefault(o => o.Ans == (sender as TextView).Text).Correct ? CorrectAns++ : FailedAns++;

            //disable all answers
            for (int i = 0; i < QuestionsRecView.ChildCount; i++)
            {
                QuestionsRecView.GetChildAt(i).FindViewById <TextView>(Resource.Id.AnsTxt).Enabled = false;
            }

            //cor ans
            CorAns.Text = CorrectAns.ToString();
            //incor ans
            FilAns.Text = FailedAns.ToString();

            // if incorect answers limit set limit -> int MaxIncorectCount = 3 default
            if (FailedAns == MaxIncorrectCount)
            {
                Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this);
                // alert.SetTitle("არადა კაი იყო 😁");
                alert.SetMessage($"შენ ვერ ჩააბარე გამოცდა იმითომ რომ {MaxIncorrectCount} შეკითხვას გაეცი არასწორი პასუხი");

                Dialog dialog = alert.Create();
                dialog.Show();
            }

            Position++;
            NextQuestion.Text = (Position + 1).ToString();

            if (AutoChange.Checked)
            {
                TicketPager.SetCurrentItem(Position, true);
            }

            if (Position == TicketsCount)
            {
                await new AnsweredService().SaveUserAnswersAsync(Tickets, Answers);

                var endUi = new Intent(this, typeof(EndActivity));
                endUi.PutExtra("TicketsCount", TicketsCount);
                StartActivity(endUi);

                ClearUi();
            }
        }
Exemple #2
0
        public bool IsNumericCorrect(string userAnswer, string correctAnswer)// to match numeric values
        {
            bool    result = false;
            decimal selectedAns;
            decimal CorrectAns;
            bool    isSelectedAnsNumeric = decimal.TryParse(correctAnswer, out CorrectAns);
            bool    isCorrectAnsNUmeric  = decimal.TryParse(userAnswer, out selectedAns);

            //Check if GivenAnswer and DB Correct answer is numeric/decimal or Not
            if (correctAnswer.Contains("+") && !userAnswer.Contains("+"))  //  check if correct answer contains + sign then check in answer given for + sign also
            {
                result = false;
            }
            if (isCorrectAnsNUmeric && isSelectedAnsNumeric)  // match the numeric value
            {
                selectedAns = Decimal.Parse(selectedAns.ToString("0.0000"));
                CorrectAns  = Decimal.Parse(CorrectAns.ToString("0.0000"));
                result      = selectedAns.Equals(CorrectAns);
            }
            return(result);
        }