private Rectangle CreateShape(string shapeType, int width, int height) { if (shapeType == "Rectangle") { var shape = new Rectangle(); shape.SetWidth(width); shape.SetHeight(height); shape.Left = Random.Next(2, Canvas.Width - width + 2); shape.Top = Random.Next(2, Canvas.Height - height + 2); return(shape); } if (shapeType == "Square") { var shape = new Square(); shape.SetWidth(width); shape.SetHeight(height); shape.Left = Random.Next(2, Canvas.Width - width + 2); shape.Top = Random.Next(2, Canvas.Height - height + 2); return(shape); } throw new Exception("Invalid Shape Type"); }