コード例 #1
0
        public void TestCircle()
        {
            IFigureFactorory figureFactory = new CircleFactory(1);
            IFigure          figure        = figureFactory.Create();

            Assert.AreEqual(figure.Square, Math.PI);
        }
コード例 #2
0
ファイル: frmMain.cs プロジェクト: FirstVP/Task2
        private void toolStripButtonCircle_Click(object sender, EventArgs e)
        {
            CurrentFactory = new CircleShapeFactory();
            Factory current = new CircleFactory(pnlMain);

            CurrentDrawman = current.FactoryMethod();
        }
コード例 #3
0
ファイル: FlyweightTest.cs プロジェクト: cwloon96/Patterns
        public void ShouldReturnSameInstance()
        {
            var redCircle1 = CircleFactory.GetCircle("red");
            var redCircle2 = CircleFactory.GetCircle("red");

            Assert.AreEqual(redCircle1, redCircle2);
        }
コード例 #4
0
        public void TestGetCircleReturnsDifferentCirclesForDifferentRadius()
        {
            CircleFactory.GetCircle(0, 0, 10, "Red");
            CircleFactory.GetCircle(0, 0, 11, "Red");

            Assert.That(CircleFactory.Circles.Count, Is.EqualTo(2));
        }
コード例 #5
0
        static void Main(string[] args)
        {
            iIOmethod ioMethod = new ConsoleIO();

            Console.WriteLine("1. Circle");
            iFigureFactory factory = new CircleFactory(ioMethod);
            iFigure        fig     = factory.create();

            Console.WriteLine("Circle square = " + fig.getSquare());

            Console.WriteLine("2. Triangle");
            factory = new TriangleFactory(ioMethod);
            fig     = factory.create();
            Console.WriteLine("Triangle square = " + fig.getSquare());
            Triangle triangle = fig as Triangle;

            if (triangle != null)
            {
                Console.WriteLine("Is this a right triangle? " + (triangle.isRightAngle() ? "Yes!!" : "No!"));
            }


            Console.WriteLine();
            Console.WriteLine("Happy end! Press a key..");
            Console.ReadKey();
        }
コード例 #6
0
ファイル: PatternsForm.cs プロジェクト: krestyanov/TMPS
        private void PatternsForm_Paint(object sender, PaintEventArgs e)
        {
            gs = e.Graphics;
            Map.Map.Graphics = e.Graphics;

            map.DrawMap();

            foreach (IObjectBuilder bl in map.MapObjects)
            {
                if (bl is CircleBuilder)
                {
                    bl.formGraphics = e.Graphics;
                    (bl as CircleBuilder).DrawObject();
                }
                else
                {
                    bl.formGraphics = e.Graphics;
                    (bl as RectangleBuilder).DrawObject();
                }
            }

            if (!FormLoaded)
            {
                IUnitFactory factory = new CircleFactory();
                for (int i = 0; i < 50; i++)
                {
                    if (i > 25)
                    {
                        factory = new RectangleFactory();
                    }
                    if (factory is CircleFactory)
                    {
                        IObjectBuilder cl   = factory.ObjectBuilder as CircleBuilder;
                        CircleBuilder  temp = CircleBuilder.CopyCircle(cl as CircleBuilder);
                        (cl as CircleBuilder).Draw(cl, map, Tasks);
                        temp.Draw(temp, map, Tasks);
                    }
                    else
                    {
                        IObjectBuilder cl = factory.ObjectBuilder as Factory.Rectangle.RectangleBuilder;
                        (cl as Factory.Rectangle.RectangleBuilder).Draw(cl, map, Tasks);
                    }
                    FormLoaded = true;
                }
                foreach (IObjectBuilder cl in map.MapObjects)
                {
                    if (cl is CircleBuilder)
                    {
                        (cl as CircleBuilder)._thisObject.X = new Random(cl.GetHashCode()).Next(1, 1000);
                        (cl as CircleBuilder)._thisObject.Y = new Random(cl.GetHashCode()).Next(1, 1000);
                    }
                    else
                    {
                        (cl as RectangleBuilder)._thisObject.X = new Random(cl.GetHashCode()).Next(1, 1000);
                        (cl as RectangleBuilder)._thisObject.Y = new Random(cl.GetHashCode()).Next(1, 1000);
                    }
                }
            }
        }
