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()
        {
            //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();
        }