diff --git a/RoadTrain/RoadTrain/DirectionType.cs b/RoadTrain/RoadTrain/DirectionType.cs new file mode 100644 index 0000000..4051946 --- /dev/null +++ b/RoadTrain/RoadTrain/DirectionType.cs @@ -0,0 +1,16 @@ +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 + } +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/DrawingRoadTrain.cs b/RoadTrain/RoadTrain/DrawingRoadTrain.cs new file mode 100644 index 0000000..5c03287 --- /dev/null +++ b/RoadTrain/RoadTrain/DrawingRoadTrain.cs @@ -0,0 +1,110 @@ +using System.Net.NetworkInformation; +using System.Net.Sockets; + +namespace RoadTrain +{ + internal class DrawingRoadTrain + { + public EntityRoadTrain? EntityRoadTrain { get; private set; } + private int _pictureWidth; + private int _pictureHeight; + private int _startPosX; + private int _startPosY; + private readonly int _roadTrainWidth = 200; + private readonly int _roadTrainHeight = 100; + public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool wheel, bool door, bool light, int width, int height) + { + if (_roadTrainWidth < width || _roadTrainHeight < height) + { + EntityRoadTrain = new EntityRoadTrain(); + EntityRoadTrain.Init(speed, weight, bodyColor, additionalColor, wheel, door, light); + _pictureWidth = width; + _pictureHeight = height; + return true; + } + return false; + } + public void SetPosition(int x, int y) + { + _startPosX = x; + _startPosY = y; + + if (_startPosX < 0 || _startPosY < 0 || _startPosX > (_pictureWidth - _roadTrainWidth) || _startPosY > (_pictureHeight - _roadTrainHeight)) + { + _startPosX = 50; + _startPosY = 50; + } + } + 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 < _pictureWidth - _roadTrainWidth) + { + _startPosX += (int)EntityRoadTrain.Step; + } + break; + //вниз + case DirectionType.Down: + if (_startPosY + EntityRoadTrain.Step < _pictureHeight - _roadTrainHeight) + { + _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); + //машина + g.DrawRectangle(pen, _startPosX, _startPosY + 50, 160, 20); //кузов + g.DrawEllipse(pen, _startPosX + 5, _startPosY + 70, 30, 30); //колесо + g.DrawEllipse(pen, _startPosX + 40, _startPosY + 70, 30, 30); //колесо + g.DrawEllipse(pen, _startPosX + 120, _startPosY + 70, 30, 30); //колесо + g.DrawRectangle(pen, _startPosX + 120, _startPosY + 10, 40, 40); //кабина + g.DrawRectangle(pen, _startPosX + 10, _startPosY, 90, 50); //бак с водой + g.DrawRectangle(pen, _startPosX + 130, _startPosY + 20, 30, 20); //окно + g.DrawLine(pen, _startPosX + 160, _startPosY + 70, _startPosX + 180, _startPosY + 80); //держатель для щетки + g.DrawRectangle(pen, _startPosX + 170, _startPosY + 80, 40, 10); //щетка + //обвесы + if (EntityRoadTrain.Wheel) + { + g.FillEllipse(additionalBrush, _startPosX + 75, _startPosY + 70, 30, 30); //колесо + } + if (EntityRoadTrain.Door) + { + g.FillRectangle(additionalBrush, _startPosX + 40, _startPosY + 20, 20, 30); //дверь + } + if (EntityRoadTrain.Light) + { + g.FillRectangle(additionalBrush, _startPosX + 135, _startPosY, 10, 10); //мигалка + } + } + } +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/EntityRoadTrain.cs b/RoadTrain/RoadTrain/EntityRoadTrain.cs new file mode 100644 index 0000000..196715a --- /dev/null +++ b/RoadTrain/RoadTrain/EntityRoadTrain.cs @@ -0,0 +1,25 @@ +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 Wheel { get; private set; } + public bool Door { get; private set; } + public bool Light { get; private set; } + public double Step => (double)Speed * 100 / Weight; + public void Init(int speed, double weight, Color bodyColor, Color + additionalColor, bool wheel, bool door, bool light) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + Wheel = wheel; + Door = door; + Light = light; + } + } +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/Form1.Designer.cs b/RoadTrain/RoadTrain/Form1.Designer.cs deleted file mode 100644 index 909c04d..0000000 --- a/RoadTrain/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/RoadTrain/Form1.cs b/RoadTrain/RoadTrain/Form1.cs deleted file mode 100644 index 8f6f5e9..0000000 --- a/RoadTrain/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/RoadTrain/Program.cs b/RoadTrain/RoadTrain/Program.cs index 45a6222..b765653 100644 --- a/RoadTrain/RoadTrain/Program.cs +++ b/RoadTrain/RoadTrain/Program.cs @@ -1,17 +1,12 @@ -namespace RoadTrain +namespace RoadTrain.A_RoadTrain_Basic { internal static class Program { - /// - /// The main entry point for the application. - /// [STAThread] static void Main() { - // 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 RoadTrain()); } } } \ No newline at end of file diff --git a/RoadTrain/RoadTrain/Properties/Resources.Designer.cs b/RoadTrain/RoadTrain/Properties/Resources.Designer.cs new file mode 100644 index 0000000..9ca041a --- /dev/null +++ b/RoadTrain/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/RoadTrain/Properties/Resources.resx b/RoadTrain/RoadTrain/Properties/Resources.resx new file mode 100644 index 0000000..53ec0b4 --- /dev/null +++ b/RoadTrain/RoadTrain/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\down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\left.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\up.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/RoadTrain/Resources/down.png b/RoadTrain/RoadTrain/Resources/down.png new file mode 100644 index 0000000..0f9a8dd Binary files /dev/null and b/RoadTrain/RoadTrain/Resources/down.png differ diff --git a/RoadTrain/RoadTrain/Resources/left.png b/RoadTrain/RoadTrain/Resources/left.png new file mode 100644 index 0000000..8b6ae1e Binary files /dev/null and b/RoadTrain/RoadTrain/Resources/left.png differ diff --git a/RoadTrain/RoadTrain/Resources/right.png b/RoadTrain/RoadTrain/Resources/right.png new file mode 100644 index 0000000..f224f62 Binary files /dev/null and b/RoadTrain/RoadTrain/Resources/right.png differ diff --git a/RoadTrain/RoadTrain/Resources/up.png b/RoadTrain/RoadTrain/Resources/up.png new file mode 100644 index 0000000..91e70fc Binary files /dev/null and b/RoadTrain/RoadTrain/Resources/up.png differ diff --git a/RoadTrain/RoadTrain/RoadTrain.Designer.cs b/RoadTrain/RoadTrain/RoadTrain.Designer.cs new file mode 100644 index 0000000..96faace --- /dev/null +++ b/RoadTrain/RoadTrain/RoadTrain.Designer.cs @@ -0,0 +1,135 @@ +namespace RoadTrain.A_RoadTrain_Basic +{ + partial class RoadTrain + { + private System.ComponentModel.IContainer components = null; + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + private void InitializeComponent() + { + pictureBoxRoadTrain = new PictureBox(); + buttonCreate = new Button(); + buttonRight = new Button(); + buttonUp = new Button(); + buttonLeft = new Button(); + buttonDown = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).BeginInit(); + SuspendLayout(); + // + // pictureBoxRoadTrain + // + pictureBoxRoadTrain.Dock = DockStyle.Fill; + pictureBoxRoadTrain.Location = new Point(0, 0); + pictureBoxRoadTrain.Margin = new Padding(3, 2, 3, 2); + pictureBoxRoadTrain.Name = "pictureBoxRoadTrain"; + pictureBoxRoadTrain.Size = new Size(700, 338); + pictureBoxRoadTrain.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxRoadTrain.TabIndex = 0; + pictureBoxRoadTrain.TabStop = false; + // + // buttonCreate + // + buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreate.Location = new Point(10, 307); + buttonCreate.Margin = new Padding(3, 2, 3, 2); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(82, 22); + buttonCreate.TabIndex = 1; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = Properties.Resources.right; + buttonRight.BackgroundImageLayout = ImageLayout.Zoom; + buttonRight.ForeColor = SystemColors.ControlText; + buttonRight.Location = new Point(663, 306); + buttonRight.Margin = new Padding(3, 2, 3, 2); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(26, 22); + buttonRight.TabIndex = 2; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += ButtonMove_Click; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImage = Properties.Resources.up; + buttonUp.BackgroundImageLayout = ImageLayout.Zoom; + buttonUp.ForeColor = SystemColors.ControlText; + buttonUp.Location = new Point(632, 280); + buttonUp.Margin = new Padding(3, 2, 3, 2); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(26, 22); + buttonUp.TabIndex = 4; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += ButtonMove_Click; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackgroundImage = Properties.Resources.left; + buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; + buttonLeft.ForeColor = SystemColors.ControlText; + buttonLeft.Location = new Point(600, 307); + buttonLeft.Margin = new Padding(3, 2, 3, 2); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(26, 22); + buttonLeft.TabIndex = 5; + buttonLeft.UseVisualStyleBackColor = true; + buttonLeft.Click += ButtonMove_Click; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImage = Properties.Resources.down; + buttonDown.BackgroundImageLayout = ImageLayout.Zoom; + buttonDown.ForeColor = SystemColors.ControlText; + buttonDown.Location = new Point(632, 307); + buttonDown.Margin = new Padding(3, 2, 3, 2); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(26, 22); + buttonDown.TabIndex = 6; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += ButtonMove_Click; + // + // RoadTrain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(700, 338); + Controls.Add(buttonDown); + Controls.Add(buttonLeft); + Controls.Add(buttonUp); + Controls.Add(buttonRight); + Controls.Add(buttonCreate); + Controls.Add(pictureBoxRoadTrain); + Margin = new Padding(3, 2, 3, 2); + Name = "RoadTrain"; + Text = "RoadTrainForm"; + ((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + public PictureBox pictureBoxRoadTrain; + private Button buttonCreate; + private Button buttonRight; + private Button buttonUp; + private Button buttonLeft; + private Button buttonDown; + } +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/RoadTrain.cs b/RoadTrain/RoadTrain/RoadTrain.cs new file mode 100644 index 0000000..616da9a --- /dev/null +++ b/RoadTrain/RoadTrain/RoadTrain.cs @@ -0,0 +1,62 @@ +namespace RoadTrain.A_RoadTrain_Basic +{ + public partial class RoadTrain : Form + { + private DrawingRoadTrain? _drawingRoadTrain; + public RoadTrain() + { + InitializeComponent(); + } + private void Draw() + { + if (_drawingRoadTrain == null) + { + return; + } + Bitmap bmp = new(pictureBoxRoadTrain.Width, + pictureBoxRoadTrain.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawingRoadTrain.DrawTransport(gr); + pictureBoxRoadTrain.Image = bmp; + } + private void buttonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawingRoadTrain = new DrawingRoadTrain(); + _drawingRoadTrain.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)), + Convert.ToBoolean(random.Next(0, 2)), + pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height); + _drawingRoadTrain.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_drawingRoadTrain == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _drawingRoadTrain.MoveTransport(DirectionType.Up); + break; + case "buttonDown": + _drawingRoadTrain.MoveTransport(DirectionType.Down); + break; + case "buttonLeft": + _drawingRoadTrain.MoveTransport(DirectionType.Left); + break; + case "buttonRight": + _drawingRoadTrain.MoveTransport(DirectionType.Right); + break; + } + Draw(); + } + } +} diff --git a/RoadTrain/RoadTrain/RoadTrain.csproj b/RoadTrain/RoadTrain/RoadTrain.csproj index b57c89e..13ee123 100644 --- a/RoadTrain/RoadTrain/RoadTrain.csproj +++ b/RoadTrain/RoadTrain/RoadTrain.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/RoadTrain/RoadTrain/Form1.resx b/RoadTrain/RoadTrain/RoadTrain.resx similarity index 93% rename from RoadTrain/RoadTrain/Form1.resx rename to RoadTrain/RoadTrain/RoadTrain.resx index 1af7de1..af32865 100644 --- a/RoadTrain/RoadTrain/Form1.resx +++ b/RoadTrain/RoadTrain/RoadTrain.resx @@ -1,17 +1,17 @@  -