diff --git a/Trolleybus/Trolleybus/Direction.cs b/Trolleybus/Trolleybus/Direction.cs new file mode 100644 index 0000000..68bfa63 --- /dev/null +++ b/Trolleybus/Trolleybus/Direction.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Trolleybus +{ + /// + /// Направление перемещения + /// + internal enum Direction + { + Up = 1, + Down = 2, + Left = 3, + Right = 4 + } +} diff --git a/Trolleybus/Trolleybus/DrawingTrolleybus.cs b/Trolleybus/Trolleybus/DrawingTrolleybus.cs new file mode 100644 index 0000000..f1ac88b --- /dev/null +++ b/Trolleybus/Trolleybus/DrawingTrolleybus.cs @@ -0,0 +1,140 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Drawing; + +namespace Trolleybus +{ + /// + /// Класс прорисовки и перемещения + /// + internal class DrawingTrolleybus + { + public EntityTrolleybus Trolleybus { get; private set; } + /// + /// левая координата отрисовки + /// + private float _startPosX; + /// + /// верхняя координата отрисовки + /// + private float _startPosY; + /// + /// Ширина окна отрисовки + /// + private int? _pictureWidth = null; + /// + /// Высота окна отрисовки + /// + private int? _pictureHeight = null; + /// + /// Ширина отрисовки + /// + protected readonly int _trolleybusWidth = 0; + /// + /// Высота отрисовки + /// + protected readonly int _trolleybusHeight = 0; + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + public void Init(int speed, float weight, Color bodyColor) + { + Trolleybus = new EntityTrolleybus(); + Trolleybus.Init(speed, weight, bodyColor); + } + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + /// Ширина картинки + /// Высота картинки + 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 (!_pictureWidth.HasValue || !_pictureHeight.HasValue) + { + return; + } + switch (direction) + { + //вправо + case Direction.Right: + if(_startPosX + _trolleybusWidth + Trolleybus.Step< _pictureWidth) + { + _startPosX += Trolleybus.Step; + } + break; + //влево + case Direction.Left: + if (_startPosX + _trolleybusWidth - Trolleybus.Step < _pictureWidth) + { + _startPosX += Trolleybus.Step; + } + break; + //вверх + case Direction.Up: + if (_startPosX + _trolleybusWidth - Trolleybus.Step < _pictureHeight) + { + _startPosX += Trolleybus.Step; + } + break; + //вниз + case Direction.Down: + if (_startPosX + _trolleybusWidth + Trolleybus.Step < _pictureHeight) + { + _startPosX += Trolleybus.Step; + } + break; + } + } + /// + /// Отрисовка троллейбуса + /// + /// + public void DrawTransport(Graphics g) + { + + } + /// + /// Смена границ формы отрисовки + /// + /// Ширина картинки + /// Высота картинки + public void ChangeBorders(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + if(_pictureWidth <= _trolleybusWidth || _pictureHeight <= _trolleybusHeight) + { + _pictureWidth = null; + _pictureHeight = null; + return; + } + if (_startPosX + _trolleybusWidth > _pictureWidth) + { + _startPosX = _pictureWidth.Value - _trolleybusWidth; + } + if (_startPosY + _trolleybusHeight > _pictureHeight) + { + _startPosY = _pictureHeight.Value - _trolleybusHeight; + } + } + } +} diff --git a/Trolleybus/Trolleybus/EntityTrolleybus.cs b/Trolleybus/Trolleybus/EntityTrolleybus.cs new file mode 100644 index 0000000..686b943 --- /dev/null +++ b/Trolleybus/Trolleybus/EntityTrolleybus.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Drawing; + +namespace Trolleybus +{ + /// + /// Класс-сущность "Троллейбус" + /// + internal class EntityTrolleybus + { + /// + /// Скорость + /// + 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) + { + Random rnd = new Random(); + Speed = speed <= 0? rnd.Next(50, 150): speed; + Weight = weight <= 0 ? rnd.Next(40, 70) : weight; + bodyColor = bodyColor; + } + } +} diff --git a/Trolleybus/Trolleybus/Form1.Designer.cs b/Trolleybus/Trolleybus/Form1.Designer.cs index b2e84f3..29311d9 100644 --- a/Trolleybus/Trolleybus/Form1.Designer.cs +++ b/Trolleybus/Trolleybus/Form1.Designer.cs @@ -29,13 +29,142 @@ namespace Trolleybus /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.button5 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.pictureBoxTrolleybus = new System.Windows.Forms.PictureBox(); + this.statusStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTrolleybus)).BeginInit(); + this.SuspendLayout(); + // + // statusStrip1 + // + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabelSpeed, + this.toolStripStatusLabelWeight, + this.toolStripStatusLabelBodyColor}); + this.statusStrip1.Location = new System.Drawing.Point(0, 428); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(800, 22); + this.statusStrip1.TabIndex = 1; + this.statusStrip1.Text = "statusStrip1"; + // + // toolStripStatusLabelSpeed + // + this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(59, 17); + this.toolStripStatusLabelSpeed.Text = "Скорость"; + // + // toolStripStatusLabelWeight + // + this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(26, 17); + this.toolStripStatusLabelWeight.Text = "Вес"; + // + // toolStripStatusLabelBodyColor + // + this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; + this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(33, 17); + this.toolStripStatusLabelBodyColor.Text = "Цвет"; + // + // buttonCreate + // + this.buttonCreate.Location = new System.Drawing.Point(12, 395); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(75, 23); + this.buttonCreate.TabIndex = 2; + this.buttonCreate.Text = "Создать"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + // + // button5 + // + this.button5.BackgroundImage = global::Trolleybus.Properties.Resources.up30; + this.button5.Location = new System.Drawing.Point(722, 359); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(30, 30); + this.button5.TabIndex = 6; + this.button5.Text = "button5"; + this.button5.UseVisualStyleBackColor = true; + // + // button4 + // + this.button4.Image = global::Trolleybus.Properties.Resources.right30; + this.button4.Location = new System.Drawing.Point(758, 395); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(30, 30); + this.button4.TabIndex = 5; + this.button4.Text = "button4"; + this.button4.UseVisualStyleBackColor = true; + // + // button3 + // + this.button3.BackgroundImage = global::Trolleybus.Properties.Resources.left30; + this.button3.Location = new System.Drawing.Point(686, 395); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(30, 30); + this.button3.TabIndex = 4; + this.button3.Text = "button3"; + this.button3.UseVisualStyleBackColor = true; + // + // button2 + // + this.button2.Image = global::Trolleybus.Properties.Resources.down30; + this.button2.Location = new System.Drawing.Point(722, 395); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(30, 30); + this.button2.TabIndex = 3; + this.button2.Text = "button2"; + this.button2.UseVisualStyleBackColor = true; + // + // pictureBoxTrolleybus + // + this.pictureBoxTrolleybus.Location = new System.Drawing.Point(0, 0); + this.pictureBoxTrolleybus.Name = "pictureBoxTrolleybus"; + this.pictureBoxTrolleybus.Size = new System.Drawing.Size(800, 425); + this.pictureBoxTrolleybus.TabIndex = 0; + this.pictureBoxTrolleybus.TabStop = false; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button5); + this.Controls.Add(this.button4); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.statusStrip1); + this.Controls.Add(this.pictureBoxTrolleybus); + this.Name = "Form1"; this.Text = "Form1"; + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTrolleybus)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private System.Windows.Forms.PictureBox pictureBoxTrolleybus; + private System.Windows.Forms.StatusStrip statusStrip1; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelSpeed; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelWeight; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelBodyColor; + private System.Windows.Forms.Button buttonCreate; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button5; } } diff --git a/Trolleybus/Trolleybus/Form1.cs b/Trolleybus/Trolleybus/Form1.cs index ff03b79..7455084 100644 --- a/Trolleybus/Trolleybus/Form1.cs +++ b/Trolleybus/Trolleybus/Form1.cs @@ -12,9 +12,39 @@ namespace Trolleybus { public partial class Form1 : Form { + private DrawingTrolleybus _trolleybus; public Form1() { InitializeComponent(); } + /// + /// Метод прорисовки троллейбуса + /// + + private void Draw() + { + Bitmap bmp = new Bitmap(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); + Graphics gr = Graphics.FromImage(bmp); + _trolleybus?.DrawTransport(gr); + pictureBoxTrolleybus.Image = bmp; + } + + /// + /// Обработка нажатия "Создать" + /// + /// + /// + + private void buttonCreate_Click(object sender, EventArgs e) + { + Random rnd = new Random(); + _trolleybus = new DrawingTrolleybus(); + _trolleybus.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + _trolleybus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); + toolStripStatusLabelSpeed.Text = $"Скорость: {_trolleybus.Trolleybus.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {_trolleybus.Trolleybus.Weight}"; + toolStripStatusLabelBodyColor.Text = $"Цвет: {_trolleybus.Trolleybus.BodyColor.Name}"; + Draw(); + } } } diff --git a/Trolleybus/Trolleybus/Form1.resx b/Trolleybus/Trolleybus/Form1.resx new file mode 100644 index 0000000..174ebc7 --- /dev/null +++ b/Trolleybus/Trolleybus/Form1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/Trolleybus/Trolleybus/Properties/Resources.Designer.cs b/Trolleybus/Trolleybus/Properties/Resources.Designer.cs index 2f95526..f10ee69 100644 --- a/Trolleybus/Trolleybus/Properties/Resources.Designer.cs +++ b/Trolleybus/Trolleybus/Properties/Resources.Designer.cs @@ -1,70 +1,103 @@ //------------------------------------------------------------------------------ // -// Этот код создан программным средством. -// Версия среды выполнения: 4.0.30319.42000 +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 // -// Изменения в этом файле могут привести к неправильному поведению и будут утрачены, если -// код создан повторно. +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. // //------------------------------------------------------------------------------ - -namespace Trolleybus.Properties -{ +namespace Trolleybus.Properties { + using System; + + /// - /// Класс ресурсов со строгим типом для поиска локализованных строк и пр. + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. /// - // Этот класс был автоматически создан при помощи StronglyTypedResourceBuilder - // класс с помощью таких средств, как ResGen или Visual Studio. - // Для добавления или удаления члена измените файл .ResX, а затем перезапустите ResGen - // с параметром /str или заново постройте свой VS-проект. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + // Этот класс создан автоматически классом 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 - { - + 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() - { + internal Resources() { } - + /// - /// Возврат кэшированного экземпляра ResourceManager, используемого этим классом. + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Trolleybus.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// - /// Переопределяет свойство CurrentUICulture текущего потока для всех - /// подстановки ресурсов с помощью этого класса ресурсов со строгим типом. + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap down30 { + get { + object obj = ResourceManager.GetObject("down30", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap left30 { + get { + object obj = ResourceManager.GetObject("left30", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap right30 { + get { + object obj = ResourceManager.GetObject("right30", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap up30 { + get { + object obj = ResourceManager.GetObject("up30", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } } } diff --git a/Trolleybus/Trolleybus/Properties/Resources.resx b/Trolleybus/Trolleybus/Properties/Resources.resx index af7dbeb..b5cfe0a 100644 --- a/Trolleybus/Trolleybus/Properties/Resources.resx +++ b/Trolleybus/Trolleybus/Properties/Resources.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,22 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\down30.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\left30.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\up30.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\right30.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/Trolleybus/Trolleybus/Resources/down30.png b/Trolleybus/Trolleybus/Resources/down30.png new file mode 100644 index 0000000..51b090e Binary files /dev/null and b/Trolleybus/Trolleybus/Resources/down30.png differ diff --git a/Trolleybus/Trolleybus/Resources/left30.png b/Trolleybus/Trolleybus/Resources/left30.png new file mode 100644 index 0000000..c5ac602 Binary files /dev/null and b/Trolleybus/Trolleybus/Resources/left30.png differ diff --git a/Trolleybus/Trolleybus/Resources/right30.png b/Trolleybus/Trolleybus/Resources/right30.png new file mode 100644 index 0000000..26c7b47 Binary files /dev/null and b/Trolleybus/Trolleybus/Resources/right30.png differ diff --git a/Trolleybus/Trolleybus/Resources/up30.png b/Trolleybus/Trolleybus/Resources/up30.png new file mode 100644 index 0000000..286e01a Binary files /dev/null and b/Trolleybus/Trolleybus/Resources/up30.png differ diff --git a/Trolleybus/Trolleybus/Trolleybus.csproj b/Trolleybus/Trolleybus/Trolleybus.csproj index 5cb518c..ce41cd2 100644 --- a/Trolleybus/Trolleybus/Trolleybus.csproj +++ b/Trolleybus/Trolleybus/Trolleybus.csproj @@ -46,6 +46,9 @@ + + + Form @@ -54,6 +57,9 @@ + + Form1.cs + ResXFileCodeGenerator Resources.Designer.cs @@ -62,6 +68,7 @@ True Resources.resx + True SettingsSingleFileGenerator @@ -76,5 +83,17 @@ + + + + + + + + + + + + \ No newline at end of file