/// <summary>
    /// Retrieved the questions and answer from the database
    /// </summary>
    /// <returns> the list of questions is returned </returns>
    public QuestionsNAnswers LoadQuestion()
    {
        QuestionsNAnswersDAO     dao       = new QuestionsNAnswersDAO();
        List <QuestionsNAnswers> questions = dao.RetrieveQuestions(DifficultyStore.Difficulty);

        question = questions[Random.Range(0, questions.Count)];

        return(question);
    }
    /// <summary>
    /// Load quiz question and answer from database through quizManager based on the dfficulty selected by the player
    /// </summary>
    void Start()
    {
        SceneManager.UnloadSceneAsync("DifficultySelection");

        // Generate question
        QuestionsNAnswers question = quizManager.LoadQuestion();

        // Display question details
        questionText.text = question.Question;
        Toggle optionToggle;

        for (int i = 0; i < optionToggles.Length; i++)
        {
            optionToggle = optionToggles[i];
            optionToggle.GetComponentInChildren <Text>().text = question.AnswerSelections[i];
        }
    }
Exemple #3
0
        /// <summary>
        /// Stores QuestionsNAnswers into database.
        /// </summary>
        /// <param name="quizRecord">QuestionsNAnswers needs to be stored</param>
        public void addData(QuestionsNAnswers quizRecord)
        {
            try
            {
                IDbCommand dbcmd = getDbCommand();
                dbcmd.CommandText =
                    "INSERT INTO " + TABLE_NAME
                    + " ( "
                    + KEY_QuizID + ", "
                    + KEY_Question + ", "
                    + KEY_CorrectOptionIndex + ", "
                    + KEY_Credit + ", "
                    + KEY_Difficulty + " ) "

                    + "VALUES ( '"
                    + quizRecord.QuizID + "', '"
                    + quizRecord.Question + "', '"
                    + quizRecord.CorrectAnswer + "', '"
                    + quizRecord.Credit + "', '"
                    + quizRecord.Difficulty + "' )";
                dbcmd.ExecuteNonQuery();



                foreach (string option in quizRecord.AnswerSelections)
                {
                    dbcmd.CommandText =
                        "INSERT INTO " + TABLE_NAME2
                        + " ( "
                        + KEY_QuizID + ", "
                        + KEY_Content + ", "
                        + KEY_OptionIndex + " ) "

                        + "VALUES ( '"
                        + quizRecord.QuizID + "', '"
                        + option + "', '"
                        + Array.IndexOf(quizRecord.AnswerSelections, option) + "' )";
                    dbcmd.ExecuteNonQuery();
                }
            }
            catch
            {
                Debug.Log("Duplicate ID!!");
            }
        }