/** * this method handles displaying question data on the UI * @param questions - the list of questions attempted by user in that stage * @param correct - whether user got the questions correct or wrong */ public void instantiateQuestions(Dictionary <string, int> questions, bool correct) { foreach (KeyValuePair <string, int> question in questions) { string[] questionNumber = question.Key.Split('_'); int indexToAccess = int.Parse(questionNumber[0]); QuestionsAndAnswers questionToAccess = questionsList[indexToAccess]; GameObject newEntry = Instantiate(entryTemplate, entryContainer); TextMeshProUGUI[] texts = newEntry.GetComponentsInChildren <TextMeshProUGUI>(); texts[0].text = questionToAccess.Question; texts[1].text = "a) " + questionToAccess.Answers[0]; texts[2].text = "b) " + questionToAccess.Answers[1]; texts[3].text = "c) " + questionToAccess.Answers[2]; texts[4].text = "d) " + questionToAccess.Answers[3]; int correctIndex = questionToAccess.CorrectAnswer; texts[correctIndex].color = Color.green; string correctStr = ""; if (correct) { GameObject wrong = newEntry.transform.GetChild(7).gameObject; wrong.SetActive(false); correctStr = "Correct"; } else { GameObject tick = newEntry.transform.GetChild(6).gameObject; tick.SetActive(false); correctStr = "Wrong"; } texts[5].text = "Number of Attempts: " + question.Value.ToString() + " | Score: " + correctStr; } }
/** * Displays the different options for the answer on the UI panel. * * @param qna a QuestionsAndAnswers */ public void SetAnswers(QuestionsAndAnswers qna) { Ans1.GetComponentInChildren <TMPro.TextMeshProUGUI>().text = qna.Answers[0]; Ans2.GetComponentInChildren <TMPro.TextMeshProUGUI>().text = qna.Answers[1]; Ans3.GetComponentInChildren <TMPro.TextMeshProUGUI>().text = qna.Answers[2]; Ans4.GetComponentInChildren <TMPro.TextMeshProUGUI>().text = qna.Answers[3]; switch (qna.CorrectAnswer) { case 1: Ans1.GetComponent <CorrectCheck>().isCorrect = true; break; case 2: Ans2.GetComponent <CorrectCheck>().isCorrect = true; break; case 3: Ans3.GetComponent <CorrectCheck>().isCorrect = true; break; case 4: Ans4.GetComponent <CorrectCheck>().isCorrect = true; break; } }
/** * Request quesions from Firebase database with the appropriate difficulty. * * @param levelRequested difficulty for requested questions */ private IEnumerator RequestForQuestions(string levelRequested, string quizId, System.Action <List <QuestionsAndAnswers> > callback) { var DBTask = DBreference.Child("questions").Child(levelRequested).GetValueAsync(); yield return(new WaitUntil(predicate: () => DBTask.IsCompleted)); if (DBTask.Exception != null) { Debug.LogWarning(message: $"Failed to register task with {DBTask.Exception}"); } else { //Data has been retrieved DataSnapshot snapshots = DBTask.Result; //long childrenCount = snapshots.ChildrenCount; foreach (var childSnapshot in snapshots.Children) { string question = childSnapshot.Child("question").Value.ToString(); string a = childSnapshot.Child("answers").Child("a").Value.ToString(); string b = childSnapshot.Child("answers").Child("b").Value.ToString(); string c = childSnapshot.Child("answers").Child("c").Value.ToString(); string d = childSnapshot.Child("answers").Child("d").Value.ToString(); string[] choices = new string[] { a, b, c, d }; string correct = childSnapshot.Child("answers").Child("correct").Value.ToString(); int correctIndex; if (correct == "a") { correctIndex = 1; } else if (correct == "b") { correctIndex = 2; } else if (correct == "c") { correctIndex = 3; } else { correctIndex = 4; } QuestionsAndAnswers tempItem = new QuestionsAndAnswers(question, choices, correctIndex); //Debug.Log(childSnapshot.Child("question").Value.ToString()); //Debug.Log(childSnapshot.Child("answers").Child("d").Value.ToString()); //Debug.Log(childSnapshot.Child("answers").Child("correct").Value.ToString()); //Debug.Log("-------------------------"); questionsList.Add(tempItem); } //questionsList.ForEach(item => Debug.Log(item.question)); callback(questionsList); } }
private QuestionsAndAnswers GetUpdatedQuestionInfo(QuestionsAndAnswers question, List <QnAQuestionDto> qnaQuestions) { question = qnaQuestions.Where(x => GetHeatIdFromQnAQuestion(x.metadata) == question.HeatQuestionId.ToLower()) .Select(q => new QuestionsAndAnswers() { HeatQuestionId = question.HeatQuestionId, QnAQuestionId = q.id, HeatQuestion = question.HeatQuestion, QnAQuestion = q.questions.ToList(), Answer = question.Answer }).FirstOrDefault(); return(question); }
/** * */ private IEnumerator queryQuestion(string questionId) { string[] questionIds = questionId.Split('_'); string stage = questionIds[0] + "_" + questionIds[1]; string questionNum = questionIds[2]; var DBTask = DBreference.Child("questions").Child(stage).Child(questionNum).GetValueAsync(); yield return(new WaitUntil(predicate: () => DBTask.IsCompleted)); if (DBTask.Exception != null) { Debug.LogWarning(message: $"Failed to register task with {DBTask.Exception}"); } else { DataSnapshot snapshot = DBTask.Result; string question = snapshot.Child("question").Value.ToString(); string a = snapshot.Child("answers").Child("a").Value.ToString(); string b = snapshot.Child("answers").Child("b").Value.ToString(); string c = snapshot.Child("answers").Child("c").Value.ToString(); string d = snapshot.Child("answers").Child("d").Value.ToString(); string[] choices = new string[] { a, b, c, d }; string correct = snapshot.Child("answers").Child("correct").Value.ToString(); int correctIndex; if (correct == "a") { correctIndex = 1; } else if (correct == "b") { correctIndex = 2; } else if (correct == "c") { correctIndex = 3; } else { correctIndex = 4; } QuestionsAndAnswers tempItem = new QuestionsAndAnswers(question, choices, correctIndex); questionsList.Add(tempItem); } }
/** * this method handles getting questions from the database for a particular level * @param levelRequested - the level chosen * @param quizId - can put any value */ private IEnumerator RequestForQuestions(string levelRequested, string quizId) { var DBTask = DBreference.Child("questions").Child(levelRequested).GetValueAsync(); yield return(new WaitUntil(predicate: () => DBTask.IsCompleted)); if (DBTask.Exception != null) { Debug.LogWarning(message: $"Failed to register task with {DBTask.Exception}"); } else { //Data has been retrieved DataSnapshot snapshots = DBTask.Result; int dbCount = 0; //long childrenCount = snapshots.ChildrenCount; foreach (var childSnapshot in snapshots.Children) { string question = childSnapshot.Child("question").Value.ToString(); string a = childSnapshot.Child("answers").Child("a").Value.ToString(); string b = childSnapshot.Child("answers").Child("b").Value.ToString(); string c = childSnapshot.Child("answers").Child("c").Value.ToString(); string d = childSnapshot.Child("answers").Child("d").Value.ToString(); string[] choices = new string[] { a, b, c, d }; string correct = childSnapshot.Child("answers").Child("correct").Value.ToString(); int correctIndex; if (correct == "a") { correctIndex = 1; } else if (correct == "b") { correctIndex = 2; } else if (correct == "c") { correctIndex = 3; } else { correctIndex = 4; } QuestionsAndAnswers tempItem = new QuestionsAndAnswers(question, choices, correctIndex); tempItem.id = levelRequested + "_" + dbCount.ToString() + "_question"; dbCount++; questionsList.Add(tempItem); } int count = 0; foreach (QuestionsAndAnswers question in questionsList) { int y_change = count * (250); GameObject tempObject = Instantiate(entryTemplate, entryContainer); InstantiatedQuestions.Add(tempObject); tempObject.name = question.id; tempObject.transform.GetChild(0).gameObject.GetComponent <TextMeshProUGUI>().text = question.Question; tempObject.transform.GetChild(1).gameObject.GetComponent <TextMeshProUGUI>().text = "a) " + question.Answers[0]; tempObject.transform.GetChild(2).gameObject.GetComponent <TextMeshProUGUI>().text = "b) " + question.Answers[1]; tempObject.transform.GetChild(3).gameObject.GetComponent <TextMeshProUGUI>().text = "c) " + question.Answers[2]; tempObject.transform.GetChild(4).gameObject.GetComponent <TextMeshProUGUI>().text = "d) " + question.Answers[3]; tempObject.GetComponent <ChooseQuestionButton>().StartButton(); count++; } } }
public UIShowQuestion(int SetId, Action timer, IWordRepository wordRepository, IMeaningRepository meaningRepository, IMemorizationRepository memorizationRepository, ISettingRepository settingRepository) { _meaningRepository = meaningRepository; _wordRepository = wordRepository; _memorizationRepository = memorizationRepository; _settingRepository = settingRepository; if (_fistWordList == null) { _fistWordList = _wordRepository.List(SetId, SessionData.loginUserId) as List <Word>; } questionsAndAnswers = new QuestionsAndAnswers(); var word = _fistWordList.OrderBy(x => Guid.NewGuid()).FirstOrDefault(); _wordId = word.ID; _setId = SetId; _timer = timer; questionsAndAnswers.Question = word.WordText; var answer = _meaningRepository.Get(x => x.WordId == word.ID); questionsAndAnswers.AndAnswer = answer.MeaningWord; questionsAndAnswers.AndAnswers = _meaningRepository.List(x => x.ID != answer.ID).OrderBy(x => Guid.NewGuid()).Select(e => e.MeaningWord).Take(4).ToList(); questionsAndAnswers.AndAnswers.Add(questionsAndAnswers.AndAnswer); InitializeComponent(); Opacity = Convert.ToInt32(_settingRepository.Get("QuestionWindowOpacity").SettingValue) / 100D; var PlayAnswer = _settingRepository.Get("PlayAnswer").SettingValue; txtWord.Text = questionsAndAnswers.Question; Rectangle r = Screen.PrimaryScreen.WorkingArea; this.StartPosition = FormStartPosition.Manual; this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height); int i = 0; var pnlSize = pnlAnswers.Size; int btnYukseklik = pnlSize.Height / questionsAndAnswers.AndAnswers.Count(); foreach (var item in questionsAndAnswers.AndAnswers.OrderBy(x => Guid.NewGuid())) { Button button = new Button(); button.Text = item; button.Name = i.ToString() + "_Btn"; button.Size = new Size(pnlSize.Width - 2, btnYukseklik); button.Click += (object sender, EventArgs e) => { var clickButton = sender as Button; if (clickButton.Text == questionsAndAnswers.AndAnswer) { clickButton.BackColor = Color.Green; } if (PlayAnswer == "1") { SpeechSynthesizer ss = new SpeechSynthesizer(); ss.SpeakAsync(button.Text); } }; i++; button.Dock = DockStyle.Top; pnlAnswers.Controls.Add(button); } var playQuestion = _settingRepository.Get("PlayQuestion").SettingValue == "1" ? true : false; if (playQuestion) { SpeechSynthesizer ss = new SpeechSynthesizer(); ss.SpeakAsync(txtWord.Text); } }
private int GetDeletedQuestionInfo(QuestionsAndAnswers question, List <QnAQuestionDto> qnaQuestions) { return(qnaQuestions.Where(x => GetHeatIdFromQnAQuestion(x.metadata) == question.HeatQuestionId.ToLower()) .Select(q => q.id).FirstOrDefault()); }