예제 #1
0
        /// <summary>
        /// A method that implementes the shapes according to the given instructions by the user in the application
        /// </summary>
        /// <param name="shape"></param> name of the shape passed by the user
        /// <param name="length"></param> number of parameters passed by the user
        /// <param name="para"></param> string array of the parameters passed by the user
        public void shape_changer(string shape, int length, string[] para)

        {
            Shape_decider shape_type = new Shape_decider();

            float[] parameters_float = new float[length];
            for (int i = 0; i < length; i++)
            {
                if (Data_storing.List_of_varaiables.Contains(para[i]))
                {
                    int index = Data_storing.List_of_varaiables.IndexOf(para[i]);
                    parameters_float[i] = (float)Data_storing.Value_of_varaiables[index];
                }
                else
                {
                    try
                    {
                        parameters_float[i] = float.Parse(para[i]);
                    }
                    catch (FormatException fe)
                    {
                        this.errors[0] = "Please pass some valid parameters to the command";
                    }
                }
            }

            Shapes sh = shape_type.GetShapes(shape);

            if (fill)
            {
                sh.GetValue(parameters_float, Default_Brush);
            }
            else
            {
                sh.GetValue(parameters_float, Default_Pen);
            }
            sh.Draw(graphics, Default_initial_positionx, Default_initial_positiony, fill);
        }
예제 #2
0
        /// <summary>
        /// Class Takes the input and executes the give code to the run the application correctly
        /// </summary>
        /// <param name="firstname"></param> first name of the code that is to be implemented
        /// <param name="parameters_string"></param> array of string that contains the input of parametes that has been given by the user to compile.
        /// <param name="gr"></param> graphics for the picturebox that the application draws the shapes in.
        public Shape_Implementation(string firstname, string[] parameters_string)
        {
            this.firstname = firstname;

            this.parameters = parameters_string;
            Shape_decider shape_type = new Shape_decider();

            if (firstname == "moveto" || firstname == "drawto")
            {
                this.to_implementation();
            }
            else if (firstname == "pen")
            {
                if (parameters_string.Length == 1)
                {
                    PencolorSwitcher p = new PencolorSwitcher(parameters_string[0]);
                    errors = p.error_pencolorSwitcher();
                }
                else
                {
                    errors[0] = "**Pass only a color name**";
                }
            }
            else if (firstname == "fill")
            {
                if (parameters_string.Length == 1)
                {
                    if (parameters_string[0] == "on")
                    {
                        fill      = true;
                        errors[0] = "**Fill turned on**";
                    }
                    else if (parameters_string[0] == "off")
                    {
                        fill      = false;
                        errors[0] = "**Fill turned off**";
                    }
                    else
                    {
                        errors[0] = "**You can turn on or turn off the fill in**";
                    }
                }
                else
                {
                    errors[0] = "**Pass only a color name**";
                }
            }

            else if (firstname == "circle")
            {
                if (parameters_string.Length == 1)
                {
                    shape_changer(firstname, parameters_string.Length, parameters_string);
                }
                else
                {
                    errors[0] = "**Pass only a Radius**";
                }
            }
            else if (firstname == "drawarc")
            {
                if (parameters_string.Length == 4)
                {
                    shape_changer(firstname, parameters_string.Length, parameters_string);
                }
                else
                {
                    errors[0] = "**Pass width,height,start angle,sweep angle**";
                }
            }
            else if (firstname == "triangle")
            {
                if (parameters_string.Length == 3)
                {
                    shape_changer(firstname, parameters_string.Length, parameters_string);
                }
                else
                {
                    errors[0] = "**Pass legnths for each side**";
                }
            }
            else if (firstname == "rectangle")
            {
                if (parameters_string.Length == 2)
                {
                    shape_changer(firstname, parameters_string.Length, parameters_string);
                }
                else
                {
                    errors[0] = "**Pass a length and a breadth**";
                }
            }
            else if (firstname == "polygon")
            {
                if (parameters_string.Length >= 4)
                {
                    shape_changer(firstname, parameters_string.Length, parameters_string);
                }
                else
                {
                    errors[0] = "**Pass a 5 parameters for the sides**";
                }
            }
            else if (firstname == "rotate")
            {
                if (parameters_string.Length == 1)
                {
                    rotating_Graphics(parameters_string);
                }
                else
                {
                    errors[0] = "**Pass a rotating angle**";
                }
            }
            else
            {
                this.errors[0] = "**Not a Valid Code**";
            }
        }