コード例 #7
0
 static public CircleFactory getInstance()
 {
     if (instance == null)
     {
         instance = new CircleFactory();
     }
     return(instance);
 }
コード例 #8
0
        public void TestGetCircleReturnsSameCircleForSameRadiusAndColor()
        {
            CircleFactory.GetCircle(0, 0, 10, "Red");
            CircleFactory.GetCircle(0, 0, 10, "Red");
            CircleFactory.GetCircle(10, 10, 10, "Red");
            CircleFactory.GetCircle(10, 10, 10, "Red");

            Assert.That(CircleFactory.Circles.Count, Is.EqualTo(1));
        }
コード例 #9
0
        public GoogleMapBuilder Circles(Action <CircleFactory> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            var factory = new CircleFactory(Component);

            action(factory);
            return(this);
        }
コード例 #10
0
ファイル: ShapeSelect.cs プロジェクト: LoofahCat/cs5700_HW4
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (cmboShapeType.SelectedItem is null)
            {
                errorMessage("Please select a type of shape");
            }
            else if (ValidateInfo())
            {
                ShapeFactory factory = null;
                switch (cmboShapeType.SelectedItem.ToString())
                {
                case "Circle":
                    Shapes.Point CirclePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text));
                    factory = new CircleFactory(CirclePoint, Int32.Parse(txtRadius1.Text));
                    break;

                case "Ellipse":
                    Shapes.Point EllipsePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text));
                    factory = new EllipseFactory(EllipsePoint, Int32.Parse(txtRadius1.Text), Int32.Parse(txtRadius2.Text));
                    break;

                case "Rectangle":
                    Shapes.Point RectanglePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text));
                    factory = new RectangleFactory(RectanglePoint, Int32.Parse(txtRadius1.Text), Int32.Parse(txtRadius2.Text));
                    break;

                case "Square":
                    Shapes.Point SquarePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text));
                    factory = new SquareFactory(SquarePoint, Int32.Parse(txtRadius1.Text));
                    break;

                case "Triangle":
                    Shapes.Point TriPoint1 = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text));
                    Shapes.Point TriPoint2 = new Shapes.Point(Int32.Parse(txtPoint2X.Text), Int32.Parse(txtPoint2Y.Text));
                    Shapes.Point TriPoint3 = new Shapes.Point(Int32.Parse(txtPoint3X.Text), Int32.Parse(txtPoint3Y.Text));
                    factory = new TriangleFactory(TriPoint1, TriPoint2, TriPoint3);
                    break;

                case "Composite Image":
                    factory = new CompositeImageFactory(filepath);
                    break;

                case "Embedded Pic":
                    Shapes.Point EmbeddedPoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text));
                    factory = new EmbeddedPicFactory(EmbeddedPoint, Int32.Parse(txtRadius1.Text), Int32.Parse(txtRadius2.Text), filepath);
                    break;
                }
                Shape shape = factory.GetShape();
                Console.WriteLine(shape.ShapeType);
                shapeToDraw = shape;
                this.Close();
            }
        }
コード例 #11
0
        public void TestDrawCircle()
        {
            Circle circle = CircleFactory.GetCircle();

            circle.FirstpointXCoordinate  = 15;
            circle.FirstpointYCoordinate  = 15;
            circle.SecondpointXCoordinate = 40;
            circle.SecondpointYCoordinate = 40;
            ICircleOperation circleOperation = CircleOperationalFactory.GetCircleOperation();

            circleOperation.Draw(circle);
        }
