Ejemplo n.º 1
0
 /// <summary>
 /// 生成指定个数的随机数。
 /// </summary>
 /// <returns>生成的随机数数组。</returns>
 private float[] GenerateRandom()
 {
     if (randomCount == 0)
     {
         return(null);
     }
     float[] randoms = new float[randomCount];
     for (int i = 0; i < randomCount; i++)
     {
         randoms[i] = RandomExt.NextSingle();
     }
     return(randoms);
 }
 /// <summary>
 /// 将拼图碎片在给定范围内随机分布。
 /// </summary>
 /// <param name="rect">碎片的分布矩形。</param>
 /// <param name="rotatable">是否允许旋转拼图碎片。</param>
 public void SpreadPieces(RectangleF rect, bool rotatable)
 {
     foreach (JigsawPiece p in this)
     {
         if (rotatable)
         {
             p.Rotate = RandomExt.Next(4) * 90;
         }
         RectangleF bounds = p.Bounds;
         float      x      = RandomExt.NextSingle() * (rect.Width - bounds.Width) + rect.X - bounds.X + p.Offset.X;
         float      y      = RandomExt.NextSingle() * (rect.Height - bounds.Height) + rect.Y - bounds.Y + p.Offset.Y;
         p.Offset = new Vector2(x, y);
     }
 }