示例#1
0
        public static void Main(string[] args)
        {
            var triangle = new Triangle(new List <Point>()
            {
                new Point(0, 0), new Point(5, 5), new Point(0, 5)
            });
            var rectangle = new Rectangle(new List <Point>()
            {
                new Point(0, 0), new Point(0, 5), new Point(5, 5), new Point(5, 0)
            });
            var rhombus =
                new Rhombus(new List <Point> {
                new Point(0, 1), new Point(2, 0), new Point(4, 1), new Point(2, 2)
            });
            var areaVisitor = new GetAreaVisitor();

            triangle.Accept(areaVisitor);
            Console.WriteLine(areaVisitor.Result);
            rectangle.Accept(areaVisitor);
            Console.WriteLine(areaVisitor.Result);
            rhombus.Accept(areaVisitor);
            Console.WriteLine(areaVisitor.Result);
            Console.WriteLine();
            var drawVisitor = new DrawingVisitor(new Point(5, 5));

            triangle.Accept(drawVisitor);
            rectangle.Accept(drawVisitor);
            rhombus.Accept(drawVisitor);
            var polygonLoveVisitor = new PolygonLoveVisitor();

            triangle.Accept(polygonLoveVisitor);
            rectangle.Accept(polygonLoveVisitor);
            rhombus.Accept(polygonLoveVisitor);
        }
示例#2
0
        public void Run()
        {
            Dot       d1 = new Dot(0, 0);
            Dot       d2 = new Dot(1, 2);
            Rectangle r  = new Rectangle(1, 5);

            XMLExport xe = new XMLExport();

            d1.Accept(xe);
            d2.Accept(xe);
            r.Accept(xe);
        }
示例#3
0
        static void Main(string[] args)
        {
            //Ex2 Part2
            List <object> operations = new List <object>();


            //Builder Ex8
            FitnessCreator MyFitness = new FitnessCreator(new FitnessBuilderA());

            MyFitness.CreateFitness();
            Console.WriteLine(MyFitness.GetFitnessTraining() + " A");

            MyFitness = new FitnessCreator(new FitnessBuilderB());
            MyFitness.CreateFitness();
            Console.WriteLine(MyFitness.GetFitnessTraining() + " B");

            //Visitor Ex6
            Circle   c      = new Circle("Im Circle");
            IVisitor threeD = new Visitor3D();

            Console.WriteLine($"3D = {c.Accept(threeD)}");

            Rectangle r    = new Rectangle("Im rectangle");
            IVisitor  twoD = new Visitor2D();

            Console.WriteLine($"2D = {r.Accept(twoD)}");

            Triangle t      = new Triangle("Im triangle");
            IVisitor update = new VisitorUpdateResolution();

            Console.WriteLine(t.Accept(update));
            Console.WriteLine(t.Accept(twoD));

            //Decorator Ex10
            IWindow windowBase = new Shading(new _3DLight(new ColorFrame(new BaseWindow())));

            Console.WriteLine(windowBase.GetDetails());

            //Part2 Ex1
            List <string> words = new List <string>
            {
                "java", "jjava", "vaj", "aavj", "j", "vjaa", "dan", "and", "ddan"
            };

            ListWordsOperation.findDuplicateWords(words);
        }
