Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Composite c1 = new Composite("c1");
            Composite c2 = new Composite("c2");

            c1.AddComponent(c2);
            c1.AddComponent(new Leaf("l11"));
            c1.AddComponent(new Leaf("l12"));
            c2.AddComponent(new Leaf("l21"));

            c1.Operation();
        }
Ejemplo n.º 2
0
        // Создать и нарисовать композит
        private void BtnComposite_Click(object sender, RoutedEventArgs e)
        {
            Composite picture = new Composite("picture", 0, 0);

            Composite background = new Composite("background", 0, 0);

            background.AddComponent(new ShapeComponent("border1", 0, 0, new Rectangle()
            {
                Fill = Brushes.Black, Width = 206, Height = 206
            }));
            background.AddComponent(new ShapeComponent("border2", 1, 1, new Rectangle()
            {
                Fill = Brushes.LightCoral, Width = 204, Height = 204
            }));
            background.AddComponent(new ShapeComponent("page", 3, 3, new Rectangle()
            {
                Fill = Brushes.White, Width = 200, Height = 200
            }));
            picture.AddComponent(background);

            Composite bushes = new Composite("bushes", 0, 154);

            bushes.AddComponent(new ShapeComponent("bush_1", 10, 0, new Tree()
            {
                Stroke = Brushes.LightGreen, Width = 100, Height = 50, Levels = 8, StrokeThickness = 2, TrunkFactor = 0.2, BranchFactor = 0.85
            }));
            bushes.AddComponent(new ShapeComponent("bush_2", 40, 0, new Tree()
            {
                Stroke = Brushes.Green, Width = 100, Height = 50, Levels = 8, StrokeThickness = 2, TrunkFactor = 0.2, BranchFactor = 0.85
            }));
            bushes.AddComponent(new ShapeComponent("bush_3", 70, 0, new Tree()
            {
                Stroke = Brushes.LightGreen, Width = 100, Height = 50, Levels = 8, StrokeThickness = 2, TrunkFactor = 0.2, BranchFactor = 0.85
            }));
            bushes.AddComponent(new ShapeComponent("bush_4", 100, 0, new Tree()
            {
                Stroke = Brushes.Green, Width = 100, Height = 50, Levels = 8, StrokeThickness = 2, TrunkFactor = 0.2, BranchFactor = 0.85
            }));
            picture.AddComponent(bushes);

            picture.AddComponent(new ShapeComponent("main_tree", 3, 4, new Tree()
            {
                Stroke = Brushes.Blue, Width = 200, Height = 200, Levels = 10, StrokeThickness = 2, TrunkFactor = 0.24, BranchFactor = 0.65, DeltaAngle = 25
            }));

            picture.Draw(canvas, canvas.ActualWidth * 0.5 - 100, 50);

            IComponent component = picture.Find("main_tree");

            Logger.Log($"По имени 'main_tree' был найден компонент {component.Title}");
        }
Ejemplo n.º 3
0
        public void Test()
        {
            Composite composite = new Composite();

            composite.AddComponent(new Leaf());
            composite.DoSomething();
        }