public void CompositeDemo()
        {
            Form1.commandLogger.logMessage(AbstractLogger.TEST, "\n\n Composite Test: \n");
            CompositeDecoration tree    = new CompositeDecoration("tree");
            CompositeDecoration branch1 = new CompositeDecoration("raudoni objektai");

            branch1.Add(new Leaf("leaf1", "red", 1, 1, 1, 1));
            branch1.Add(new Leaf("leaf2", "red", 2, 2, 2, 2));
            CompositeDecoration branch2 = new CompositeDecoration("geltoni objektai");

            branch2.Add(new Leaf("leaf3", "yellow", 3, 3, 3, 3));
            branch2.Add(new Leaf("leaf4", "yellow", 4, 4, 4, 4));
            tree.Add(branch1);
            tree.Add(branch2);

            Form1.commandLogger.logMessage(AbstractLogger.TEST, "\n\n tree display: " + tree.Display(1));
            Form1.commandLogger.logMessage(AbstractLogger.TEST, "\n");

            List <Component> test  = branch1.GetChild();
            List <Component> test2 = branch2.GetChild();
            int s = test2.Count() + 1;

            for (int i = 1; i < s; i++)
            {
                string branch = "branch" + i;

                if (branch.Equals("branch1"))
                {
                    foreach (var a in test)
                    {
                        Form1.commandLogger.logMessage(AbstractLogger.TEST, a.GetColor() + " " + a.GetX() + " " + a.GetY() + " " + a.GetWidth() + " " + a.GetHeight() + "\n");
                    }
                }
                else
                {
                    foreach (var a in test2)
                    {
                        Form1.commandLogger.logMessage(AbstractLogger.TEST, a.GetColor() + " " + a.GetX() + " " + a.GetY() + " " + a.GetWidth() + " " + a.GetHeight() + "\n");
                    }
                }
            }

            Form1.commandLogger.logMessage(AbstractLogger.TEST, "\n");
        }