示例#4
0
        static void Main(string[] args)
        {
            #region ############### FIRST TESTS ###############

            Console.WriteLine("#############################################");
            Console.WriteLine("###       FIRST TESTS (Simple tests)       ##");
            Console.WriteLine("#############################################\n");

            // Rectangle : Position (0,0) Length 10 Width 10
            Rectangle rectangle_1 = new Rectangle(10, 10);
            Console.WriteLine("Rectangle 1 creation : Position (0,0) Length 10 Width 10");

            // Rectangle : Position (1,2) Length 12 Width 15
            Rectangle rectangle_2 = new Rectangle(1, 2, 12, 15);
            Console.WriteLine("Rectangle 2 creation : Position (1,2) Length 12 Width 15");

            // Cercle : Position (0,0) Radius 10
            Circle circle_1 = new Circle(10);
            Console.WriteLine("Circle 1 creation : Position (0,0) Radius 10");

            // Cercle : Position (10,4) Radius 12
            Circle circle_2 = new Circle(10, 4, 11);
            Console.WriteLine("Circle 2 creation : Position (10,4) Radius 11");

            // Visitor creation
            Console.WriteLine("Visitor creation");
            ConsoleVisitor visitor = new ConsoleVisitor();

            // Visit 1 : rectangle_1
            Console.WriteLine("\nVisit 1: Rectangle 1\n====================");
            rectangle_1.Accept(visitor);

            // Visit 2 : rectangle_2
            Console.WriteLine("\nVisit 2: Rectangle 2\n====================");
            rectangle_2.Accept(visitor);

            // Visit 3 : circle_1
            Console.WriteLine("\nVisit 3: Circle 1\n=================");
            circle_1.Accept(visitor);

            // Visit 4 : circle_2
            Console.WriteLine("\nVisit 4: Circle 2\n=================");
            circle_2.Accept(visitor);


            Console.WriteLine("\n=================== EOF ===================");
            Console.WriteLine("Press any key to continue to a new test...");
            Console.ReadLine();
            Console.Clear();
            #endregion


            Console.WriteLine("#############################################");
            Console.WriteLine("###      SECOND TESTS (Shapes tests)       ##");
            Console.WriteLine("#############################################\n");

            // ShapeGroup 1 : Position (0,0) Empty group
            ShapeGroup group_1 = new ShapeGroup();
            Console.WriteLine("ShapeGroup 1 : Position (0,0) Empty group");

            // ShapeGroup 2 : Position (2,2) Empty group
            ShapeGroup group_2 = new ShapeGroup(2, 2);
            Console.WriteLine("ShapeGroup 2 : Position (2,2) Empty group");

            // Shape list creation and adding shapes
            List <Shape> shapeList_1 = new List <Shape>();
            shapeList_1.Add(rectangle_1);
            shapeList_1.Add(rectangle_2);
            shapeList_1.Add(circle_1);
            shapeList_1.Add(circle_2);
            group_1.AddShape(rectangle_1);
            group_2.AddShape(rectangle_2);
            Console.WriteLine("shapeList_1 creation and adding rectangle_1, rectangle_2, circle_1, circle_2,");

            // ShapeGroup 3 : Position (0,0) shapList_1 in argument
            ShapeGroup group_3 = new ShapeGroup(shapeList_1);
            Console.WriteLine("ShapeGroup 3 : Position (0,0) shapList_1 in argument");

            // ShapeGroup 4 : Position (4,4) shapList_1 in argument
            ShapeGroup group_4 = new ShapeGroup(4, 4, shapeList_1);
            Console.WriteLine("ShapeGroup 4 : Position (4,4) shapList_1 in argument");

            // Visit 1 : group_1
            Console.WriteLine("\nVisit 1: Shape Group 1\n======================");
            group_1.Accept(visitor);

            // Visit 2 : group_2
            Console.WriteLine("\nVisit 2: Shape Group 2\n======================");
            group_2.Accept(visitor);

            // Visit 3 : group_3
            Console.WriteLine("\nVisit 3: Shape Group 3\n======================");
            group_3.Accept(visitor);

            // Visit 4 : group_4
            Console.WriteLine("\nVisit 4: Shape Group 4\n======================");
            group_4.Accept(visitor);

            Console.WriteLine("\n=================== EOF ===================");
            Console.WriteLine("Press any key to close console...");
            Console.ReadLine();
        }
示例#5
0
 public void VisitRectangle(Rectangle rect)
 {
     rect.Accept(new ReplaceShape(_mouseX - rect.Width / 2, _mouseY - rect.Height / 2));
 }