コード例 #12
0
ファイル: CircleTest.cs プロジェクト: pwnsbey/cs5700
        public void TestScale()
        {
            ShapeFactory sf = new CircleFactory();

            Circle myCircle = (Circle)sf.Create2dShape();

            myCircle.SetCenter(1, 2);
            myCircle.SetRadius(5);
            Assert.AreEqual(1, myCircle.GetCenter().X, 0);
            Assert.AreEqual(2, myCircle.GetCenter().Y, 0);
            Assert.AreEqual(5, myCircle.GetRadius(), 0);

            myCircle.Scale(3);
            Assert.AreEqual(1, myCircle.GetCenter().X, 0);
            Assert.AreEqual(2, myCircle.GetCenter().Y, 0);
            Assert.AreEqual(15, myCircle.GetRadius(), 0);

            myCircle.Scale(0.2);
            Assert.AreEqual(1, myCircle.GetCenter().X, 0);
            Assert.AreEqual(2, myCircle.GetCenter().Y, 0);
            Assert.AreEqual(3, myCircle.GetRadius(), 0);

            try
            {
                myCircle.Scale(double.PositiveInfinity);
                Assert.Fail("Expected exception not thrown");
            }
            catch (Exception)
            {
                // ignore
            }

            try
            {
                myCircle.Scale(double.NegativeInfinity);
                Assert.Fail("Expected exception not thrown");
            }
            catch (Exception)
            {
                // ignore
            }

            try
            {
                myCircle.Scale(double.NaN);
                Assert.Fail("Expected exception not thrown");
            }
            catch (Exception)
            {
                // ignore
            }
        }
コード例 #13
0
        public void CircleFactory_ShouldValidateParametersLength(int parametersLength)
        {
            // Arrange
            var parameters = new double[parametersLength];
            var factory    = new CircleFactory();

            // Act
            var result = factory.TryParseFigureParameters(parameters, out var message);

            // Assert
            Assert.False(result);
            Assert.Equal("Circle parameters array must contain one value for radius", message);
        }
コード例 #14
0
        public void CircleFactory_ShouldValidateRadiusValue(double radius)
        {
            // Arrange
            var parameters = new double[] { radius };
            var factory    = new CircleFactory();

            // Act
            var result = factory.TryParseFigureParameters(parameters, out var message);

            // Assert
            Assert.False(result);
            Assert.Equal("Circle radius cannot be less or equal zero", message);
        }
コード例 #15
0
        public void CircleFactory_ShouldCreateCircle_WithCorrectRadius()
        {
            // Arrange
            double radius     = 123;
            var    parameters = new double[] { radius };
            var    factory    = new CircleFactory();

            // Act
            var circle = factory.CreateFigure(parameters) as Circle;

            // Assert
            Assert.Equal(radius, circle.Radius);
        }
コード例 #16
0
ファイル: CircleTest.cs プロジェクト: pwnsbey/cs5700
        public void TestComputeArea()
        {
            ShapeFactory sf = new CircleFactory();

            Circle myCircle = (Circle)sf.Create2dShape();

            myCircle.SetCenter(1, 2);
            myCircle.SetRadius(5);
            Assert.AreEqual(78.53975, myCircle.ComputeArea(), 0.0001);

            myCircle = new Circle(1, 2, 4.234);
            Assert.AreEqual(56.3185174, myCircle.ComputeArea(), 0.0001);

            myCircle = new Circle(1, 2, 0);
            Assert.AreEqual(0, myCircle.ComputeArea(), 0);
        }
コード例 #17
0
        static void Main(string[] args)
        {
            var squareSide   = new SquareFactory().Create().Parameter;
            var circleRadius = new CircleFactory().Create().Parameter;

            string result;

            if (squareSide >= 2 * circleRadius)
            {
                result = "Circle inscribed in square";
            }
            else if (Math.Round(Math.Sqrt(2) / 2 * squareSide, 2) <= circleRadius)
            {
                result = "The circle described around the square";
            }
            else
            {
                result = "Figures intersect";
            }
            Console.WriteLine(result);
            Console.ReadKey();
        }
