示例#1
0
        /// <summary> Get the shape implementing Interface.</summary>
        /// <param name="shapeType">Type of the shape.</param>
        /// <returns>Shape</returns>
        public IDrawShape getShape(string shapeType)
        {
            IDrawShape shape = null;

            switch (shapeType)
            {
            case "CIRCLE":
                shape = new DrawCircle();
                break;

            case "RECTANGLE":
                shape = new DrawRectangle();
                break;

            case "TRIANGLE":
                shape = new DrawTriangle();
                break;
            }
            return(shape);
        }
 public MainPresenter(IDrawShape shapeDrawService)
 {
     this.shapeDrawService = shapeDrawService;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Circle"/> class.
 /// </summary>
 /// <param name="drawShape">The draw shape.</param>
 /// <param name="radius">The radius.</param>
 public Circle(IDrawShape drawShape, float radius) : base(drawShape)
 {
     this.radius = radius;
 }
示例#4
0
        /// <summary>Sends the draw command.</summary>
        /// <param name="lineOfCommand">The line of command.</param>
        private void sendDrawCommand(string lineOfCommand)
        {
            String[] shapes   = { "circle", "rectangle", "triangle" };
            String[] variable = { "radius", "width", "height", "counter", "hypotenuse" };

            lineOfCommand = Regex.Replace(lineOfCommand, @"\s+", " ");
            string[] words = lineOfCommand.Split(' ');
            //removing white spaces in between words
            for (int i = 0; i < words.Length; i++)
            {
                words[i] = words[i].Trim();
            }
            String  firstWord      = words[0].ToLower();
            Boolean firstWordShape = shapes.Contains(firstWord);

            if (firstWordShape)
            {
                if (firstWord.Equals("circle"))
                {
                    Boolean secondWordIsVariable = variable.Contains(words[1].ToLower());
                    if (secondWordIsVariable)
                    {
                        if (words[1].ToLower().Equals("radius"))
                        {
                            IShape = shapeFactory.getShape("CIRCLE");
                            IShape.SetShapeParam(radius, 0, 0);
                            IShape.DrawShape(g);
                        }
                    }
                    else
                    {
                        IShape = shapeFactory.getShape("CIRCLE");
                        IShape.SetShapeParam(Int32.Parse(words[1]), 0, 0);
                        IShape.DrawShape(g);
                    }
                }
                else if (firstWord.Equals("rectangle"))
                {
                    String   args  = lineOfCommand.Substring(9, (lineOfCommand.Length - 9));
                    String[] parms = args.Split(',');
                    for (int i = 0; i < parms.Length; i++)
                    {
                        parms[i] = parms[i].Trim();
                    }
                    Boolean secondWordIsVariable = variable.Contains(parms[0].ToLower());
                    Boolean thirdWordIsVariable  = variable.Contains(parms[1].ToLower());
                    if (secondWordIsVariable)
                    {
                        if (thirdWordIsVariable)
                        {
                            IShape = shapeFactory.getShape("RECTANGLE");
                            IShape.SetShapeParam(width, height, 0);
                            IShape.DrawShape(g);
                        }
                        else
                        {
                            IShape = shapeFactory.getShape("RECTANGLE");
                            IShape.SetShapeParam(width, Int32.Parse(parms[1]), 0);
                            IShape.DrawShape(g);
                        }
                    }
                    else
                    {
                        if (thirdWordIsVariable)
                        {
                            IShape = shapeFactory.getShape("RECTANGLE");
                            IShape.SetShapeParam(Int32.Parse(parms[0]), height, 0);
                            IShape.DrawShape(g);
                        }
                        else
                        {
                            IShape = shapeFactory.getShape("RECTANGLE");
                            IShape.SetShapeParam(Int32.Parse(parms[0]), Int32.Parse(parms[1]), 0);
                            IShape.DrawShape(g);
                        }
                    }
                }
                else if (firstWord.Equals("triangle"))
                {
                    String   args  = lineOfCommand.Substring(8, (lineOfCommand.Length - 8));
                    String[] parms = args.Split(',');
                    if (parms.Length == 3)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            parms[i] = parms[i].Trim();
                        }
                        IShape = shapeFactory.getShape("TRIANGLE");
                        IShape.SetShapeParam(Int32.Parse(parms[0]), Int32.Parse(parms[1]), Int32.Parse(parms[2]));
                        IShape.DrawShape(g);
                    }
                }
            }
            else
            {
                if (firstWord.Equals("loop"))
                {
                    counter = int.Parse(words[1]);
                    int loopStartLine = (GetStartLineNumber("loop"));
                    int loopEndLine   = (GetEndLineNumber("endloop") - 1);
                    loopNumber = loopEndLine;
                    for (int i = 0; i < counter; i++)
                    {
                        for (int j = loopStartLine; j <= loopEndLine; j++)
                        {
                            String oneLineCommand = textBoxCmd.Lines[j];
                            oneLineCommand = oneLineCommand.Trim();
                            if (!oneLineCommand.Equals(""))
                            {
                                RunCommand(oneLineCommand);
                            }
                        }
                    }
                }
                else if (firstWord.Equals("if"))
                {
                    Boolean loop = false;
                    if (words[1].ToLower().Equals("radius"))
                    {
                        if (radius == int.Parse(words[1]))
                        {
                            loop = true;
                        }
                    }
                    else if (words[1].ToLower().Equals("width"))
                    {
                        if (width == int.Parse(words[1]))
                        {
                            loop = true;
                        }
                    }
                    else if (words[1].ToLower().Equals("height"))
                    {
                        if (height == int.Parse(words[1]))
                        {
                            loop = true;
                        }
                    }
                    else if (words[1].ToLower().Equals("counter"))
                    {
                        if (counter == int.Parse(words[1]))
                        {
                            loop = true;
                        }
                    }
                    int ifStartLine = (GetStartLineNumber("if"));
                    int ifEndLine   = (GetEndLineNumber("endif") - 1);
                    loopNumber = ifEndLine;
                    if (loop)
                    {
                        for (int j = ifStartLine; j <= ifEndLine; j++)
                        {
                            String oneLineCommand = textBoxCmd.Lines[j];
                            oneLineCommand = oneLineCommand.Trim();
                            if (!oneLineCommand.Equals(""))
                            {
                                RunCommand(oneLineCommand);
                            }
                        }
                    }
                }
            }
        }
 // a bridge between the shape that's being drawn an
 // the component which actually draws it
 public Shape(IDrawShape drawShape)
 {
     this.drawShape = drawShape;
 }