diff --git a/DumpTruck/DumpTruck/Direction.cs b/DumpTruck/DumpTruck/Direction.cs new file mode 100644 index 0000000..8cd74cb --- /dev/null +++ b/DumpTruck/DumpTruck/Direction.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DumpTruck +{ + internal enum DirectionType + { + Up = 1, + Down = 2, + Left = 3, + Right = 4 + } +} \ No newline at end of file diff --git a/DumpTruck/DumpTruck/DrawingTruck.cs b/DumpTruck/DumpTruck/DrawingTruck.cs new file mode 100644 index 0000000..8a05ede --- /dev/null +++ b/DumpTruck/DumpTruck/DrawingTruck.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DumpTruck +{ + internal class DrawingTruck + { + public EntityTruck? EntityTruck { get; private set; } + private int _startPosX; + private int _startPosY; + private int _pictureWidth; + private int _pictureHeight; + protected readonly int _truckWidth = 100; + protected readonly int _truckHeight = 50; + public bool Init(int speed, float weight, Color bodyColor, Color additionalColor, int width, int height, bool threeWheels, bool dump) + { + if (width < _truckWidth || height < _truckHeight) + { + return false; + } + _pictureWidth = width; + _pictureHeight = height; + EntityTruck = new EntityTruck(); + EntityTruck.Init(speed, weight, bodyColor, additionalColor, threeWheels, dump); + return true; + } + public void SetPosition(int x, int y) + { + if (x < 0 || x + _truckWidth > _pictureWidth) + { + x = _pictureWidth - _truckWidth; + } + if (y < 0 || y + _truckHeight > _pictureHeight) + { + y = _pictureHeight - _truckHeight; + } + _startPosX = x; + _startPosY = y; + } + public void MoveTransport(DirectionType direction) + { + if (EntityTruck == null) + + { + return; + } + + switch (direction) + { + case DirectionType.Left: + if (_startPosX - EntityTruck.Step > 0) + { + _startPosX -= (int)EntityTruck.Step; + } + break; + //вверх + case DirectionType.Up: + if (_startPosY - EntityTruck.Step > 0) + { + _startPosY -= (int)EntityTruck.Step; + } + break; + //вправо + case DirectionType.Right: + if (_startPosX + EntityTruck.Step + _truckWidth < _pictureWidth) + { + _startPosX += (int)EntityTruck.Step; + } + break; + case DirectionType.Down: + if (_startPosY + EntityTruck.Step + _truckHeight < _pictureHeight) + { + _startPosY += (int)EntityTruck.Step; + } + break; + } + + + } + public void DrawTransport(Graphics g, Color bodyColor, Color additionalColor, bool threeWheels, bool Dump) + { + if (EntityTruck == null) + { + return; + } + + + Brush br = new SolidBrush(EntityTruck?.BodyColor ?? Color.Black); + g.FillRectangle(br, _startPosX + 80, _startPosY, 20, 30); + + Brush brBodyRandom = new SolidBrush(bodyColor); + g.FillRectangle(brBodyRandom, _startPosX, _startPosY + 30, 100, 5); + + Brush brBlack = new SolidBrush(Color.Black); + + g.FillEllipse(brBlack, _startPosX, _startPosY + 35, 20, 20); + if (threeWheels) + g.FillEllipse(brBlack, _startPosX + 22, _startPosY + 35, 20, 20); + g.FillEllipse(brBlack, _startPosX + 80, _startPosY + 35, 20, 20); + + Brush brWhite = new SolidBrush(Color.White); + g.FillEllipse(brWhite, _startPosX + 5, _startPosY + 40, 10, 10); + if (threeWheels) + g.FillEllipse(brWhite, _startPosX + 27, _startPosY + 40, 10, 10); + g.FillEllipse(brWhite, _startPosX + 85, _startPosY + 40, 10, 10); + + Pen pen = new Pen(Color.Black); + + g.DrawRectangle(pen, _startPosX + 80, _startPosY, 20, 30); + g.DrawRectangle(pen, _startPosX, _startPosY + 30, 100, 5); + g.DrawEllipse(pen, _startPosX, _startPosY + 35, 20, 20); + if (threeWheels) + g.DrawEllipse(pen, _startPosX + 22, _startPosY + 35, 20, 20); + g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20); + + + //Brush brBody = new SolidBrush(EntityTruck?.AdditionalColor ?? Color.Red); + if (Dump) + { + Brush brBodyAdditional = new SolidBrush(additionalColor); + g.FillRectangle(brBodyAdditional, _startPosX + 0, _startPosY, 70, 30); + Pen pen1 = new Pen(Color.Black); + g.DrawRectangle(pen1, _startPosX + 0, _startPosY, 70, 30); + } + + + + } + } +} \ No newline at end of file diff --git a/DumpTruck/DumpTruck/DumpTruck.csproj b/DumpTruck/DumpTruck/DumpTruck.csproj index b57c89e..13ee123 100644 --- a/DumpTruck/DumpTruck/DumpTruck.csproj +++ b/DumpTruck/DumpTruck/DumpTruck.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/DumpTruck/DumpTruck/EntityTruck.cs b/DumpTruck/DumpTruck/EntityTruck.cs new file mode 100644 index 0000000..8f9e4dc --- /dev/null +++ b/DumpTruck/DumpTruck/EntityTruck.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DumpTruck +{ + internal class EntityTruck + { + public int Speed { get; private set; } + + public float Weight { get; private set; } + + public Color BodyColor { get; private set; } + public Color AdditionalColor { get; private set; } + + public bool ThreeWheels { get; private set; } + + public bool Dump { get; private set; } + + public float Step => Speed * 100 / Weight; + + public void Init(int speed, float weight, Color bodyColor, Color additionalColor, bool threeWheels, bool dump) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + ThreeWheels = threeWheels; + Dump = dump; + } + } +} \ No newline at end of file diff --git a/DumpTruck/DumpTruck/Form1.Designer.cs b/DumpTruck/DumpTruck/Form1.Designer.cs deleted file mode 100644 index 073cfce..0000000 --- a/DumpTruck/DumpTruck/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace DumpTruck -{ - 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/DumpTruck/DumpTruck/Form1.cs b/DumpTruck/DumpTruck/Form1.cs deleted file mode 100644 index 2326120..0000000 --- a/DumpTruck/DumpTruck/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace DumpTruck -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/DumpTruck/DumpTruck/FormTruck.Designer.cs b/DumpTruck/DumpTruck/FormTruck.Designer.cs new file mode 100644 index 0000000..47c7eda --- /dev/null +++ b/DumpTruck/DumpTruck/FormTruck.Designer.cs @@ -0,0 +1,142 @@ +namespace DumpTruck +{ + partial class FormTruck + { + /// + /// 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.btnCreate = new System.Windows.Forms.Button(); + this.btnLeft = new System.Windows.Forms.Button(); + this.btnDown = new System.Windows.Forms.Button(); + this.btnRight = new System.Windows.Forms.Button(); + this.btnUp = new System.Windows.Forms.Button(); + this.pictureBoxTruck = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTruck)).BeginInit(); + this.SuspendLayout(); + // + // btnCreate + // + this.btnCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnCreate.Location = new System.Drawing.Point(12, 426); + this.btnCreate.Name = "btnCreate"; + this.btnCreate.Size = new System.Drawing.Size(75, 23); + this.btnCreate.TabIndex = 0; + this.btnCreate.Text = "Создать"; + this.btnCreate.UseVisualStyleBackColor = true; + this.btnCreate.Click += new System.EventHandler(this.btnCreate_Click); + // + // btnLeft + // + this.btnLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnLeft.BackgroundImage = global::DumpTruck.Properties.Resources.left; + this.btnLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.btnLeft.Location = new System.Drawing.Point(766, 419); + this.btnLeft.Name = "btnLeft"; + this.btnLeft.Size = new System.Drawing.Size(30, 30); + this.btnLeft.TabIndex = 1; + this.btnLeft.Text = " "; + this.btnLeft.UseVisualStyleBackColor = true; + this.btnLeft.Click += new System.EventHandler(this.btnMove_Click); + // + // btnDown + // + this.btnDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnDown.BackgroundImage = global::DumpTruck.Properties.Resources.down; + this.btnDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.btnDown.Location = new System.Drawing.Point(802, 419); + this.btnDown.Name = "btnDown"; + this.btnDown.Size = new System.Drawing.Size(30, 30); + this.btnDown.TabIndex = 2; + this.btnDown.Text = " "; + this.btnDown.UseVisualStyleBackColor = true; + this.btnDown.Click += new System.EventHandler(this.btnMove_Click); + // + // btnRight + // + this.btnRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnRight.BackgroundImage = global::DumpTruck.Properties.Resources.right; + this.btnRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.btnRight.Location = new System.Drawing.Point(838, 419); + this.btnRight.Name = "btnRight"; + this.btnRight.Size = new System.Drawing.Size(30, 30); + this.btnRight.TabIndex = 3; + this.btnRight.Text = " "; + this.btnRight.UseVisualStyleBackColor = true; + this.btnRight.Click += new System.EventHandler(this.btnMove_Click); + // + // btnUp + // + this.btnUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnUp.BackgroundImage = global::DumpTruck.Properties.Resources.up; + this.btnUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.btnUp.Location = new System.Drawing.Point(802, 383); + this.btnUp.Name = "btnUp"; + this.btnUp.Size = new System.Drawing.Size(30, 30); + this.btnUp.TabIndex = 4; + this.btnUp.Text = " "; + this.btnUp.UseVisualStyleBackColor = true; + this.btnUp.Click += new System.EventHandler(this.btnMove_Click); + // + // pictureBoxTruck + // + this.pictureBoxTruck.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxTruck.Location = new System.Drawing.Point(0, 0); + this.pictureBoxTruck.Name = "pictureBoxTruck"; + this.pictureBoxTruck.Size = new System.Drawing.Size(884, 461); + this.pictureBoxTruck.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxTruck.TabIndex = 5; + this.pictureBoxTruck.TabStop = false; + // + // FormTruck + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(884, 461); + this.Controls.Add(this.btnUp); + this.Controls.Add(this.btnRight); + this.Controls.Add(this.btnDown); + this.Controls.Add(this.btnLeft); + this.Controls.Add(this.btnCreate); + this.Controls.Add(this.pictureBoxTruck); + this.Name = "FormTruck"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "FormTruck"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTruck)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button btnCreate; + private Button btnLeft; + private Button btnDown; + private Button btnRight; + private Button btnUp; + private PictureBox pictureBoxTruck; + } +} \ No newline at end of file diff --git a/DumpTruck/DumpTruck/FormTruck.cs b/DumpTruck/DumpTruck/FormTruck.cs new file mode 100644 index 0000000..584da64 --- /dev/null +++ b/DumpTruck/DumpTruck/FormTruck.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace DumpTruck +{ + public partial class FormTruck : Form + { + + private DrawingTruck? _drawningTruck; + + + private void Draw() + { + + if (_drawningTruck == null) + { + return; + } + Random rnd = new Random(); + Bitmap bmp = new(pictureBoxTruck.Width, + pictureBoxTruck.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningTruck.DrawTransport(gr, Color.FromArgb(0,255,128),Color.FromArgb(255,0,0), false, true); + pictureBoxTruck.Image = bmp; + } + + public FormTruck() + { + InitializeComponent(); + } + + private void btnCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningTruck = new DrawingTruck(); + _drawningTruck.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256)), Color.FromArgb(random.Next(0,256)), pictureBoxTruck.Width, pictureBoxTruck.Height, Convert.ToBoolean(random.Next(2)), Convert.ToBoolean(random.Next(2))); + _drawningTruck.SetPosition(random.Next(1, 100), random.Next(1, 100)); + Draw(); + } + + private void btnMove_Click(object sender, EventArgs e) + { + if (_drawningTruck == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "btnUp": + _drawningTruck.MoveTransport(DirectionType.Up); + break; + case "btnDown": + _drawningTruck.MoveTransport(DirectionType.Down); + break; + case "btnLeft": + _drawningTruck.MoveTransport(DirectionType.Left); + break; + case "btnRight": + _drawningTruck.MoveTransport(DirectionType.Right); + break; + } + Draw(); + } + } +} \ No newline at end of file diff --git a/DumpTruck/DumpTruck/FormTruck.resx b/DumpTruck/DumpTruck/FormTruck.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/DumpTruck/DumpTruck/FormTruck.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/DumpTruck/DumpTruck/Program.cs b/DumpTruck/DumpTruck/Program.cs index a716913..b5a689f 100644 --- a/DumpTruck/DumpTruck/Program.cs +++ b/DumpTruck/DumpTruck/Program.cs @@ -11,7 +11,7 @@ namespace DumpTruck // 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 FormTruck()); } } } \ No newline at end of file diff --git a/DumpTruck/DumpTruck/Properties/Resources.Designer.cs b/DumpTruck/DumpTruck/Properties/Resources.Designer.cs new file mode 100644 index 0000000..aac7e60 --- /dev/null +++ b/DumpTruck/DumpTruck/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace DumpTruck.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("DumpTruck.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/DumpTruck/DumpTruck/Form1.resx b/DumpTruck/DumpTruck/Properties/Resources.resx similarity index 84% rename from DumpTruck/DumpTruck/Form1.resx rename to DumpTruck/DumpTruck/Properties/Resources.resx index 1af7de1..3d5a144 100644 --- a/DumpTruck/DumpTruck/Form1.resx +++ b/DumpTruck/DumpTruck/Properties/Resources.resx @@ -117,4 +117,17 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\down.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\left.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\right.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\up.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/DumpTruck/DumpTruck/Resources/down.jpg b/DumpTruck/DumpTruck/Resources/down.jpg new file mode 100644 index 0000000..aabdc4a Binary files /dev/null and b/DumpTruck/DumpTruck/Resources/down.jpg differ diff --git a/DumpTruck/DumpTruck/Resources/left.jpg b/DumpTruck/DumpTruck/Resources/left.jpg new file mode 100644 index 0000000..36676e1 Binary files /dev/null and b/DumpTruck/DumpTruck/Resources/left.jpg differ diff --git a/DumpTruck/DumpTruck/Resources/right.jpg b/DumpTruck/DumpTruck/Resources/right.jpg new file mode 100644 index 0000000..84e1972 Binary files /dev/null and b/DumpTruck/DumpTruck/Resources/right.jpg differ diff --git a/DumpTruck/DumpTruck/Resources/up.jpg b/DumpTruck/DumpTruck/Resources/up.jpg new file mode 100644 index 0000000..25c56cb Binary files /dev/null and b/DumpTruck/DumpTruck/Resources/up.jpg differ