コード例 #18
0
        ShapeFactory GetShapeFactory(int type)
        {
            ShapeFactory shapeFactory = null;

            switch (type)
            {
            case 0:
                shapeFactory = new CircleFactory();
                break;

            case 1:
                shapeFactory = new RegtangleFactory();
                break;

            case 2:
                shapeFactory = new TriangleFactory();
                break;

            default:
                break;
            }
            return(shapeFactory);
        }
コード例 #19
0
ファイル: CircleTest.cs プロジェクト: pwnsbey/cs5700
        public void TestMove()
        {
            ShapeFactory sf = new CircleFactory();

            Circle myCircle = (Circle)sf.Create2dShape();

            myCircle.SetCenter(1, 2);
            myCircle.SetRadius(5);
            Assert.AreEqual(1, myCircle.GetCenter().X, 0);
            Assert.AreEqual(2, myCircle.GetCenter().Y, 0);
            Assert.AreEqual(5, myCircle.GetRadius(), 0);

            myCircle.Move(3, 4);
            Assert.AreEqual(4, myCircle.GetCenter().X, 0);
            Assert.AreEqual(6, myCircle.GetCenter().Y, 0);
            Assert.AreEqual(5, myCircle.GetRadius(), 0);

            myCircle.Move(0.123, 0.456);
            Assert.AreEqual(4.123, myCircle.GetCenter().X, 0);
            Assert.AreEqual(6.456, myCircle.GetCenter().Y, 0);
            Assert.AreEqual(5, myCircle.GetRadius(), 0);

            myCircle.Move(-0.123, -0.456);
            Assert.AreEqual(4, myCircle.GetCenter().X, 0);
            Assert.AreEqual(6, myCircle.GetCenter().Y, 0);
            Assert.AreEqual(5, myCircle.GetRadius(), 0);

            myCircle.Move(-12, -26);
            Assert.AreEqual(-8, myCircle.GetCenter().X, 0);
            Assert.AreEqual(-20, myCircle.GetCenter().Y, 0);
            Assert.AreEqual(5, myCircle.GetRadius(), 0);

            try
            {
                myCircle.Move(double.PositiveInfinity, 1);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-x value", e.Message);
            }

            try
            {
                myCircle.Move(double.NegativeInfinity, 1);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-x value", e.Message);
            }

            try
            {
                myCircle.Move(double.NaN, 1);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-x value", e.Message);
            }

            try
            {
                myCircle.Move(1, double.PositiveInfinity);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-y value", e.Message);
            }

            try
            {
                myCircle.Move(1, double.PositiveInfinity);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-y value", e.Message);
            }

            try
            {
                myCircle.Move(1, double.NaN);
                Assert.Fail("Expected exception not thrown");
            }
            catch (ShapeException e)
            {
                Assert.AreEqual("Invalid delta-y value", e.Message);
            }
        }