示例#2
0
        private void PictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Graphics canvas = e.Graphics;

            canvas.FillRectangle(Brushes.Green, tower1.X, tower1.Y, tower1.Height, tower1.Width);
            canvas.FillRectangle(Brushes.Orange, tower2.X, tower2.Y, tower2.Height, tower2.Width);
            //piešiame takelį, kuriuo vaikščios monstrai
            foreach (Rectangle item in mapPath.rectangles)
            {
                canvas.FillRectangle(Brushes.LightCoral, item.X, item.Y, item.Height, item.Width);
            }

            foreach (Monster mon in monsters)
            {
                canvas.FillRectangle(Brushes.Azure, mon.PosX, mon.PosY, 20, 20);
            }

            //--------------------------------------------------------------------------------------------------

            CompositeDecoration tree    = new CompositeDecoration("tree");
            CompositeDecoration branch1 = new CompositeDecoration("rudi objektai");

            //                                 iligs|Plotis|x|y
            branch1.Add(new Leaf("leaf1", "Brown", 5, 40, 5, 40));
            branch1.Add(new Leaf("leaf2", "Brown", 25, 5, 5, 40));
            branch1.Add(new Leaf("leaf3", "Brown", 20, 5, 5, 60));
            branch1.Add(new Leaf("leaf4", "Brown", 25, 5, 5, 80));

            branch1.Add(new Leaf("leaf15", "Brown", 5, 30, 0, 150));
            branch1.Add(new Leaf("leaf16", "Brown", 35, 5, 0, 150));
            branch1.Add(new Leaf("leaf17", "Brown", 5, 30, 15, 150));
            branch1.Add(new Leaf("leaf18", "Brown", 5, 30, 30, 150));
            CompositeDecoration branch2 = new CompositeDecoration("Juodi objektai");

            branch2.Add(new Leaf("leaf5", "Black", 5, 40, 5, 100));
            branch2.Add(new Leaf("leaf6", "Black", 6, 6, 10, 118));
            branch2.Add(new Leaf("leaf7", "Black", 6, 6, 14, 113));
            branch2.Add(new Leaf("leaf8", "Black", 6, 6, 18, 109));
            branch2.Add(new Leaf("leaf9", "Black", 6, 6, 22, 104));
            branch2.Add(new Leaf("leaf10", "Black", 6, 6, 25, 100));
            branch2.Add(new Leaf("leaf11", "Black", 6, 6, 14, 122));
            branch2.Add(new Leaf("leaf12", "Black", 6, 6, 18, 126));
            branch2.Add(new Leaf("leaf13", "Black", 6, 6, 22, 130));
            branch2.Add(new Leaf("leaf14", "Black", 6, 6, 25, 134));
            tree.Add(branch1);
            tree.Add(branch2);



            List <GameServer.Models.Component> test  = branch1.GetChild();
            List <GameServer.Models.Component> test2 = branch2.GetChild();
            int s = test2.Count() + 1;

            for (int i = 1; i < s; i++)
            {
                string branch = "branch" + i;

                if (branch.Equals("branch1"))
                {
                    foreach (var a in test)
                    {
                        // string color = a.GetColor();
                        canvas.FillRectangle(Brushes.Brown, a.GetX(), a.GetY(), a.GetWidth(), a.GetHeight());
                        //Form1.commandLogger.logMessage(AbstractLogger.TEST, a.GetColor() + " " + a.GetX() + " " + a.GetY() + " " + a.GetWidth() + " " + a.GetHeight() + "\n");
                    }
                }
                else
                {
                    foreach (var a in test2)
                    {
                        canvas.FillRectangle(Brushes.Black, a.GetX(), a.GetY(), a.GetWidth(), a.GetHeight());

                        //Form1.commandLogger.logMessage(AbstractLogger.TEST, a.GetColor() + " " + a.GetX() + " " + a.GetY() + " " + a.GetWidth() + " " + a.GetHeight() + "\n");
                    }
                }
            }
            //-------------------------------------------------------------------------------

            //No flyweight

            /*
             * if (ambient.Count == 200)
             * {
             *  foreach (Decoration deco in ambient)
             *  {
             *      switch (deco.name)
             *      {
             *          case ("Log"):
             *              canvas.FillRectangle(Brushes.Brown, deco.GetX(), deco.GetY(), deco.GetWidth(), deco.GetHeight());
             *              break;
             *          case ("Rock"):
             *              canvas.FillRectangle(Brushes.DarkSlateGray, deco.GetX(), deco.GetY(), deco.GetWidth(), deco.GetHeight());
             *              break;
             *          case ("Water"):
             *              canvas.FillRectangle(Brushes.Blue, deco.GetX(), deco.GetY(), deco.GetWidth(), deco.GetHeight());
             *              break;
             *          case ("Leaf"):
             *              canvas.FillRectangle(Brushes.ForestGreen, deco.GetX(), deco.GetY(), deco.GetWidth(), deco.GetHeight());
             *              break;
             *
             *      }
             *  }
             *  if (decorated == false)
             *  {
             *      richTextBox1.AppendText("dekoravimas atliktas per: " + time + " tick'ų");
             *      decorated = true;
             *  }
             * }
             */

            //Flyweight

            int z = 0;

            if (coord.Count() == 600)
            {
                for (int i = 0; i < 200; i++)
                {
                    int type = coord[z];
                    z++;
                    IDecoration deco;
                    switch (type)
                    {
                    case (0):
                        deco = df.GetDecoration("Log");
                        canvas.FillRectangle(Brushes.Brown, coord[z], coord[z + 1], deco.GetWidth(), deco.GetHeight());
                        z += 2;
                        break;

                    case (1):
                        deco = df.GetDecoration("Rock");
                        canvas.FillRectangle(Brushes.DarkSlateGray, coord[z], coord[z + 1], deco.GetWidth(), deco.GetHeight());
                        z += 2;
                        break;

                    case (2):
                        deco = df.GetDecoration("Water");
                        canvas.FillRectangle(Brushes.Blue, coord[z], coord[z + 1], deco.GetWidth(), deco.GetHeight());
                        z += 2;
                        break;

                    case (3):
                        deco = df.GetDecoration("Leaf");
                        canvas.FillRectangle(Brushes.ForestGreen, coord[z], coord[z + 1], deco.GetWidth(), deco.GetHeight());
                        z += 2;
                        break;
                    }
                }
                if (decorated == false)
                {
                    richTextBox1.AppendText("dekoravimas atliktas per: " + time + " tick'ų\n");
                    decorated = true;
                }
            }
        }