示例#1
0
文件: Program.cs 项目: jonwa/CSharp
        private static Shape[] GetListOfShapes(int amount)
        {
            Shape[] ret = new Shape[amount];
            for (int i = 0; i < amount; ++i)
            {
                ret[i] = _prototypes[_random.Next(0, 3)];
                RandomizeShape(ret[i]);
            }

            return ret;
        }
示例#2
0
文件: Program.cs 项目: jonwa/CSharp
 private static void RandomizeShape(Shape shape)
 {
     if(shape.GetType() == typeof(Triangle))
     {
         ((Triangle)shape).Base = (double)_random.Next(1, 40);
         ((Triangle)shape).Height = (double)_random.Next(1, 40);
     }
     else if (shape.GetType() == typeof(Circle))
     {
         ((Circle)shape).Radius = (double)_random.Next(1, 40);
     }
     else if(shape.GetType() == typeof(Rectangle))
     {
         ((Rectangle)shape).Width = (double)_random.Next(1, 40);
         ((Rectangle)shape).Height = (double)_random.Next(1, 40);
     }
 }