/// <summary>
        /// Creates and returns a new random component with shape and color given.
        /// </summary>
        /// <param name="color">will be the color of the returned component</param>
        /// <param name="shape">will be the shape of the returned component</param>
        /// <returns>Returns a new component WITH random letter and digit but with the shape and color in parameters</returns>
        public static ComponentPerception RandomComponentWith(Shape referenceShape, Color referenceColor)
        {
            ComponentPerception c = new ComponentPerception();

            c.Shape = referenceShape;
            c.Color = referenceColor;
            c.Digit = r.Next(minDigit, maxDigit + 1);

            c.Dock = DockStyle.Fill;

            return(c);
        }
예제 #2
0
        /// <summary>
        /// Displays a prompt in which the user can enter his answer.
        /// </summary>
        /// <param name="c">Component related to the answer asked.</param>
        /// <returns>Number answered by the user.</returns>
        private int AskDigitOfComponent(ComponentPerception c)
        {
            Form          form     = new Form();
            Label         label    = new Label();
            NumericUpDown updown   = new NumericUpDown();
            Button        buttonOk = new Button();

            #region Form creation
            form.Text  = "Figure " + c.Letter.ToString();
            label.Text = "Quelle était la valeur associée\n à la figure " + c.Letter.ToString() + " ?";
            updown.ResetText();

            Panel buttonOkPanel = new Panel(); //only about aesthectics
            buttonOkPanel.Dock      = DockStyle.Bottom;
            buttonOkPanel.Height    = 50;
            buttonOkPanel.BackColor = Color.WhiteSmoke;

            buttonOk.Text         = "OK";
            buttonOk.DialogResult = DialogResult.OK;

            label.Dock      = DockStyle.Top;
            label.Font      = new Font("Arial", 11);
            label.TextAlign = ContentAlignment.MiddleCenter;
            label.Dock      = DockStyle.Top;
            label.Height    = 50;
            label.BackColor = Color.White;

            updown.Location  = new Point(105, 60);
            updown.Width     = 75;
            updown.TextAlign = HorizontalAlignment.Center;
            updown.Minimum   = 0;
            updown.Maximum   = 9;

            buttonOk.Location = new Point(191, 13);
            buttonOk.Width    = 75;
            buttonOk.Height   = 25;
            buttonOk.Text     = "OK";

            buttonOkPanel.Controls.Add(buttonOk);

            form.ClientSize = new Size(280, 158);
            form.Controls.AddRange(new Control[] { label, updown, buttonOkPanel });
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition   = FormStartPosition.CenterScreen;
            form.BackColor       = Color.White;
            form.AcceptButton    = buttonOk;
            #endregion

            form.ShowDialog();

            return((int)updown.Value);
        }
예제 #3
0
        /// <summary>
        /// Generates a random permutation of the components. Fisher–Yates logic.
        /// </summary>
        private void ShuffleComponents()
        {
            int n = Components.Count;

            while (n > 1)
            {
                n--;
                int k = new Random().Next(n + 1);
                ComponentPerception c = Components[k];
                Components[k] = Components[n];
                Components[n] = c;
            }
        }
        /// <summary>
        /// Creates and returns a new random component without shape and color given.
        /// </summary>
        /// <param name="color">will be the color of the returned component</param>
        /// <param name="shape">will be the shape of the returned component</param>
        /// <returns>Returns a new component WITHOUT random letter and digit but with the shape and color in parameters</returns>
        public static ComponentPerception RandomComponentWithoutBoth(Shape referenceShape, Color referenceColor)
        {
            ComponentPerception c = new ComponentPerception();

            //changing shape and color of component if it has both of the excluded characteristics
            do
            {
                c.Color = (r.Next(0, 2) == 0) ? Color.RoyalBlue : Color.Yellow; //transform to Enum ?;
                c.Shape = RandomEnumValue <Shape>();
            } while (c.Shape == referenceShape && c.Color == referenceColor);
            c.Digit = r.Next(minDigit, maxDigit + 1);

            c.Dock = DockStyle.Fill;

            return(c);
        }
예제 #5
0
        /// <summary>
        /// Generates and adding to the list pseudo-random components (pseudo because they are according to the specifications)
        /// </summary>
        /// <param name="numberOfComponents">The number of components to generate</param>
        private void GenerateRandomComponents()
        {
            int numberOfFixedComponents = new Random().Next(3, 5); //3 or 4 (cf. specifications)

            //generates and add to the list of components 3 or 4 components with specified color and shape
            for (int i = 0; i < numberOfFixedComponents; i++)
            {
                Components.Add(ComponentPerception.RandomComponentWith(ReferenceShape, ReferenceColor));
            }

            //generates the other components randomly, without the same reference color and shape as the first ones
            for (int i = 0; i < numberOfComponents - numberOfFixedComponents; i++)
            {
                Components.Add(ComponentPerception.RandomComponentWithoutBoth(ReferenceShape, ReferenceColor));
            }
        }
예제 #6
0
 /// <summary>
 /// Set random shape and color for the current mask, which will be ask to memorize to the user.
 /// </summary>
 public void SetRandomReferenceShapeAndColor()
 {
     ReferenceShape = ComponentPerception.RandomEnumValue <Shape>();
     ReferenceColor = (new Random().Next(0, 2) == 0) ? Color.RoyalBlue : Color.Yellow;
 }