diff --git a/RoadTrain/DirectionType.cs b/RoadTrain/DirectionType.cs new file mode 100644 index 0000000..c83f70f --- /dev/null +++ b/RoadTrain/DirectionType.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RoadTrain +{ + public enum DirectionType + { + /// + /// Вверх + /// + Up = 1, + + /// + /// Вниз + /// + Down = 2, + + /// + /// Влево + /// + Left = 3, + + /// + /// Вправо + /// + Right = 4 + } +} diff --git a/RoadTrain/DrawningRoadTrain.cs b/RoadTrain/DrawningRoadTrain.cs new file mode 100644 index 0000000..8f04668 --- /dev/null +++ b/RoadTrain/DrawningRoadTrain.cs @@ -0,0 +1,155 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RoadTrain +{ + public class DrawningRoadTrain + { + /// + /// Класс-сущность + /// + public EntityRoadTrain? EntityRoadTrain { get; private set; } + /// + /// Ширина окна + /// + private int _pictureWidth; + /// + /// Высота окна + /// + private int _pictureHeight; + /// + /// Левая координата прорисовки автомобиля + /// + private int _startPosX; + /// + /// Верхняя кооридната прорисовки автомобиля + /// + private int _startPosY; + /// + /// Ширина прорисовки автомобиля + /// + private readonly int _trainWidth = 70; + /// + /// Высота прорисовки автомобиля + /// + private readonly int _trainHeight = 30; + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия контейнера для воды + /// Признак наличия щетки + /// Ширина картинки + /// Высота картинки + /// true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах + public bool Init(EntityRoadTrain entityRoadTrain, int width, int height) + { + if (width < _trainWidth) { return false; } + if (height < _trainHeight) { return false; } + _pictureWidth = width; + _pictureHeight = height; + EntityRoadTrain = entityRoadTrain; + + return true; + } + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + if (x < 0) { x = 0; } + if (y < 0) { y = 0; } + if (x > 200) { x = 200; } + if (y > 200) { y = 200; } + _startPosX = x; + _startPosY = y; + } + /// + /// Изменение направления перемещения + /// + /// Направление + public void MoveTransport(DirectionType direction) + { + if (EntityRoadTrain == null) + { + return; + } + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX - EntityRoadTrain.Step > 0) + { + _startPosX -= (int)EntityRoadTrain.Step; + } + break; + //вверх + case DirectionType.Up: + if (_startPosY - EntityRoadTrain.Step > 0) + { + _startPosY -= (int)EntityRoadTrain.Step; + } + break; + // вправо + case DirectionType.Right: + if (_startPosX + EntityRoadTrain.Step + _trainWidth < _pictureWidth) + { + _startPosX += (int)EntityRoadTrain.Step; + } + break; + //вниз + case DirectionType.Down: + if (_startPosY + EntityRoadTrain.Step + _trainHeight < _pictureHeight) + { + _startPosY += (int)EntityRoadTrain.Step; + } + break; + } + } + /// + /// Прорисовка объекта + /// + /// + public void DrawTransport(Graphics g) + { + if (EntityRoadTrain == null) + { + return; + } + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(EntityRoadTrain.AdditionalColor); + //Контейнер с водой + if (EntityRoadTrain.WaterContainer) + { + g.DrawEllipse(pen, _startPosX + 30, _startPosY, 10, 20); + g.FillEllipse(additionalBrush, _startPosX + 30, _startPosY, 10, 20); + + } + if (EntityRoadTrain.SweepingBrush) + { + g.DrawLine(pen, _startPosX + 30, _startPosY + 10, _startPosX + 20, _startPosY + 10); + g.DrawLine(pen, _startPosX + 20, _startPosY + 10, _startPosX + 10, _startPosY + 30); + g.DrawLine(pen, _startPosX + 17, _startPosY + 30, _startPosX + 3, _startPosY + 30); + } + Brush br = new SolidBrush(EntityRoadTrain.BodyColor); + g.DrawLine(pen, _startPosX + 20, _startPosY + 20, _startPosX + 70, _startPosY + 20); + g.DrawEllipse(pen, _startPosX + 20, _startPosY + 20, 10, 10); + g.DrawEllipse(pen, _startPosX + 30, _startPosY + 20, 10, 10); + g.DrawEllipse(pen, _startPosX + 60, _startPosY + 20, 10, 10); + g.DrawRectangle(pen, _startPosX + 60, _startPosY, 10, 20); + + g.FillEllipse(br, _startPosX + 20, _startPosY + 20, 10, 10); + g.FillEllipse(br, _startPosX + 30, _startPosY + 20, 10, 10); + g.FillEllipse(br, _startPosX + 60, _startPosY + 20, 10, 10); + g.FillRectangle(br, _startPosX + 60, _startPosY, 10, 20); + } + } +} diff --git a/RoadTrain/EntityRoadTrain.cs b/RoadTrain/EntityRoadTrain.cs new file mode 100644 index 0000000..ac4557e --- /dev/null +++ b/RoadTrain/EntityRoadTrain.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RoadTrain +{ + public class EntityRoadTrain + { + /// + /// Скорость + /// + public int Speed { get; private set; } + /// + /// Вес + /// + public double Weight { get; private set; } + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + /// + /// Дополнительный цвет (для опциональных элементов) + /// + public Color AdditionalColor { get; private set; } + /// + /// Признак (опция) наличия контейнера с водой + /// + public bool WaterContainer { get; private set; } + /// + /// Признак (опция) наличия щетки + /// + public bool SweepingBrush { get; private set; } + /// + /// Шаг перемещения поезда + /// + public double Step => (double)Speed * 100 / Weight; + /// + /// Инициализация полей объекта-класса поезда + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия контейнера с водой + /// Признак наличия щетки + public void Init(int speed, double weight, Color bodyColor, Color + additionalColor, bool waterContainer, bool sweepingBrush) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + WaterContainer = waterContainer; + SweepingBrush = sweepingBrush; + } + + } +} diff --git a/RoadTrain/Form1.Designer.cs b/RoadTrain/Form1.Designer.cs deleted file mode 100644 index 909c04d..0000000 --- a/RoadTrain/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace RoadTrain -{ - partial class Form1 - { - /// - /// 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() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/RoadTrain/Form1.cs b/RoadTrain/Form1.cs deleted file mode 100644 index 8f6f5e9..0000000 --- a/RoadTrain/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace RoadTrain -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/RoadTrain/FormRoadTrain.Designer.cs b/RoadTrain/FormRoadTrain.Designer.cs new file mode 100644 index 0000000..6cf71ad --- /dev/null +++ b/RoadTrain/FormRoadTrain.Designer.cs @@ -0,0 +1,138 @@ +namespace RoadTrain +{ + partial class FormRoadTrain + { + /// + /// 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() + { + pictureBoxRoadTrain = new PictureBox(); + buttonLeft = new Button(); + buttonUp = new Button(); + buttonRight = new Button(); + buttonDown = new Button(); + buttonCreate = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).BeginInit(); + SuspendLayout(); + // + // pictureBoxRoadTrain + // + pictureBoxRoadTrain.BackgroundImageLayout = ImageLayout.Zoom; + pictureBoxRoadTrain.Dock = DockStyle.Fill; + pictureBoxRoadTrain.Location = new Point(0, 0); + pictureBoxRoadTrain.Name = "pictureBoxRoadTrain"; + pictureBoxRoadTrain.Size = new Size(685, 362); + pictureBoxRoadTrain.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxRoadTrain.TabIndex = 0; + pictureBoxRoadTrain.TabStop = false; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackgroundImage = Properties.Resources.left; + buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; + buttonLeft.Location = new Point(539, 268); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(30, 30); + buttonLeft.TabIndex = 2; + buttonLeft.UseVisualStyleBackColor = true; + buttonLeft.Click += ButtonMove_Click; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImage = Properties.Resources.up; + buttonUp.BackgroundImageLayout = ImageLayout.Zoom; + buttonUp.Location = new Point(583, 222); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(30, 30); + buttonUp.TabIndex = 3; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += ButtonMove_Click; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = Properties.Resources.right; + buttonRight.BackgroundImageLayout = ImageLayout.Zoom; + buttonRight.Location = new Point(626, 268); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(30, 30); + buttonRight.TabIndex = 4; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += ButtonMove_Click; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImage = Properties.Resources.down; + buttonDown.BackgroundImageLayout = ImageLayout.Zoom; + buttonDown.Location = new Point(583, 314); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(30, 30); + buttonDown.TabIndex = 5; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += ButtonMove_Click; + // + // buttonCreate + // + buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreate.Location = new Point(92, 265); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(75, 23); + buttonCreate.TabIndex = 6; + buttonCreate.Text = "создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // FormRoadTrain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(685, 362); + Controls.Add(buttonCreate); + Controls.Add(buttonDown); + Controls.Add(buttonRight); + Controls.Add(buttonUp); + Controls.Add(buttonLeft); + Controls.Add(pictureBoxRoadTrain); + Name = "FormRoadTrain"; + Text = "FormRoadTrain"; + ((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private PictureBox pictureBoxRoadTrain; + + private Button buttonLeft; + private Button buttonUp; + private Button buttonRight; + private Button buttonDown; + private Button buttonCreate; + } +} \ No newline at end of file diff --git a/RoadTrain/FormRoadTrain.cs b/RoadTrain/FormRoadTrain.cs new file mode 100644 index 0000000..d4ee115 --- /dev/null +++ b/RoadTrain/FormRoadTrain.cs @@ -0,0 +1,91 @@ +namespace RoadTrain +{ + public partial class FormRoadTrain : Form + { + /// + /// - + /// + private DrawningRoadTrain? _drawningRoadTrain; + /// + /// + /// + public FormRoadTrain() + { + InitializeComponent(); + } + /// + /// + /// + private void Draw() + { + if (_drawningRoadTrain == null) + { + return; + } + Bitmap bmp = new(pictureBoxRoadTrain.Width, + pictureBoxRoadTrain.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningRoadTrain.DrawTransport(gr); + pictureBoxRoadTrain.Image = bmp; + } + /// + /// "" + /// + /// + /// + + /// + /// + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_drawningRoadTrain == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _drawningRoadTrain.MoveTransport(DirectionType.Up); + break; + case "buttonDown": + _drawningRoadTrain.MoveTransport(DirectionType.Down); + break; + case "buttonLeft": + _drawningRoadTrain.MoveTransport(DirectionType.Left); + break; + case "buttonRight": + _drawningRoadTrain.MoveTransport(DirectionType.Right); + break; + } + Draw(); + } + + private void buttonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningRoadTrain = new DrawningRoadTrain(); + EntityRoadTrain entityRoadTrain = new EntityRoadTrain(); + entityRoadTrain.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)), + Convert.ToBoolean(random.Next(0, 2)), + Convert.ToBoolean(random.Next(0, 2))); + + _drawningRoadTrain.Init(entityRoadTrain, pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height); + + _drawningRoadTrain.SetPosition(random.Next(10, 100), + random.Next(10, 100)); + Draw(); + } + + + } +} + diff --git a/RoadTrain/FormRoadTrain.resx b/RoadTrain/FormRoadTrain.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/RoadTrain/FormRoadTrain.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/RoadTrain/Program.cs b/RoadTrain/Program.cs index 45a6222..23d1345 100644 --- a/RoadTrain/Program.cs +++ b/RoadTrain/Program.cs @@ -11,7 +11,7 @@ namespace RoadTrain // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new FormRoadTrain()); } } } \ No newline at end of file diff --git a/RoadTrain/Properties/Resources.Designer.cs b/RoadTrain/Properties/Resources.Designer.cs new file mode 100644 index 0000000..9ca041a --- /dev/null +++ b/RoadTrain/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace RoadTrain.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("RoadTrain.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 down { + get { + object obj = ResourceManager.GetObject("down", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap left { + get { + object obj = ResourceManager.GetObject("left", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap right { + get { + object obj = ResourceManager.GetObject("right", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap up { + get { + object obj = ResourceManager.GetObject("up", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/RoadTrain/Form1.resx b/RoadTrain/Properties/Resources.resx similarity index 84% rename from RoadTrain/Form1.resx rename to RoadTrain/Properties/Resources.resx index 1af7de1..9b9e383 100644 --- a/RoadTrain/Form1.resx +++ b/RoadTrain/Properties/Resources.resx @@ -117,4 +117,17 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\left.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\up.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\right.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/RoadTrain/Resources/down.png b/RoadTrain/Resources/down.png new file mode 100644 index 0000000..84204b3 Binary files /dev/null and b/RoadTrain/Resources/down.png differ diff --git a/RoadTrain/Resources/left.png b/RoadTrain/Resources/left.png new file mode 100644 index 0000000..16c62ca Binary files /dev/null and b/RoadTrain/Resources/left.png differ diff --git a/RoadTrain/Resources/right.png b/RoadTrain/Resources/right.png new file mode 100644 index 0000000..3016709 Binary files /dev/null and b/RoadTrain/Resources/right.png differ diff --git a/RoadTrain/Resources/up.png b/RoadTrain/Resources/up.png new file mode 100644 index 0000000..68d77d1 Binary files /dev/null and b/RoadTrain/Resources/up.png differ diff --git a/RoadTrain/RoadTrain.csproj b/RoadTrain/RoadTrain.csproj index b57c89e..13ee123 100644 --- a/RoadTrain/RoadTrain.csproj +++ b/RoadTrain/RoadTrain.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file