diff --git a/DumpTruck/DumpTruck/Direction.cs b/DumpTruck/DumpTruck/Direction.cs new file mode 100644 index 0000000..fbff3f8 --- /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 Direction + { + 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..fb1ab84 --- /dev/null +++ b/DumpTruck/DumpTruck/DrawingTruck.cs @@ -0,0 +1,120 @@ +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 Truck { get; private set; } + private float _startPosX; + private float _startPosY; + private int? _pictureWidth = null; + private int? _pictureHeight = null; + protected readonly int _truckWidth = 100; + protected readonly int _truckHeight = 55; + public void Init(int speed, float weight, Color bodyColor) + { + Truck = new EntityTruck(); + Truck.Init(speed, weight, bodyColor); + } + public void SetPosition(int x, int y, int width, int height) + { + _startPosX = x; + _startPosY = y; + _pictureWidth = width; + _pictureHeight = height; + } + public void MoveTransport(Direction direction) + { + if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + switch (direction) + { + case Direction.Left: + if (_startPosX - Truck.Step > 0) + { + _startPosX -= Truck.Step; + } + break; + case Direction.Right: + if (_startPosX + _truckWidth + Truck.Step < _pictureWidth) + { + _startPosX += Truck.Step; + } + + break; + case Direction.Up: + if (_startPosY - Truck.Step > 0) + { + _startPosY -= Truck.Step; + } + break; + case Direction.Down: + if (_startPosY + _truckHeight + Truck.Step < _pictureHeight) + { + _startPosY += Truck.Step; + } + break; + + } + } + public void DrawTransport(Graphics g) + { + if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + + + Brush br = new SolidBrush(Truck?.BodyColor ?? Color.Black); + g.FillRectangle(br, _startPosX + 80, _startPosY, 20, 30); + + Brush brBrown = new SolidBrush(Color.FromArgb(200, 150, 40)); + g.FillRectangle(brBrown, _startPosX, _startPosY + 30, 100, 5); + + Brush brBlack = new SolidBrush(Color.Black); + g.FillEllipse(brBlack, _startPosX, _startPosY + 35, 20, 20); + 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); + 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); + g.DrawEllipse(pen, _startPosX + 22, _startPosY + 35, 20, 20); + g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20); + + } + public void ChangeBorders(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + if (_pictureWidth <= _truckWidth || _pictureHeight <= _truckHeight) + { + _pictureHeight = null; + _pictureWidth = null; + return; + } + if (_startPosX + _truckWidth >= _pictureWidth) + { + _startPosX = _pictureWidth.Value - _truckWidth; + } + if (_startPosY + _truckHeight >= _pictureHeight) + { + _startPosY = _pictureHeight.Value - _truckHeight; + } + } + } +} \ 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..f0a7cd2 --- /dev/null +++ b/DumpTruck/DumpTruck/EntityTruck.cs @@ -0,0 +1,27 @@ +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 float Step => Speed * 100 / Weight; + + public void Init(int speed, float weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } + } +} \ 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/Form1.Designer.cs b/DumpTruck/DumpTruck/FormTruck.Designer.cs similarity index 77% rename from DumpTruck/DumpTruck/Form1.Designer.cs rename to DumpTruck/DumpTruck/FormTruck.Designer.cs index 073cfce..e2ceb32 100644 --- a/DumpTruck/DumpTruck/Form1.Designer.cs +++ b/DumpTruck/DumpTruck/FormTruck.Designer.cs @@ -1,6 +1,6 @@ namespace DumpTruck { - partial class Form1 + partial class FormTruck { /// /// Required designer variable. @@ -28,10 +28,10 @@ /// 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"; + components = new System.ComponentModel.Container(); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Text = "Form1"; } #endregion diff --git a/DumpTruck/DumpTruck/FormTruck.cs b/DumpTruck/DumpTruck/FormTruck.cs new file mode 100644 index 0000000..1a2608a --- /dev/null +++ b/DumpTruck/DumpTruck/FormTruck.cs @@ -0,0 +1,28 @@ +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 + { + public FormTruck() + { + InitializeComponent(); + } + private void btnCreate_Click(object sender, EventArgs e) + { + + } + private void btnMove_Click(object sender, EventArgs e) + { + + } + } +} \ 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