コード例 #20
0
ファイル: Editor.cs プロジェクト: artemgulai/xt_net_web
        public static void Demo()
        {
            List <Figure> figures = new List <Figure>();

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Console graphical editor.");
                Console.WriteLine("Select option.");
                Console.WriteLine("1. Add Line.");
                Console.WriteLine("2. Add Circle.");
                Console.WriteLine("3. Add Rectangle.");
                Console.WriteLine("4. Add Round.");
                Console.WriteLine("5. Add Ring.");
                Console.WriteLine("6. Add Ring (aggregation).");
                Console.WriteLine("7. Show figures.");
                Console.WriteLine("0. Exit.");

                int select;
                while (!int.TryParse(Console.ReadLine(), out select))
                {
                    Console.WriteLine("Wrong input. Try again.");
                }

                switch (select)
                {
                case 1:
                    figures.Add(LineFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Line added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 2:
                    figures.Add(CircleFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Circle added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 3:
                    figures.Add(RectangleFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Rectangle added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 4:
                    figures.Add(RoundFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Round added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 5:
                    figures.Add(RingFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Ring added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 6:
                    figures.Add(RingAggregationFactory.Create());
                    Console.Clear();
                    Console.WriteLine("Ring (aggregation) added. Press enter to continue.");
                    Console.ReadLine();
                    break;

                case 7:
                    Console.Clear();
                    foreach (Figure figure in figures)
                    {
                        figure.ShowInfo();
                        Console.WriteLine();
                    }
                    Console.ReadLine();
                    break;

                case 0:
                    Console.WriteLine("Good luck!");
                    Console.ReadLine();
                    return;

                default:
                    Console.WriteLine("Wrong option. Try again.");
                    break;
                }
            }
        }
コード例 #21
0
 public void HandleEvent()
 {
     circleFactory           = new CircleFactory();
     Canvas.CurFigureFactory = circleFactory;
 }
コード例 #22
0
        static void Main()
        {
            Figure         factory = new Figure();
            Random         rand    = new Random();
            List <IFigure> figures = new List <IFigure>();
            bool           finish  = false;

            for (int i = 0; i < 5; i++)
            {
                figures.Add(factory.Create((Dict)rand.Next(0, 3)));
            }
            do
            {
                Console.WriteLine("1. Wyświetl figury.");
                Console.WriteLine("2. Dodaj figurę.");
                Console.WriteLine("K. Wyjdź.");
                string choice;
                choice = Console.ReadLine();
                switch (choice)
                {
                case "1":
                    Console.Clear();
                    do
                    {
                        Console.WriteLine("Aby zwiększyc, zmniejszyć lub usunąć figurę wybierz ją po numerze.");
                        for (int i = 0; i < figures.Count; i++)
                        {
                            Console.WriteLine("{0}. {1}", i + 1, figures[i].ToString());
                        }
                        Console.WriteLine("K. Wróć.");
                        choice = Console.ReadLine();
                        if (choice == "K" || choice == "k")
                        {
                            finish = true;
                            Console.Clear();
                        }
                        else
                        {
                            try
                            {
                                int index = Convert.ToInt32(choice) - 1;
                                Console.Clear();
                                do
                                {
                                    Console.WriteLine(figures[index].ToString());
                                    Console.WriteLine("1. Powiększ.");
                                    Console.WriteLine("2. Zmniejsz.");
                                    Console.WriteLine("3. Usuń.");
                                    Console.WriteLine("K. Wróć.");
                                    choice = Console.ReadLine();
                                    Console.Clear();
                                    switch (choice)
                                    {
                                    case "1":
                                        figures[index].Increase();
                                        break;

                                    case "2":
                                        figures[index].Decrease();
                                        break;

                                    case "3":
                                        figures.RemoveAt(index);
                                        finish = true;
                                        break;

                                    case "k":
                                    case "K":
                                        finish = true;
                                        break;

                                    default:
                                        Console.WriteLine("Zła wartość. Wpisz ponownie.");
                                        break;
                                    }
                                }while (!finish);
                                finish = false;
                            }
                            catch
                            {
                                Console.Clear();
                                Console.WriteLine("Zła wartość. Podaj ponownie.");
                            }
                        }
                    }while (!finish);
                    finish = false;
                    break;

                case "2":
                    do
                    {
                        Console.WriteLine("Wybierz jaką figurę tworzysz:");
                        Console.WriteLine("1. Kwadrat.");
                        Console.WriteLine("2. Prostokąt.");
                        Console.WriteLine("3. Koło.");
                        Console.WriteLine("K. Wróć.");
                        choice = Console.ReadLine();
                        Console.Clear();
                        double a, b;
                        switch (choice)
                        {
                        case "1":
                            SquareFactory squareFactory = new SquareFactory();
                            Console.WriteLine("Podaj długość boku. ");
                            a = Convert.ToDouble(Console.ReadLine());
                            figures.Add(squareFactory.Create(a));
                            break;

                        case "2":
                            RectangleFactory rectangleFactory = new RectangleFactory();
                            Console.WriteLine("Podaj długość pierwszego boku. ");
                            a = Convert.ToDouble(Console.ReadLine());
                            Console.WriteLine("Podaj długość drugiego boku. ");
                            b = Convert.ToDouble(Console.ReadLine());
                            figures.Add(rectangleFactory.Create(a, b));
                            break;

                        case "3":
                            CircleFactory circleFactory = new CircleFactory();
                            Console.WriteLine("Podaj długość promienia. ");
                            a = Convert.ToDouble(Console.ReadLine());
                            figures.Add(circleFactory.Create(a));
                            break;

                        case "k":
                        case "K":
                            finish = true;
                            break;

                        default:
                            Console.Clear();
                            Console.WriteLine("Zły wybór. Wybierz ponownie.");
                            break;
                        }
                    }while (!finish);
                    finish = false;
                    Console.Clear();
                    break;

                case "k":
                case "K":
                    finish = true;
                    break;

                default:
                    Console.Clear();
                    Console.WriteLine("Zły wybór. Wybierz ponownie.");
                    break;
                }
            }while (!finish);
        }
コード例 #23
0
        public Shape getShape(int initialX, int initialY, int secondaryX, int secondaryY, bool add)
        {
            if (designation == shapeDesignation.EMBEDDED_PIC)
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                DialogResult   result          = openFileDialog1.ShowDialog();
                if (result == DialogResult.OK)
                {
                    string file = openFileDialog1.FileName;
                    Console.WriteLine(openFileDialog1.FileName);
                    embeddedPicFilepath = openFileDialog1.FileName;
                }
            }
            ShapeFactory factory = null;

            switch (designation)
            {
            case shapeDesignation.CIRCLE:
                Shapes.Point CirclePoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY));
                factory = new CircleFactory(CirclePoint, Math.Abs(secondaryX - initialX));
                break;

            case shapeDesignation.ELLIPSE:
                Shapes.Point EllipsePoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY));
                factory = new EllipseFactory(EllipsePoint, Math.Abs(secondaryY - initialY), Math.Abs(secondaryX - initialX));
                break;

            case shapeDesignation.RECTANGLE:
                Shapes.Point RectanglePoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY));
                factory = new RectangleFactory(RectanglePoint, Math.Abs(secondaryY - initialY), Math.Abs(secondaryX - initialX));
                break;

            case shapeDesignation.SQUARE:
                Shapes.Point SquarePoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY));
                factory = new SquareFactory(SquarePoint, Math.Abs(secondaryX - initialX));
                break;

            case shapeDesignation.TRIANGLE:
                //TODO: Figure out rectangular triangle drawing
                //Shapes.Point TriPoint1 = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text));
                //Shapes.Point TriPoint2 = new Shapes.Point(Int32.Parse(txtPoint2X.Text), Int32.Parse(txtPoint2Y.Text));
                //Shapes.Point TriPoint3 = new Shapes.Point(Int32.Parse(txtPoint3X.Text), Int32.Parse(txtPoint3Y.Text));
                //factory = new TriangleFactory(TriPoint1, TriPoint2, TriPoint3);
                break;

            case shapeDesignation.EMBEDDED_PIC:
                Shapes.Point EmbeddedPoint = new Shapes.Point(Math.Min(initialX, secondaryX), Math.Min(initialY, secondaryY));
                factory = new EmbeddedPicFactory(EmbeddedPoint, Math.Abs(secondaryX - initialX), Math.Abs(secondaryY - initialY), embeddedPicFilepath);
                break;

            case shapeDesignation.LINE:
                //TODO: Create Line in shapes
                break;

            default:
                return(null);
            }
            Shape shape = factory.GetShape();

            if (add)
            {
                addToList(shape);
            }
            return(shape);
        }
