Exemplo n.º 1
0
        /// <summary>
        /// Generates a "choose matching string" question
        /// </summary>
        /// <param name="elementNumber">Amount of the elements in the generated
        /// regular expression</param>
        public ChooseMatchQuestion(int elementNumber)
        {
            //Generate the required regular expression
            regex = RegexGenerator.GenerateExpression(elementNumber);
            parsedRegex = new Regex(regex);

            //Pick which string will be the correct one
            correctID = randomGen.Next(4);

            for (int i = 0; i < 4; i++)
            {
                //Generate a random string that matches the expression
                string matchString = parsedRegex.RandomString();

                //If this string is not supposed to be correct, make it invalid
                if (i == correctID) options[i] = matchString;
                else options[i] = GenerateInvalidString(matchString);

                //This way, each string will be generated from a different string
                //that matches the expression, hence, the 4 strings won't look similar
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Shows a hint to this question to the user
        /// </summary>
        public void DisplayHint()
        {
            //Exit if the hint has been used
            if (!hintAvailable) return;

            //Mark the hint as used
            hintAvailable = false;

            //Find the correct option
            Regex parsedQuestionRegex = new Regex(questionRegex);
            int correctOption = 0;
            while (!parsedQuestionRegex.Match(options[correctOption]))
            {
                correctOption++;
            }

            //Generate two different IDs so that none of them is the correct ID
            int toRemove1, toRemove2;
            do {
                toRemove1 = randGen.Next(4);
            } while (toRemove1 == correctOption);
            do {
                toRemove2 = randGen.Next(4);
            } while (toRemove2 == correctOption || toRemove2 == toRemove1);

            //Remove the two incorrect options
            displayedOptions[toRemove1].Hide();
            displayedOptions[toRemove2].Hide();

            displayedOptions[toRemove1].Checked = false;
            displayedOptions[toRemove2].Checked = false;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Generates a "write matching string" question
 /// </summary>
 /// <param name="elementNumber">Amount of the elements in the generated
 /// regular expression</param>
 public MatchStringQuestion(int elementNumber)
 {
     //Generate a random regular expression and parse it
     regex = RegexGenerator.GenerateExpression(elementNumber);
     parsedRegex = new Regex(regex);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Shows a hint to this question to the user
        /// </summary>
        public void DisplayHint()
        {
            //Bail out if the hint has already been displayed for this question
            if (!hintAvailable) return;

            //Hint no longer available
            hintAvailable = false;

            //Get a random answer that matches this regex
            Regex parsedExp = new Regex(questionRegex);
            char[] randomAnswer = parsedExp.RandomString().ToCharArray();

            //Replace some characters in it with underscores
            for (int i = 0; i < randomAnswer.Length; i++)
            {
                if (randGen.Next() % 3 == 0) randomAnswer[i] = '_';
            }

            //Display the hint
            txtHint.Text = "Hint: " + new string(randomAnswer);
            txtHint.Show();
        }