diff --git a/GasolineTanker/GasolineTanker/DrawningGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawningGasolineTanker.cs index 64b18a4..e30bf9b 100644 --- a/GasolineTanker/GasolineTanker/DrawningGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawningGasolineTanker.cs @@ -14,11 +14,11 @@ namespace GasolineTanker private int _startPosX = 0; private int _startPosY = 0; //Ширина грузовика - private readonly int _gasolineTankerWidth = 110; + private readonly int _gasolineTankerWidth = 200; //Высота грузовика - private readonly int _gasolineTankerHeight = 60; + private readonly int _gasolineTankerHeight = 100; //Инициализация свойств - public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) + public bool Init(int speed, double weight, Color bodyColor, bool tank, bool signalBeacon, Color additionalColor, int width, int height) { if (width <= _gasolineTankerWidth || height <= _gasolineTankerHeight) @@ -28,8 +28,7 @@ namespace GasolineTanker _pictureWidth = width; _pictureHeight = height; EntityGasolineTanker = new EntityGasolineTanker(); - //!!!!!! - EntityGasolineTanker.Init(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine); + EntityGasolineTanker.Init(speed, weight, bodyColor, tank, signalBeacon, additionalColor); return true; } public void SetPosition(int x, int y) @@ -103,28 +102,61 @@ namespace GasolineTanker return; } Pen pen = new(Color.Black); + Brush bodyBrush = new SolidBrush(EntityGasolineTanker.BodyColor); Brush additionalBrush = new SolidBrush(EntityGasolineTanker.AdditionalColor); + Brush wheelBrush = new SolidBrush(Color.Black); //Дополнительные элементы - if (EntityGasolineTanker.BodyKit) + if (EntityGasolineTanker.Tank) { - //обвес + //Цистерна + g.FillEllipse(additionalBrush, _startPosX + _gasolineTankerWidth / 20 * 3, _startPosY + _gasolineTankerHeight / 10 * 2, _gasolineTankerWidth / 20 * 4, _gasolineTankerHeight / 10 * 4); + g.FillEllipse(additionalBrush, _startPosX + _gasolineTankerWidth / 20 * 9, _startPosY + _gasolineTankerHeight / 10 * 2, _gasolineTankerWidth / 20 * 4, _gasolineTankerHeight / 10 * 4); + Point[] pointsTunk = + { + new Point(_startPosX + _gasolineTankerWidth / 20 * 5, _startPosY + _gasolineTankerHeight / 10 * 2), + new Point(_startPosX + _gasolineTankerWidth / 20 * 11, _startPosY + _gasolineTankerHeight / 10 * 2), + new Point(_startPosX + _gasolineTankerWidth / 20 * 11, _startPosY + _gasolineTankerHeight / 10 * 6), + new Point(_startPosX + _gasolineTankerWidth / 20 * 5, _startPosY + _gasolineTankerHeight / 10 * 6), + }; + g.FillPolygon(additionalBrush, pointsTunk); } - //границы автомобиля - g.DrawEllipse(pen, _startPosX + 10, _startPosY + 5, 20, 20); - g.DrawEllipse(pen, _startPosX + 10, _startPosY + 35, 20, 20); - g.DrawEllipse(pen, _startPosX + 80, _startPosY + 5, 20, 20); - g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20); - g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30); - g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10, 30); - g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52); - //задние фары - Brush brRed = new SolidBrush(Color.Red); - g.FillEllipse(brRed, _startPosX + 10, _startPosY + 5, 20, 20); - g.FillEllipse(brRed, _startPosX + 10, _startPosY + 35, 20, 20); - //передние фары - Brush brYellow = new SolidBrush(Color.Yellow); - g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20, 20); - g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20, 20); + if (EntityGasolineTanker.SignalBeacon) + { + //Маячок + Point[] pointsBeacon = + { + new Point(_startPosX + _gasolineTankerWidth / 20 * 14, _startPosY + _gasolineTankerHeight / 10 * 2), + new Point(_startPosX + _gasolineTankerWidth / 20 * 14, _startPosY + _gasolineTankerHeight / 10 * 1), + new Point(_startPosX + _gasolineTankerWidth / 20 * 15, _startPosY + _gasolineTankerHeight / 10 * 1), + new Point(_startPosX + _gasolineTankerWidth / 20 * 15, _startPosY + _gasolineTankerHeight / 10 * 2), + }; + g.FillPolygon(additionalBrush, pointsBeacon); + //g.DrawPolygon(pen, pointsBeacon); + } + /* + //Граница отрисовки объекта + Point[] pointsBorder = { new Point(_startPosX, _startPosY), + new Point(_startPosX, _startPosY + _gasolineTankerHeight), + new Point(_startPosX + _gasolineTankerWidth, _startPosY + _gasolineTankerHeight), + new Point(_startPosX + _gasolineTankerWidth, _startPosY)}; + + g.DrawPolygon(pen, pointsBorder); + */ + Point[] pointsFrame = { + new Point(_startPosX + _gasolineTankerWidth / 20 * 2, _startPosY + _gasolineTankerHeight / 10 * 6), + new Point(_startPosX + _gasolineTankerWidth / 20 * 13, _startPosY + _gasolineTankerHeight / 10 * 6), + new Point(_startPosX + _gasolineTankerWidth / 20 * 13, _startPosY + _gasolineTankerHeight / 10 * 2), + new Point(_startPosX + _gasolineTankerWidth / 20 * 16, _startPosY + _gasolineTankerHeight / 10 * 2), + new Point(_startPosX + _gasolineTankerWidth / 20 * 18, _startPosY + _gasolineTankerHeight / 10 * 5), + new Point(_startPosX + _gasolineTankerWidth / 20 * 18, _startPosY + _gasolineTankerHeight / 10 * 7), + new Point(_startPosX + _gasolineTankerWidth / 20 * 2, _startPosY + _gasolineTankerHeight / 10 * 7),}; + + g.FillPolygon(bodyBrush, pointsFrame); + g.DrawPolygon(pen, pointsFrame); + //Колёса + g.FillEllipse(wheelBrush, _startPosX + _gasolineTankerWidth / 20 * 3, _startPosY + _gasolineTankerHeight / 10 * 7, _gasolineTankerWidth / 20 * 2, _gasolineTankerHeight / 10 * 2); + g.FillEllipse(wheelBrush, _startPosX + _gasolineTankerWidth / 20 * 5, _startPosY + _gasolineTankerHeight / 10 * 7, _gasolineTankerWidth / 20 * 2, _gasolineTankerHeight / 10 * 2); + g.FillEllipse(wheelBrush, _startPosX + _gasolineTankerWidth / 20 * 15, _startPosY + _gasolineTankerHeight / 10 * 7, _gasolineTankerWidth / 20 * 2, _gasolineTankerHeight / 10 * 2); } } } diff --git a/GasolineTanker/GasolineTanker/EntityGasolineTanker.cs b/GasolineTanker/GasolineTanker/EntityGasolineTanker.cs index 63aca0a..bf89b23 100644 --- a/GasolineTanker/GasolineTanker/EntityGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/EntityGasolineTanker.cs @@ -13,26 +13,23 @@ namespace GasolineTanker public double Weight { get; private set; } // Основной цвет public Color BodyColor { get; private set; } + //Наличие цистерны + public bool Tank { get; private set; } + //Наличие сигнального маяка + public bool SignalBeacon { get; private set; } //Дополнительный цвет public Color AdditionalColor { get; private set; } - //Наличие обвеса - public bool BodyKit { get; private set; } - //Наличие антикрыла - public bool Wing { get; private set; } - //Наличие гоночной полосы - public bool SportLine { get; private set; } //Шаг перемещения public double Step => (double)Speed * 100 / Weight; //Инициализация полей Грузовика - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine) + public void Init(int speed, double weight, Color bodyColor, bool tank, bool signalBeacon, Color additionalColor) { Speed = speed; Weight = weight; BodyColor = bodyColor; + Tank = tank; + SignalBeacon = signalBeacon; AdditionalColor = additionalColor; - BodyKit = bodyKit; - Wing = wing; - SportLine = sportLine; } } } diff --git a/GasolineTanker/GasolineTanker/Form1.cs b/GasolineTanker/GasolineTanker/Form1.cs index dc907fb..224dafa 100644 --- a/GasolineTanker/GasolineTanker/Form1.cs +++ b/GasolineTanker/GasolineTanker/Form1.cs @@ -20,19 +20,20 @@ namespace GasolineTanker private void ButtonCreate_Click(object sender, EventArgs e) { + Random random = new(); _drawningGasolineTanker = new DrawningGasolineTanker(); - _drawningGasolineTanker.Init(random.Next(100, 300), + _drawningGasolineTanker.Init( + random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Convert.ToBoolean(random.Next(0, 2)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), + Convert.ToBoolean(random.Next(0, 2)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), PictureBoxGasolineTanker.Width, PictureBoxGasolineTanker.Height); _drawningGasolineTanker.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); } private void ButtonMove_Click(object sender, EventArgs e)