예제 #1
0
파일: Program.cs 프로젝트: lineaalba/Shapes
        /// <summary>
        /// Returns a list with shapes.
        /// </summary>
        private static List <string> ShapeLists(bool is3D)
        {
            RandomClass random = new RandomClass();

            List <Shape2D> shapes2d = new List <Shape2D>();
            List <Shape3D> shapes3d = new List <Shape3D>();
            List <string>  shapes   = new List <string>();
            Shape2D        shape2d;
            Shape3D        shape3d;
            ShapeType      shapeType;

            int min = 1;
            int max = 50;

            Random r            = new Random();
            int    randomNumber = r.Next(5, 16);

            for (int i = 0; i < randomNumber; i++)
            {
                shapeType = (ShapeType)random.RandomShape(is3D);

                if (shapeType == ShapeType.Cuboid)
                {
                    shape3d = new Cuboid(random.RandomNumberShapes(min, max), random.RandomNumberShapes(min, max), random.RandomNumberShapes(min, max));
                    shapes3d.Add(shape3d);
                }
                else if (shapeType == ShapeType.Cylinder)
                {
                    shape3d = new Cylinder(random.RandomNumberShapes(min, max), random.RandomNumberShapes(min, max), random.RandomNumberShapes(min, max));
                    shapes3d.Add(shape3d);
                }
                else if (shapeType == ShapeType.Sphere)
                {
                    shape3d = new Sphere(random.RandomNumberShapes(min, max));
                    shapes3d.Add(shape3d);
                }
                else if (shapeType == ShapeType.Ellipse)
                {
                    shape2d = new Ellipse(random.RandomNumberShapes(min, max), random.RandomNumberShapes(min, max));
                    shapes2d.Add(shape2d);
                }
                else if (shapeType == ShapeType.Rectangle)
                {
                    shape2d = new Rectangle(random.RandomNumberShapes(min, max), random.RandomNumberShapes(min, max));
                    shapes2d.Add(shape2d);
                }
            }

            if (is3D)
            {
                shapes3d = shapes3d.OrderBy(x => x.ShapeType)
                           .ThenBy(x => x.Volume)
                           .ToList();
                foreach (var i in shapes3d)
                {
                    shapes.Add(i.ToString("R"));
                }
            }
            else
            {
                shapes2d = shapes2d.OrderBy(x => x.ShapeType)
                           .ThenBy(x => x.Area)
                           .ToList();
                foreach (var i in shapes2d)
                {
                    shapes.Add(i.ToString("R"));
                }
            }

            return(shapes);
        }