diff --git a/Bulldozer/Bulldozer/Direction.cs b/Bulldozer/Bulldozer/Direction.cs new file mode 100644 index 0000000..9dd27b4 --- /dev/null +++ b/Bulldozer/Bulldozer/Direction.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bulldozer +{ + public enum DirectionType + { + Up = 1, + + Down = 2, + + Left = 3, + + Right = 4 + } +} diff --git a/Bulldozer/Bulldozer/DrawningBulldozer.cs b/Bulldozer/Bulldozer/DrawningBulldozer.cs new file mode 100644 index 0000000..0ad080c --- /dev/null +++ b/Bulldozer/Bulldozer/DrawningBulldozer.cs @@ -0,0 +1,207 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bulldozer +{ + public class DrawningBulldozer + { + /// + /// Класс-сущность + /// + public EntityBulldozer? EntityBulldozer { get; private set; } + /// + /// Ширина окна + /// + private int _pictureWidth; + /// + /// Высота окна + /// + private int _pictureHeight; + /// + /// Левая координата прорисовки бульдозера + /// + private int _startPosX; + /// + /// Верхняя кооридната прорисовки бульдозера + /// + private int _startPosY; + /// + /// Ширина прорисовки бульдозера + /// + private readonly int bulldozerWidth = 170; + /// + /// Высота прорисовки бульдозера + /// + private readonly int bulldozerHeight = 85; + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Цвет для ковша + /// Признак наличия переднего ковша + /// Признак наличия заднего ковша + /// Ширина картинки + /// Высота картинки + /// true - объект создан, false - проверка не пройдена, + public bool Init(int speed, double weight, Color bulldozerColor, Color cabinColor, Color covshColor, bool hasMoldboardfront, bool hasRipper, int width, int height) + { + if (width < _pictureWidth || height < _pictureHeight) + { + return false; + } + _pictureWidth = width; + _pictureHeight = height; + EntityBulldozer = new EntityBulldozer(); + EntityBulldozer.Init(speed, weight, bulldozerColor, cabinColor, covshColor, hasMoldboardfront, hasRipper); + return true; + } + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + if (x <= _pictureWidth - bulldozerWidth && y <= _pictureHeight - bulldozerHeight) + { + _startPosX = x; + _startPosY = y; + } + } + /// + /// Изменение направления перемещения + /// + /// Направление + public void MoveTransport(DirectionType direction) + { + if (EntityBulldozer == null) + + { + return; + } + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX - EntityBulldozer.Step > 0) + { + _startPosX -= (int)EntityBulldozer.Step; + } + if (_startPosX - EntityBulldozer.Step < 0) + { + _startPosX -= _startPosX - (int)EntityBulldozer.Step; + } + break; + //вверх + case DirectionType.Up: + if (_startPosY - EntityBulldozer.Step > 0) + { + _startPosY -= (int)EntityBulldozer.Step; + } + else if (_startPosY - EntityBulldozer.Step < 0) + { + _startPosY -= _startPosY - (int)EntityBulldozer.Step; + } + break; + // вправо + case DirectionType.Right: + if (_startPosX + EntityBulldozer.Step + bulldozerWidth < _pictureWidth) + { + _startPosX += (int)EntityBulldozer.Step; + } + else if (_startPosX + EntityBulldozer.Step + bulldozerWidth > _pictureWidth) + { + _startPosX += _pictureWidth - _startPosX - bulldozerWidth; + } + break; + //вниз + case DirectionType.Down: + if (_startPosY + EntityBulldozer.Step + bulldozerHeight < _pictureHeight) + { + _startPosY += (int)EntityBulldozer.Step; + } + else if (_startPosY + EntityBulldozer.Step + bulldozerHeight > _pictureHeight) + { + _startPosY += _pictureHeight - _startPosY - bulldozerHeight; + } + break; + } + } + /// + /// Прорисовка объекта + /// + /// + public void DrawTransport(Graphics g) + { + if (EntityBulldozer == null) + { + return; + } + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(EntityBulldozer.CabinColor); + + // Тело трактора + Brush bulldozerColor = new SolidBrush(EntityBulldozer.BulldozerColor); + g.FillRectangle(bulldozerColor, _startPosX + 25, _startPosY + 20, 110, 30); + g.FillRectangle(bulldozerColor, _startPosX + 60, _startPosY, 10, 30); + + int x = _startPosX + 30; // начальная позиция X + int y = _startPosY; // начальная позиция Y + int width = 110; // ширина прямоугольника + int height = 30; // высота прямоугольника + int radius = 20; // радиус закругления углов + + // Рисуем закругленный прямоугольник + g.DrawArc(pen, x - 5, y + 50, radius * 2, radius * 2, 180, 90); // верхний левый угол + g.DrawLine(pen, x + radius - 5, y + 50, x + width - radius - 5, y + 50); // верхняя горизонталь + g.DrawArc(pen, x + width - radius * 2 - 5, y + 50, radius * 2, radius * 2, 270, 90); // верхний правый угол + g.DrawArc(pen, x + width - radius * 2 - 5, y + height - radius * 2 + 50, radius * 2, radius * 2, 0, 90); // нижний правый угол + g.DrawLine(pen, x + width - radius - 5, y + height + 50, x + radius - 5, y + height + 50); // нижняя горизонталь + g.DrawArc(pen, x - 5, y + height - radius * 2 + 50, radius * 2, radius * 2, 90, 90); // нижний левый угол + + int wheelRadius = 15; + + // Рисуем колеса трактора + g.DrawEllipse(pen, _startPosX + 30, _startPosY + 50, wheelRadius * 2, wheelRadius * 2); + g.FillEllipse(additionalBrush, _startPosX + 30, _startPosY + 50, wheelRadius * 2, wheelRadius * 2); + g.DrawEllipse(pen, _startPosX + 65, _startPosY + 50, wheelRadius * 2, wheelRadius * 2); + g.FillEllipse(additionalBrush, _startPosX + 65, _startPosY + 50, wheelRadius * 2, wheelRadius * 2); + g.DrawEllipse(pen, _startPosX + 100, _startPosY + 50, wheelRadius * 2, wheelRadius * 2); + g.FillEllipse(additionalBrush, _startPosX + 100, _startPosY + 50, wheelRadius * 2, wheelRadius * 2); + + // Кабина + Brush cabinColor = new SolidBrush(EntityBulldozer.CabinColor); + g.FillRectangle(cabinColor, _startPosX + 105, _startPosY, 30, 20); + + // Рисуем ковш спереди + if (EntityBulldozer.HasMoldboardfront) + { + Point[] trianglePoints = new Point[] + { + new Point(_startPosX + 25, _startPosY + 30), + new Point(_startPosX + 25, _startPosY + 80), + new Point(_startPosX, _startPosY + 80), + }; + g.DrawPolygon(pen, trianglePoints); + } + // Рисуем ковш сзади + if (EntityBulldozer.HasRipper) + { + Point[] trianglePoints2 = new Point[] + { + new Point(_startPosX + 130, _startPosY + 50), + new Point(_startPosX + 160, _startPosY + 50), + new Point(_startPosX + 160, _startPosY + 80) + + }; + g.DrawPolygon(pen, trianglePoints2); + } + } + } +} diff --git a/Bulldozer/Bulldozer/EntityBulldozer.cs b/Bulldozer/Bulldozer/EntityBulldozer.cs new file mode 100644 index 0000000..75372f8 --- /dev/null +++ b/Bulldozer/Bulldozer/EntityBulldozer.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bulldozer +{ + public class EntityBulldozer + { + /// + /// Скорость + /// + public int Speed { get; private set; } + /// + /// Вес + /// + public double Weight { get; private set; } + /// + /// Основной цвет + /// + public Color BulldozerColor { get; private set; } + /// + /// Дополнительный цвет (для опциональных элементов) + /// + public Color CabinColor { get; private set; } + public Color CovshColor { get; private set; } + /// + /// Признак (опция) наличия переднего ковша + /// + public bool HasMoldboardfront { get; private set; } + /// + /// Признак (опция) наличия заднего ковша + /// + public bool HasRipper { get; private set; } + /// + /// Шаг перемещения автомобиля + /// + public double Step => (double)Speed * 100 / Weight; + /// + /// Инициализация полей объекта-класса спортивного автомобиля + /// + /// Скорость + /// Вес автомобиля + /// Основной цвет + /// Дополнительный цвет + /// Цвет для ковша + /// Признак наличия переднего ковша + /// Признак наличия заднего ковша + public void Init(int speed, double weight, Color bulldozerColor, Color cabinColor, Color covshColor, bool hasMoldboardfront, bool hasRipper) + { + Speed = speed; + Weight = weight; + BulldozerColor = bulldozerColor; + CabinColor = cabinColor; + CovshColor = covshColor; + HasMoldboardfront = hasMoldboardfront; + HasRipper = hasRipper; + } + } +} diff --git a/Bulldozer/Bulldozer/Form1.Designer.cs b/Bulldozer/Bulldozer/Form1.Designer.cs deleted file mode 100644 index 24dbf88..0000000 --- a/Bulldozer/Bulldozer/Form1.Designer.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace Bulldozer -{ - partial class FormBulldozer - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - SuspendLayout(); - // - // FormBulldozer - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Name = "FormBulldozer"; - Text = "Form1"; - ResumeLayout(false); - } - - #endregion - } -} \ No newline at end of file diff --git a/Bulldozer/Bulldozer/Form1.cs b/Bulldozer/Bulldozer/Form1.cs deleted file mode 100644 index 34d95c6..0000000 --- a/Bulldozer/Bulldozer/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Bulldozer -{ - public partial class FormBulldozer : Form - { - public FormBulldozer() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/Bulldozer/Bulldozer/FormBulldozer.Designer.cs b/Bulldozer/Bulldozer/FormBulldozer.Designer.cs new file mode 100644 index 0000000..4a14d64 --- /dev/null +++ b/Bulldozer/Bulldozer/FormBulldozer.Designer.cs @@ -0,0 +1,136 @@ +namespace Bulldozer +{ + partial class FormBulldozer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + pictureBoxBulldozer = new PictureBox(); + ButtonCreateBulldozer = new Button(); + buttonLeft = new Button(); + buttonRight = new Button(); + buttonUp = new Button(); + buttonDown = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).BeginInit(); + SuspendLayout(); + // + // pictureBoxBulldozer + // + pictureBoxBulldozer.Dock = DockStyle.Fill; + pictureBoxBulldozer.Location = new Point(0, 0); + pictureBoxBulldozer.Name = "pictureBoxBulldozer"; + pictureBoxBulldozer.Size = new Size(800, 450); + pictureBoxBulldozer.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxBulldozer.TabIndex = 0; + pictureBoxBulldozer.TabStop = false; + // + // ButtonCreateBulldozer + // + ButtonCreateBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + ButtonCreateBulldozer.Location = new Point(54, 396); + ButtonCreateBulldozer.Name = "ButtonCreateBulldozer"; + ButtonCreateBulldozer.Size = new Size(75, 23); + ButtonCreateBulldozer.TabIndex = 1; + ButtonCreateBulldozer.Text = "Создать"; + ButtonCreateBulldozer.UseVisualStyleBackColor = true; + ButtonCreateBulldozer.Click += ButtonCreateBulldozer_Click; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; + buttonLeft.Location = new Point(660, 373); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(30, 30); + buttonLeft.TabIndex = 2; + buttonLeft.Text = "<"; + buttonLeft.UseVisualStyleBackColor = true; + buttonLeft.Click += ButtonMove_Click; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImageLayout = ImageLayout.Zoom; + buttonRight.Location = new Point(732, 373); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(30, 30); + buttonRight.TabIndex = 3; + buttonRight.Text = ">"; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += ButtonMove_Click; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImageLayout = ImageLayout.Zoom; + buttonUp.Location = new Point(696, 342); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(30, 30); + buttonUp.TabIndex = 4; + buttonUp.Text = "^"; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += ButtonMove_Click; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImageLayout = ImageLayout.Zoom; + buttonDown.Location = new Point(696, 403); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(30, 30); + buttonDown.TabIndex = 5; + buttonDown.Text = "v"; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += ButtonMove_Click; + // + // FormBulldozer + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonDown); + Controls.Add(buttonUp); + Controls.Add(buttonRight); + Controls.Add(buttonLeft); + Controls.Add(ButtonCreateBulldozer); + Controls.Add(pictureBoxBulldozer); + Name = "FormBulldozer"; + Text = "Бульдозер"; + ((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private PictureBox pictureBoxBulldozer; + private Button ButtonCreateBulldozer; + private Button buttonLeft; + private Button buttonRight; + private Button buttonUp; + private Button buttonDown; + } +} \ No newline at end of file diff --git a/Bulldozer/Bulldozer/FormBulldozer.cs b/Bulldozer/Bulldozer/FormBulldozer.cs new file mode 100644 index 0000000..516e779 --- /dev/null +++ b/Bulldozer/Bulldozer/FormBulldozer.cs @@ -0,0 +1,63 @@ +using System.Windows.Forms; + +namespace Bulldozer +{ + public partial class FormBulldozer : Form + { + private DrawningBulldozer? _drawningBulldozer; + public FormBulldozer() + { + InitializeComponent(); + } + private void Draw() + { + if (_drawningBulldozer == null) + { + return; + } + Bitmap bmp = new(pictureBoxBulldozer.Width, + pictureBoxBulldozer.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningBulldozer.DrawTransport(gr); + pictureBoxBulldozer.Image = bmp; + } + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_drawningBulldozer == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _drawningBulldozer.MoveTransport(DirectionType.Up); + break; + case "buttonDown": + _drawningBulldozer.MoveTransport(DirectionType.Down); + break; + case "buttonLeft": + _drawningBulldozer.MoveTransport(DirectionType.Left); + break; + case "buttonRight": + _drawningBulldozer.MoveTransport(DirectionType.Right); + break; + } + Draw(); + } + + private void ButtonCreateBulldozer_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningBulldozer = new DrawningBulldozer(); + _drawningBulldozer.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)), pictureBoxBulldozer.Width, pictureBoxBulldozer.Height); + _drawningBulldozer.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } + } +} \ No newline at end of file diff --git a/Bulldozer/Bulldozer/Form1.resx b/Bulldozer/Bulldozer/FormBulldozer.resx similarity index 100% rename from Bulldozer/Bulldozer/Form1.resx rename to Bulldozer/Bulldozer/FormBulldozer.resx diff --git a/Bulldozer/Bulldozer/Properties/Resources.Designer.cs b/Bulldozer/Bulldozer/Properties/Resources.Designer.cs new file mode 100644 index 0000000..e6cab04 --- /dev/null +++ b/Bulldozer/Bulldozer/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace Bulldozer.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Bulldozer_Lab1.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrow_down { + get { + object obj = ResourceManager.GetObject("arrow_down", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrow_left { + get { + object obj = ResourceManager.GetObject("arrow_left", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrow_right { + get { + object obj = ResourceManager.GetObject("arrow_right", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrow_up { + get { + object obj = ResourceManager.GetObject("arrow_up", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/Bulldozer/Bulldozer/Properties/Resources.resx b/Bulldozer/Bulldozer/Properties/Resources.resx new file mode 100644 index 0000000..47aca23 --- /dev/null +++ b/Bulldozer/Bulldozer/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\arrow_down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrow_left.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrow_right.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrow_up.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file