Exemplo n.º 1
0
        public static Shape GenerateShape(ShapeID t)
        {
            Random rand = new Random();

            switch (t)
            {
            case ShapeID.Triangle:
            {
                string   ID       = rand.Next().ToString();
                Triangle triangle = new Triangle(ID, rand.Next(15), rand.Next(15), rand.Next(15));
                if (triangle._exist())
                {
                    Console.WriteLine("我是一个随机生成的三角形!我的面积是:" + triangle.area + " !我的随机编号是:" + ID + "!"); return(triangle);
                }
                else
                {
                    Console.WriteLine("随即生成的三条边居然无法构成一个三角形!可恶,只好生成一个边长为2的默认三角形啦qaq");
                    return(new Triangle(ID, 2, 2, 2));
                }
            }

            case ShapeID.Rectangle:
            {
                string    ID        = rand.Next().ToString();
                Rectangle rectangle = new Rectangle(ID, rand.Next(15), rand.Next(15));
                Console.WriteLine("我是一个随机生成的矩形!我的面积是:" + rectangle.area + " !我的随机编号是:" + ID + "!");
                return(rectangle);
            }
            }
            throw new InvalidEnumArgumentException();
        }
Exemplo n.º 2
0
 private Model.Shape GenerateShape(ShapeID id, int index, Color color, List <Point> points)
 {
     Model.Shape shape = new Model.Shape(id, index);
     foreach (Point p in points)
     {
         shape.ShapeMembers.Add(new Cell(HelperMethods.CloneRectangle(_cellRectangle, new SolidColorBrush(Colors.Black), new SolidColorBrush(color)), (int)p.X, (int)p.Y));
     }
     return(shape);
 }
Exemplo n.º 3
0
 public Shape(ShapeID id, int index)
 {
     ID    = id;
     Index = index;
 }