コード例 #24
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            int ChoiceOfShape = 0;

            do
            {
                Console.WriteLine("Enter Your Choice to Draw Shape");
                Console.WriteLine("1.Line");
                Console.WriteLine("2.Circle");
                Console.WriteLine("3.Rectangle");
                Console.WriteLine("4.Exit");

                ChoiceOfShape = int.Parse(Console.ReadLine());

                switch (ChoiceOfShape)
                {
                case 1:

                    Console.WriteLine("1.Line");
                    Line line = LineFactory.GetLine();

                    Console.WriteLine("Enter X Co-ordinate of First point");
                    int XLineFirst = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter Y Co-ordinate of First point");
                    int YLineFirst = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter X Co-ordinate of Second point");
                    int XLineSecond = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter Y Co-ordinate of Second point");
                    int YLineSecond = int.Parse(Console.ReadLine());

                    line.FirstpointXCoordinate  = XLineFirst;    //100
                    line.FirstpointYCoordinate  = YLineFirst;    //200
                    line.SecondpointXCoordinate = XLineSecond;   //400
                    line.SecondpointYCoordinate = YLineSecond;   //300

                    ILineOperation lineOperation = LineOperationFactory.GetLineOperation();

                    //IShapeOperation lineOperation = ShapeOperationFactory.GetLineOperation();

                    lineOperation.Draw(line);
                    log.InfoFormat("Line Created");


                    break;

                case 2:

                    Console.WriteLine("2.Circle");

                    Circle circle = CircleFactory.GetCircle();

                    Console.WriteLine("Enter X & Y Co-ordinate of Centre point");
                    int XCircleFirst = int.Parse(Console.ReadLine());
                    int YCircleFirst = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter X & Y Equidistance Points of Radius");
                    int XCircleSecond = int.Parse(Console.ReadLine());
                    int YCircleSecond = int.Parse(Console.ReadLine());

                    circle.FirstpointXCoordinate  = XCircleFirst;      //10
                    circle.FirstpointYCoordinate  = YCircleFirst;      //10
                    circle.SecondpointXCoordinate = XCircleSecond;     //50
                    circle.SecondpointYCoordinate = YCircleSecond;     //50

                    ICircleOperation circleOperation = CircleOperationalFactory.GetCircleOperation();
                    circleOperation.Draw(circle);

                    log.InfoFormat("Circle Created");

                    break;

                case 3:

                    Console.WriteLine("3.Rectangle");

                    ERectangle rectangle = RectangleFactory.GetRectangle();

                    Console.WriteLine("Enter X & Y Co-ordinate of First point of Rectangle");
                    int XRectFirst = int.Parse(Console.ReadLine());
                    int YRectFirst = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter X & Y Co-ordinate of Second Point of Rectangle");
                    int XRectSecond = int.Parse(Console.ReadLine());
                    int YRectSecond = int.Parse(Console.ReadLine());

                    rectangle.FirstpointXCoordinate  = XRectFirst;
                    rectangle.FirstpointYCoordinate  = YRectFirst;
                    rectangle.SecondpointXCoordinate = XRectSecond;
                    rectangle.SecondpointYCoordinate = YRectSecond;

                    IRectangleOperation rectangleOperation = RectangleOperationFactory.GetRectangleOperation();
                    rectangleOperation.Draw(rectangle);

                    log.InfoFormat("Rectangle Created");

                    break;

                case 4:


                    Console.WriteLine("4.Exit");
                    Console.WriteLine("Welcome Again!!");

                    System.Environment.Exit(0);

                    break;

                default:

                    Console.WriteLine("Wrong Choice ! ");
                    break;
                }
            } while (ChoiceOfShape != 3);
        }