diff --git a/ProjectRoadTrain/ProjectRoadTrain/DirectionType.cs b/ProjectRoadTrain/ProjectRoadTrain/DirectionType.cs new file mode 100644 index 0000000..54ea441 --- /dev/null +++ b/ProjectRoadTrain/ProjectRoadTrain/DirectionType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectRoadTrain; + +public enum DirectionType +{ + Up = 1, + Down = 2, + Left = 3, + Right = 4 +} diff --git a/ProjectRoadTrain/ProjectRoadTrain/DrawningRoadTrain.cs b/ProjectRoadTrain/ProjectRoadTrain/DrawningRoadTrain.cs new file mode 100644 index 0000000..7ed02de --- /dev/null +++ b/ProjectRoadTrain/ProjectRoadTrain/DrawningRoadTrain.cs @@ -0,0 +1,133 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectRoadTrain; + +public class DrawningRoadTrain +{ + public EntityRoadTrain? EntityRoadTrain { get; private set; } + + private int? _pictureWidth; + + private int? _pictureHight; + + private int? _startPosX; + + private int? _startPosY; + + private readonly int _drawningRoadWidth = 270; + + private readonly int _drawningRoadHeight = 120; + + public void Init(int speed, double weight, Color bodycolor, Color bodytankcolor, bool watertank, bool cleanbrush) + { + EntityRoadTrain = new EntityRoadTrain(); + EntityRoadTrain.Init(speed, weight, bodycolor, bodytankcolor, watertank, cleanbrush); + _pictureWidth = null; + _pictureHight = null; + _startPosX = null; + _startPosY = null; + } + + public bool SetPictureSize(int width, int height) + { + _pictureWidth = width; + _pictureHight = height; + return true; + } + + public void SetPosition(int x, int y) + { + if (!_pictureHight.HasValue || !_pictureWidth.HasValue) + { + return; + } + _startPosX = x; + _startPosY = y; + } + + + public bool MoveTransport(DirectionType direction) + { + if (EntityRoadTrain == null || !_startPosX.HasValue || + !_startPosY.HasValue) + { + return false; + } + if (_startPosX.Value < 0 || _startPosY.Value < 0 || _startPosX > _pictureWidth - _drawningRoadWidth || _startPosY > _pictureHight - _drawningRoadHeight) + { + return false; + } + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX.Value - EntityRoadTrain.Step > 0) + { + _startPosX -= (int)EntityRoadTrain.Step; + } + + return true; + //вверх + case DirectionType.Up: + if (_startPosY.Value - EntityRoadTrain.Step > 0) + { + _startPosY -= (int)EntityRoadTrain.Step; + } + + return true; + // вправо + case DirectionType.Right: + if (_startPosX.Value + EntityRoadTrain.Step < _pictureWidth - _drawningRoadWidth) + { + _startPosX += (int)EntityRoadTrain.Step; + } + return true; + //вниз + case DirectionType.Down: + if (_startPosY.Value + EntityRoadTrain.Step < _pictureHight - _drawningRoadHeight) + { + _startPosY += (int)EntityRoadTrain.Step; + } + + return true; + default: + return false; + } + + } + + public void DrawTransport(Graphics g) + { + if (EntityRoadTrain == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + Pen pen = new(Color.Black); + Brush bodytankcolor = new SolidBrush(EntityRoadTrain.BodyTankColor); + Brush blackcolor = new SolidBrush(Color.Black); + Brush bodycolor = new SolidBrush(EntityRoadTrain.BodyColor); + + if (EntityRoadTrain.WaterTank || EntityRoadTrain.CleanBrush) + { + g.FillRectangle(bodytankcolor, _startPosX.Value + 140, _startPosY.Value + 70, 100, 2); + g.FillRectangle(bodytankcolor, _startPosX.Value + 140, _startPosY.Value + 75, 100, 2); + g.FillRectangle(bodytankcolor, _startPosX.Value + 140, _startPosY.Value + 65, 100, 2); + g.FillEllipse(bodytankcolor, _startPosX.Value + 20, _startPosY.Value + 10, 100, 50); + } + g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 60, 170, 20); + g.DrawRectangle(pen, _startPosX.Value + 140, _startPosY.Value, 50, 60); + g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 10, 100, 50); + // 120 высота + // 270 ширина + g.FillRectangle(blackcolor, _startPosX.Value + 20, _startPosY.Value + 60, 170, 20); + g.FillRectangle(bodycolor, _startPosX.Value + 140, _startPosY.Value, 50, 60); + g.FillEllipse(blackcolor, _startPosX.Value + 140, _startPosY.Value + 77, 48, 40); + g.FillEllipse(blackcolor, _startPosX.Value + 69, _startPosY.Value + 77, 48, 40); + g.FillEllipse(blackcolor, _startPosX.Value + 20, _startPosY.Value + 77, 48, 40); + } +} diff --git a/ProjectRoadTrain/ProjectRoadTrain/EntityRoadTrain.cs b/ProjectRoadTrain/ProjectRoadTrain/EntityRoadTrain.cs new file mode 100644 index 0000000..6d9c8c8 --- /dev/null +++ b/ProjectRoadTrain/ProjectRoadTrain/EntityRoadTrain.cs @@ -0,0 +1,24 @@ +namespace ProjectRoadTrain; + +public class EntityRoadTrain +{ + public int Speed { get; private set; } + public double Weight { get; private set; } + public Color BodyColor { get; private set; } + public Color BodyTankColor { get; private set; } + public bool WaterTank { get; private set; } + public bool CleanBrush { get; private set; } + public double Step => Speed * 50 / Weight; + + public void Init(int speed, double weight, Color bodycolor, Color bodytankcolor, + bool watertank, bool cleanbrush) + { + Speed = speed; + Weight = weight; + BodyColor = bodycolor; + BodyTankColor = bodytankcolor; + WaterTank = watertank; + CleanBrush = cleanbrush; + } + +} diff --git a/ProjectRoadTrain/ProjectRoadTrain/Form1.Designer.cs b/ProjectRoadTrain/ProjectRoadTrain/Form1.Designer.cs deleted file mode 100644 index 3a9b4c4..0000000 --- a/ProjectRoadTrain/ProjectRoadTrain/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ProjectRoadTrain -{ - 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 - } -} diff --git a/ProjectRoadTrain/ProjectRoadTrain/Form1.cs b/ProjectRoadTrain/ProjectRoadTrain/Form1.cs deleted file mode 100644 index e4f7772..0000000 --- a/ProjectRoadTrain/ProjectRoadTrain/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ProjectRoadTrain -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.Designer.cs b/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.Designer.cs new file mode 100644 index 0000000..cdadb17 --- /dev/null +++ b/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.Designer.cs @@ -0,0 +1,134 @@ +namespace ProjectRoadTrain +{ + 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(); + buttonCreate = new Button(); + buttonLeft = new Button(); + buttonDown = new Button(); + buttonRight = new Button(); + buttonUp = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).BeginInit(); + SuspendLayout(); + // + // pictureBoxRoadTrain + // + pictureBoxRoadTrain.Dock = DockStyle.Fill; + pictureBoxRoadTrain.Location = new Point(0, 0); + pictureBoxRoadTrain.Name = "pictureBoxRoadTrain"; + pictureBoxRoadTrain.Size = new Size(923, 536); + pictureBoxRoadTrain.TabIndex = 0; + pictureBoxRoadTrain.TabStop = false; + // + // buttonCreate + // + buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreate.Location = new Point(12, 495); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(94, 29); + buttonCreate.TabIndex = 1; + buttonCreate.Text = "создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackgroundImage = Properties.Resources.arrowLeft; + buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; + buttonLeft.Location = new Point(789, 488); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(35, 35); + buttonLeft.TabIndex = 2; + buttonLeft.UseVisualStyleBackColor = true; + buttonLeft.Click += buttonMove_Click; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImage = Properties.Resources.arrowDown; + buttonDown.BackgroundImageLayout = ImageLayout.Stretch; + buttonDown.Location = new Point(830, 488); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(35, 35); + buttonDown.TabIndex = 3; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += buttonMove_Click; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = Properties.Resources.arrowRight; + buttonRight.BackgroundImageLayout = ImageLayout.Stretch; + buttonRight.Location = new Point(871, 488); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(35, 35); + buttonRight.TabIndex = 4; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += buttonMove_Click; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImage = Properties.Resources.arrowUp; + buttonUp.BackgroundImageLayout = ImageLayout.Stretch; + buttonUp.Location = new Point(830, 447); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(35, 35); + buttonUp.TabIndex = 5; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += buttonMove_Click; + // + // FormRoadTrain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(923, 536); + Controls.Add(buttonUp); + Controls.Add(buttonRight); + Controls.Add(buttonDown); + Controls.Add(buttonLeft); + Controls.Add(buttonCreate); + Controls.Add(pictureBoxRoadTrain); + Name = "FormRoadTrain"; + Text = "автопоезд"; + ((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).EndInit(); + ResumeLayout(false); + } + + #endregion + + private PictureBox pictureBoxRoadTrain; + private Button buttonCreate; + private Button buttonLeft; + private Button buttonDown; + private Button buttonRight; + private Button buttonUp; + } +} \ No newline at end of file diff --git a/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.cs b/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.cs new file mode 100644 index 0000000..bd4b5d1 --- /dev/null +++ b/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.cs @@ -0,0 +1,67 @@ +namespace ProjectRoadTrain; + +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 buttonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningRoadTrain = new DrawningRoadTrain(); + _drawningRoadTrain.Init(random.Next(100, 300), random.Next(1200, 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.SetPictureSize(pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height); + _drawningRoadTrain.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } + + private void buttonMove_Click(object sender, EventArgs e) + { + if (_drawningRoadTrain == null) + { + return; + } + + string name = ((Button)sender)?.Name ?? string.Empty; + bool result = false; + switch (name) + { + case "buttonUp": + result = _drawningRoadTrain.MoveTransport(DirectionType.Up); + break; + case "buttonDown": + result = _drawningRoadTrain.MoveTransport(DirectionType.Down); + break; + case "buttonLeft": + result = _drawningRoadTrain.MoveTransport(DirectionType.Left); + break; + case "buttonRight": + result = _drawningRoadTrain.MoveTransport(DirectionType.Right); + break; + } + + if (result) + { + Draw(); + } + } +} diff --git a/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.resx b/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/ProjectRoadTrain/ProjectRoadTrain/Program.cs b/ProjectRoadTrain/ProjectRoadTrain/Program.cs index c4062a4..d87a77e 100644 --- a/ProjectRoadTrain/ProjectRoadTrain/Program.cs +++ b/ProjectRoadTrain/ProjectRoadTrain/Program.cs @@ -11,7 +11,7 @@ namespace ProjectRoadTrain // 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/ProjectRoadTrain/ProjectRoadTrain/ProjectRoadTrain.csproj b/ProjectRoadTrain/ProjectRoadTrain/ProjectRoadTrain.csproj index e1a0735..244387d 100644 --- a/ProjectRoadTrain/ProjectRoadTrain/ProjectRoadTrain.csproj +++ b/ProjectRoadTrain/ProjectRoadTrain/ProjectRoadTrain.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ProjectRoadTrain/ProjectRoadTrain/Properties/Resources.Designer.cs b/ProjectRoadTrain/ProjectRoadTrain/Properties/Resources.Designer.cs new file mode 100644 index 0000000..07e90b1 --- /dev/null +++ b/ProjectRoadTrain/ProjectRoadTrain/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ProjectRoadTrain.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("ProjectRoadTrain.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 arrowDown { + get { + object obj = ResourceManager.GetObject("arrowDown", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowLeft { + get { + object obj = ResourceManager.GetObject("arrowLeft", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowRight { + get { + object obj = ResourceManager.GetObject("arrowRight", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowUp { + get { + object obj = ResourceManager.GetObject("arrowUp", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/ProjectRoadTrain/ProjectRoadTrain/Properties/Resources.resx b/ProjectRoadTrain/ProjectRoadTrain/Properties/Resources.resx new file mode 100644 index 0000000..dc343a1 --- /dev/null +++ b/ProjectRoadTrain/ProjectRoadTrain/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\arrowUp.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowRight.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowLeft.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowDown.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/ProjectRoadTrain/ProjectRoadTrain/Resources/arrowDown.jpg b/ProjectRoadTrain/ProjectRoadTrain/Resources/arrowDown.jpg new file mode 100644 index 0000000..f21002e Binary files /dev/null and b/ProjectRoadTrain/ProjectRoadTrain/Resources/arrowDown.jpg differ diff --git a/ProjectRoadTrain/ProjectRoadTrain/Resources/arrowLeft.jpg b/ProjectRoadTrain/ProjectRoadTrain/Resources/arrowLeft.jpg new file mode 100644 index 0000000..61b8dae Binary files /dev/null and b/ProjectRoadTrain/ProjectRoadTrain/Resources/arrowLeft.jpg differ diff --git a/ProjectRoadTrain/ProjectRoadTrain/Resources/arrowRight.jpg b/ProjectRoadTrain/ProjectRoadTrain/Resources/arrowRight.jpg new file mode 100644 index 0000000..b440197 Binary files /dev/null and b/ProjectRoadTrain/ProjectRoadTrain/Resources/arrowRight.jpg differ diff --git a/ProjectRoadTrain/ProjectRoadTrain/Resources/arrowUp.jpg b/ProjectRoadTrain/ProjectRoadTrain/Resources/arrowUp.jpg new file mode 100644 index 0000000..e630cea Binary files /dev/null and b/ProjectRoadTrain/ProjectRoadTrain/Resources/arrowUp.jpg differ