static void Main() { Form form = new Form(); form.Width = 800; form.Height = 600; DrawingBoard.Init(form); form.Show(); //DrawingBoard.Draw(); //Использование абстрактной фабрики IFigureFactory figureFactory = LoadFactory(); for (int i = 0; i < 20; i++) { IDrawAPI circle = figureFactory.GetFigure("CircleFigure"); circle.DrawAt(random.Next(0, DrawingBoard.Width - MAXWIDTHOFFSET), random.Next(TEXTOFFSET, DrawingBoard.Height - MAXHEIGTHOFFSET)); } for (int i = 0; i < 20; i++) { IDrawAPI circle = figureFactory.GetFigure("SquareFigure"); circle.DrawAt(random.Next(0, DrawingBoard.Width - MAXWIDTHOFFSET), random.Next(TEXTOFFSET, DrawingBoard.Height - MAXHEIGTHOFFSET)); } for (int i = 0; i < 20; i++) { IDrawAPI circle = figureFactory.GetFigure("RectangleFigure"); circle.DrawAt(random.Next(0, DrawingBoard.Width - MAXWIDTHOFFSET), random.Next(TEXTOFFSET, DrawingBoard.Height - MAXHEIGTHOFFSET)); } DrawingBoard.Buffer.Graphics.DrawString($"Circle instances:{CircleFigure.ObjectCounter}" + $"\nSquare instances:{SquareFigure.ObjectCounter}" + $"\nRectangle instances:{RectangleFigure.ObjectCounter}", SystemFonts.DefaultFont, Brushes.White, 0, 0); DrawingBoard.Draw(); Application.Run(form); }
private void Form1_MouseClick(object sender, MouseEventArgs e) { var figure = _figureFactory.GetFigure(); int.TryParse(WidthTxtBx.Text, out int width); int.TryParse(HeightTxtBx.Text, out int height); if (width > 0 && height > 0) { if (figure is CustomRectangle) { AdjustFigureSettings(figure, new Size(width, height)); if (OffRdBtn.Checked) { figure.Points[0] = e.Location; } } else if (figure is Circle) { AdjustFigureSettings(figure, new Size(width, height)); figure.Points[0] = e.Location; } else if (figure is Rhomb) { AdjustFigureSettings(figure, new Size(width, height)); figure.Points[0] = e.Location; figure.Points[1].X = figure.Points[0].X - width; figure.Points[1].Y = figure.Points[0].Y + height; figure.Points[2].X = figure.Points[0].X; figure.Points[2].Y = figure.Points[1].Y + height; figure.Points[3].X = figure.Points[0].X + width; figure.Points[3].Y = figure.Points[2].Y - height; } else { AdjustFigureSettings(figure, new Size(width, height)); if ((FigureNamesCmbBx.SelectedItem as string) == FigureNames.UpsideDownTriangle) { figure.Points[0] = e.Location; figure.Points[1].X = e.Location.X - width; figure.Points[1].Y = e.Location.Y - height; figure.Points[2].X = e.Location.X + width; figure.Points[2].Y = e.Location.Y - height; } else { figure.Points[0] = e.Location; figure.Points[1].X = e.Location.X - width; figure.Points[1].Y = e.Location.Y + height; figure.Points[2].X = e.Location.X + width; figure.Points[2].Y = e.Location.Y + height; } } _figures.Add(figure); this.Refresh(); } }