From 9b810760470cf9ec625d74911716955834ec34ab Mon Sep 17 00:00:00 2001 From: Oleg Date: Tue, 13 Sep 2022 11:17:44 +0400 Subject: [PATCH 1/5] =?UTF-8?q?Lab1.=20=D0=94=D0=BE=D0=B4=D0=BB=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D1=82=D1=8C=20=D0=B4=D0=BE=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Trolleybus/Trolleybus/Direction.cs | 19 +++ Trolleybus/Trolleybus/DrawingTrolleybus.cs | 140 ++++++++++++++++++ Trolleybus/Trolleybus/EntityTrolleybus.cs | 46 ++++++ Trolleybus/Trolleybus/Form1.Designer.cs | 131 +++++++++++++++- Trolleybus/Trolleybus/Form1.cs | 30 ++++ Trolleybus/Trolleybus/Form1.resx | 123 +++++++++++++++ .../Properties/Resources.Designer.cs | 107 ++++++++----- .../Trolleybus/Properties/Resources.resx | 26 +++- Trolleybus/Trolleybus/Resources/down30.png | Bin 0 -> 2030 bytes Trolleybus/Trolleybus/Resources/left30.png | Bin 0 -> 2112 bytes Trolleybus/Trolleybus/Resources/right30.png | Bin 0 -> 2138 bytes Trolleybus/Trolleybus/Resources/up30.png | Bin 0 -> 1986 bytes Trolleybus/Trolleybus/Trolleybus.csproj | 19 +++ 13 files changed, 598 insertions(+), 43 deletions(-) create mode 100644 Trolleybus/Trolleybus/Direction.cs create mode 100644 Trolleybus/Trolleybus/DrawingTrolleybus.cs create mode 100644 Trolleybus/Trolleybus/EntityTrolleybus.cs create mode 100644 Trolleybus/Trolleybus/Form1.resx create mode 100644 Trolleybus/Trolleybus/Resources/down30.png create mode 100644 Trolleybus/Trolleybus/Resources/left30.png create mode 100644 Trolleybus/Trolleybus/Resources/right30.png create mode 100644 Trolleybus/Trolleybus/Resources/up30.png 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 0000000000000000000000000000000000000000..51b090e913d382bba3b2ba6616ca0dc4e6c69df9 GIT binary patch literal 2030 zcmd^A_fyk}5)ah`9@Rstg6L6#^dN@@ga8i^B$Oa{k)k0Gj1rF^#ZUwRMUOUw)^MFIo@NjW*% zc>po@r-8)*?|$sA2m}!#!U+WigU4r(UjZmY^l(6cD*Dux0U#P|bIk?>Vr57k+!6yY z2){l<)}$NB#=03l&D2ahBd{r{ zrpADUA=QNv&z@O7)G5|XEY?i6Gl9l{-{VHELGy05$;00vd$DVE$Hz_a>N~^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dg#t#jd)|aVw~lEp8!Gm}s&Yv`<1yh4WBsIvol<9a8~c zNe?uuq2iOW_n@>u;`~OYP&HY+<}vPmF+()g!5P>? z_j%P1l@1@C220$AxLfN2CnAx^<182LC$5aQ@kd9EAZOdSyuQA_m`pU3Luyncw%LJ%oUxNDI~Oh1nTYt+D+xPWFW`WPWGJ*8DH>`B;{g(s zH@H`O%W{8o+VLl$!;;M(-@m>|Y1pd|(|D$S}v=7w^0Sipei+>> zC=Cv9un!@PwNzf4>cq;ldLiJViMR4ln*=s|#iG(aB%mdU8EB>tk+^Jf2VauL@N--y zkCV^dpKFOgcoGQzfv>0$?L(w%FJdr^AQFs#tMYSJNlD2rHO+Qyd2FmKzbVf_``|;7 zNW>lFXo-J_UL0U~MMS_lXATPnSbaaas!?49$JTbXsnXEhJ>mLjex5L!*_m-b%k9OB z7d*!Gg~5|9=g#f7X||V$x8G@HqC&fi&Qm+Mz6l9d{r&w|avrWlqikxh7e67^BrXg- z=P~*Q22MBy>V4jyD?BWW>(4~KBH$M~a*o2UO=7~wkJPC_6L%%2KQc~xLE~t!%uXqy z@L!wbd7Rif4d^cf+*CN~B6Igu0)AnD3;*w~VNuW!+YR!VCP zZjisMSDo?6K17p>XbzB5mzSf{wU=E9@1!%`g;E(8R) zhlhvr5@zm_GAS*p(3}}{q6!__0)+||)rk+ntoCfj?}o9Xr9opR8t*zB^Ov$zo%SV( znm^FL`C~SGXKP)GpK}HV27EqWHvss0GXeiFe_7M2P4)jYptK!9n4iEcrTGobBPdI0 PqXV!GZkRf|z_kAY>$LR@ literal 0 HcmV?d00001 diff --git a/Trolleybus/Trolleybus/Resources/right30.png b/Trolleybus/Trolleybus/Resources/right30.png new file mode 100644 index 0000000000000000000000000000000000000000..26c7b47bf9541857ebddeccd1c0e6df8cf3a6a8a GIT binary patch literal 2138 zcmaKtdpy(oAIHa*P@DT`;X7__4?3A_BIOgs`3yB zM1f#yLn=DeK7kF)7k2>%fjmpy zCHC3@_HseCZlMs!p5~t=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G*|P@#fmx=V%~r>M)ISvfb@z5-Lc$;Y0l<9vF8}}l literal 0 HcmV?d00001 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 From 717fbc3ca5c5dc6d037b5420a20a1c2d3c62fbd8 Mon Sep 17 00:00:00 2001 From: Oleg Date: Sat, 17 Sep 2022 18:06:08 +0400 Subject: [PATCH 2/5] intermediate 1 --- Trolleybus/Trolleybus/DrawingTrolleybus.cs | 31 +++++++++++++++++++++- Trolleybus/Trolleybus/Form1.Designer.cs | 22 +++++++-------- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Trolleybus/Trolleybus/DrawingTrolleybus.cs b/Trolleybus/Trolleybus/DrawingTrolleybus.cs index f1ac88b..5ba3a9d 100644 --- a/Trolleybus/Trolleybus/DrawingTrolleybus.cs +++ b/Trolleybus/Trolleybus/DrawingTrolleybus.cs @@ -110,7 +110,36 @@ namespace Trolleybus /// public void DrawTransport(Graphics g) { - + if (_startPosX < 0 || _startPosY < 0 + || !_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + Pen pen = new Pen(Color.Black); + Brush brBlue = new SolidBrush(Color.LightBlue); + Brush dBlue = new SolidBrush(Color.DarkBlue); + Brush bWhite = new SolidBrush(Color.White); + g.DrawRectangle(pen, _startPosX, _startPosY, 200, 50); + g.DrawRectangle(pen, _startPosX + 100, _startPosY + 10, 20, 40); + Pen WinBlue = new Pen(Color.Blue); + g.FillEllipse(brBlue, _startPosX, _startPosY + 5, 20, 25); + g.DrawEllipse(WinBlue, _startPosX, _startPosY + 5, 20, 25); + g.FillEllipse(brBlue, _startPosX + 25, _startPosY + 5, 20, 25); + g.DrawEllipse(WinBlue, _startPosX + 25, _startPosY + 5, 20, 25); + g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 5, 20, 25); + g.DrawEllipse(WinBlue, _startPosX + 50, _startPosY + 5, 20, 25); + g.FillEllipse(brBlue, _startPosX + 75, _startPosY + 5, 20, 25); + g.DrawEllipse(WinBlue, _startPosX + 75, _startPosY + 5, 20, 25); + g.FillEllipse(brBlue, _startPosX + 120, _startPosY + 5, 20, 25); + g.DrawEllipse(WinBlue, _startPosX + 120, _startPosY + 5, 20, 25); + g.FillEllipse(brBlue, _startPosX + 145, _startPosY + 5, 20, 25); + g.DrawEllipse(WinBlue, _startPosX + 145, _startPosY + 5, 20, 25); + g.FillEllipse(brBlue, _startPosX + 170, _startPosY + 5, 20, 25); + g.DrawEllipse(WinBlue, _startPosX + 170, _startPosY + 5, 20, 25); + g.FillEllipse(bWhite, _startPosX, _startPosY + 40, 30, 30); + g.DrawEllipse(pen, _startPosX, _startPosY + 40, 30, 30); + g.FillEllipse(bWhite, _startPosX + 170, _startPosY + 40, 30, 30); + g.DrawEllipse(pen, _startPosX + 170, _startPosY + 40, 30, 30); } /// /// Смена границ формы отрисовки diff --git a/Trolleybus/Trolleybus/Form1.Designer.cs b/Trolleybus/Trolleybus/Form1.Designer.cs index 29311d9..753eeea 100644 --- a/Trolleybus/Trolleybus/Form1.Designer.cs +++ b/Trolleybus/Trolleybus/Form1.Designer.cs @@ -75,7 +75,7 @@ namespace Trolleybus // // buttonCreate // - this.buttonCreate.Location = new System.Drawing.Point(12, 395); + this.buttonCreate.Location = new System.Drawing.Point(12, 390); this.buttonCreate.Name = "buttonCreate"; this.buttonCreate.Size = new System.Drawing.Size(75, 23); this.buttonCreate.TabIndex = 2; @@ -86,41 +86,41 @@ namespace Trolleybus // button5 // this.button5.BackgroundImage = global::Trolleybus.Properties.Resources.up30; - this.button5.Location = new System.Drawing.Point(722, 359); + this.button5.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.button5.Location = new System.Drawing.Point(729, 347); 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.BackgroundImage = global::Trolleybus.Properties.Resources.right30; + this.button4.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.button4.Location = new System.Drawing.Point(765, 383); 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.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.button3.Location = new System.Drawing.Point(693, 383); 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.BackgroundImage = global::Trolleybus.Properties.Resources.down30; + this.button2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.button2.Location = new System.Drawing.Point(729, 383); 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 From 9b74a54dbfa8c877ebe55be666bd7b4eb2b6cf2f Mon Sep 17 00:00:00 2001 From: Oleg Date: Sat, 17 Sep 2022 20:19:26 +0400 Subject: [PATCH 3/5] Intermediate 2 --- Trolleybus/Trolleybus/DrawingTrolleybus.cs | 32 +++++--- Trolleybus/Trolleybus/Form1.Designer.cs | 96 +++++++++++----------- Trolleybus/Trolleybus/Form1.cs | 30 ++++++- 3 files changed, 101 insertions(+), 57 deletions(-) diff --git a/Trolleybus/Trolleybus/DrawingTrolleybus.cs b/Trolleybus/Trolleybus/DrawingTrolleybus.cs index 5ba3a9d..e50e156 100644 --- a/Trolleybus/Trolleybus/DrawingTrolleybus.cs +++ b/Trolleybus/Trolleybus/DrawingTrolleybus.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; +using System.Windows.Forms; namespace Trolleybus { @@ -22,6 +23,14 @@ namespace Trolleybus /// private float _startPosY; /// + /// левая координата начала отрисовки + /// + private float _startX; + /// + /// Верхняя координата начала отрисовки + /// + private float _startY; + /// /// Ширина окна отрисовки /// private int? _pictureWidth = null; @@ -32,11 +41,11 @@ namespace Trolleybus /// /// Ширина отрисовки /// - protected readonly int _trolleybusWidth = 0; + protected readonly int _trolleybusWidth = 200; /// /// Высота отрисовки /// - protected readonly int _trolleybusHeight = 0; + protected readonly int _trolleybusHeight = 50; /// /// Инициализация свойств /// @@ -55,10 +64,13 @@ namespace Trolleybus /// Координата Y /// Ширина картинки /// Высота картинки - public void SetPosition(int x, int y, int width, int height) +// public void SetPosition(int x, int y, int startX, int startY, int width, int height) + public void SetPosition(int x, int y, int startX, int startY, int width, int height) { _startPosX = x; _startPosY = y; + _startX = startX; + _startY = startY; _pictureWidth = width; _pictureHeight = height; } @@ -76,30 +88,30 @@ namespace Trolleybus { //вправо case Direction.Right: - if(_startPosX + _trolleybusWidth + Trolleybus.Step< _pictureWidth) + if(_startPosX + _trolleybusWidth + Trolleybus.Step < _pictureWidth) { _startPosX += Trolleybus.Step; } break; //влево case Direction.Left: - if (_startPosX + _trolleybusWidth - Trolleybus.Step < _pictureWidth) + if (_startPosX > _startX) { - _startPosX += Trolleybus.Step; + _startPosX -= Trolleybus.Step; } break; //вверх case Direction.Up: - if (_startPosX + _trolleybusWidth - Trolleybus.Step < _pictureHeight) + if (_startPosY > _startY) { - _startPosX += Trolleybus.Step; + _startPosY -= Trolleybus.Step; } break; //вниз case Direction.Down: - if (_startPosX + _trolleybusWidth + Trolleybus.Step < _pictureHeight) + if (_startPosY + _trolleybusHeight + Trolleybus.Step < _pictureHeight) { - _startPosX += Trolleybus.Step; + _startPosY += Trolleybus.Step; } break; } diff --git a/Trolleybus/Trolleybus/Form1.Designer.cs b/Trolleybus/Trolleybus/Form1.Designer.cs index 753eeea..7160c1d 100644 --- a/Trolleybus/Trolleybus/Form1.Designer.cs +++ b/Trolleybus/Trolleybus/Form1.Designer.cs @@ -34,10 +34,10 @@ namespace Trolleybus 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.buttonUp = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); this.pictureBoxTrolleybus = new System.Windows.Forms.PictureBox(); this.statusStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTrolleybus)).BeginInit(); @@ -83,51 +83,55 @@ namespace Trolleybus this.buttonCreate.UseVisualStyleBackColor = true; this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); // - // button5 + // buttonUp // - this.button5.BackgroundImage = global::Trolleybus.Properties.Resources.up30; - this.button5.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.button5.Location = new System.Drawing.Point(729, 347); - this.button5.Name = "button5"; - this.button5.Size = new System.Drawing.Size(30, 30); - this.button5.TabIndex = 6; - this.button5.UseVisualStyleBackColor = true; + this.buttonUp.BackgroundImage = global::Trolleybus.Properties.Resources.up30; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(729, 347); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 6; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); // - // button4 + // buttonRight // - this.button4.BackgroundImage = global::Trolleybus.Properties.Resources.right30; - this.button4.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.button4.Location = new System.Drawing.Point(765, 383); - this.button4.Name = "button4"; - this.button4.Size = new System.Drawing.Size(30, 30); - this.button4.TabIndex = 5; - this.button4.UseVisualStyleBackColor = true; + this.buttonRight.BackgroundImage = global::Trolleybus.Properties.Resources.right30; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(765, 383); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 5; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); // - // button3 + // buttonLeft // - this.button3.BackgroundImage = global::Trolleybus.Properties.Resources.left30; - this.button3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.button3.Location = new System.Drawing.Point(693, 383); - this.button3.Name = "button3"; - this.button3.Size = new System.Drawing.Size(30, 30); - this.button3.TabIndex = 4; - this.button3.UseVisualStyleBackColor = true; + this.buttonLeft.BackgroundImage = global::Trolleybus.Properties.Resources.left30; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(693, 383); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 4; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); // - // button2 + // buttonDown // - this.button2.BackgroundImage = global::Trolleybus.Properties.Resources.down30; - this.button2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.button2.Location = new System.Drawing.Point(729, 383); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(30, 30); - this.button2.TabIndex = 3; - this.button2.UseVisualStyleBackColor = true; + this.buttonDown.BackgroundImage = global::Trolleybus.Properties.Resources.down30; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(729, 383); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 3; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); // // pictureBoxTrolleybus // - this.pictureBoxTrolleybus.Location = new System.Drawing.Point(0, 0); + this.pictureBoxTrolleybus.Location = new System.Drawing.Point(12, 12); this.pictureBoxTrolleybus.Name = "pictureBoxTrolleybus"; - this.pictureBoxTrolleybus.Size = new System.Drawing.Size(800, 425); + this.pictureBoxTrolleybus.Size = new System.Drawing.Size(776, 413); this.pictureBoxTrolleybus.TabIndex = 0; this.pictureBoxTrolleybus.TabStop = false; // @@ -136,10 +140,10 @@ namespace Trolleybus 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.buttonUp); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonCreate); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.pictureBoxTrolleybus); @@ -161,10 +165,10 @@ namespace Trolleybus 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; + private System.Windows.Forms.Button buttonDown; + private System.Windows.Forms.Button buttonLeft; + private System.Windows.Forms.Button buttonRight; + private System.Windows.Forms.Button buttonUp; } } diff --git a/Trolleybus/Trolleybus/Form1.cs b/Trolleybus/Trolleybus/Form1.cs index 7455084..07959cc 100644 --- a/Trolleybus/Trolleybus/Form1.cs +++ b/Trolleybus/Trolleybus/Form1.cs @@ -40,11 +40,39 @@ namespace Trolleybus 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); + _trolleybus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), Location.X, Location.Y, pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); +// _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(); } + + private void ButtonMove_Click(object sender, EventArgs e) + { + //получаем имя кнопки + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _trolleybus?.MoveTransport(Direction.Up); + break; + case "buttonDown": + _trolleybus?.MoveTransport(Direction.Down); + break; + case "buttonLeft": + _trolleybus?.MoveTransport(Direction.Left); + break; + case "buttonRight": + _trolleybus?.MoveTransport(Direction.Right); + break; + } + Draw(); + } + private void PictureBoxTrolleybus_Resize(object sender, EventArgs e) + { + _trolleybus?.ChangeBorders(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); + Draw(); + } } } From 9da23c5b30f1a00705755f9e3caf74feb5e830b4 Mon Sep 17 00:00:00 2001 From: Oleg Date: Sat, 17 Sep 2022 20:30:26 +0400 Subject: [PATCH 4/5] Final --- Trolleybus/Trolleybus/DrawingTrolleybus.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Trolleybus/Trolleybus/DrawingTrolleybus.cs b/Trolleybus/Trolleybus/DrawingTrolleybus.cs index e50e156..d963d78 100644 --- a/Trolleybus/Trolleybus/DrawingTrolleybus.cs +++ b/Trolleybus/Trolleybus/DrawingTrolleybus.cs @@ -9,7 +9,7 @@ using System.Windows.Forms; namespace Trolleybus { /// - /// Класс прорисовки и перемещения + /// Класс прорисовки и перемещения объекта /// internal class DrawingTrolleybus { From ee9c15b506bb664749b2810c266cb5eb4465e771 Mon Sep 17 00:00:00 2001 From: Oleg Date: Fri, 30 Sep 2022 11:22:36 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D1=89?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BB=D0=B5=D0=B2=D0=BE=20?= =?UTF-8?q?=D0=B8=20=D0=B2=D0=B2=D0=B5=D1=80=D1=85.=20=D0=98=D1=81=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20pictureBox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Trolleybus/Trolleybus/DrawingTrolleybus.cs | 14 +++++++------- Trolleybus/Trolleybus/Form1.Designer.cs | 4 ++-- Trolleybus/Trolleybus/Form1.cs | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Trolleybus/Trolleybus/DrawingTrolleybus.cs b/Trolleybus/Trolleybus/DrawingTrolleybus.cs index d963d78..a2e0bdf 100644 --- a/Trolleybus/Trolleybus/DrawingTrolleybus.cs +++ b/Trolleybus/Trolleybus/DrawingTrolleybus.cs @@ -25,11 +25,11 @@ namespace Trolleybus /// /// левая координата начала отрисовки /// - private float _startX; + //private float _startX; /// /// Верхняя координата начала отрисовки /// - private float _startY; + //private float _startY; /// /// Ширина окна отрисовки /// @@ -65,12 +65,12 @@ namespace Trolleybus /// Ширина картинки /// Высота картинки // public void SetPosition(int x, int y, int startX, int startY, int width, int height) - public void SetPosition(int x, int y, int startX, int startY, int width, int height) + public void SetPosition(int x, int y, int width, int height) { _startPosX = x; _startPosY = y; - _startX = startX; - _startY = startY; +// _startX = startX; +// _startY = startY; _pictureWidth = width; _pictureHeight = height; } @@ -95,14 +95,14 @@ namespace Trolleybus break; //влево case Direction.Left: - if (_startPosX > _startX) + if (_startPosX - Trolleybus.Step > 0) { _startPosX -= Trolleybus.Step; } break; //вверх case Direction.Up: - if (_startPosY > _startY) + if (_startPosY - Trolleybus.Step > 0) { _startPosY -= Trolleybus.Step; } diff --git a/Trolleybus/Trolleybus/Form1.Designer.cs b/Trolleybus/Trolleybus/Form1.Designer.cs index 7160c1d..46cbfec 100644 --- a/Trolleybus/Trolleybus/Form1.Designer.cs +++ b/Trolleybus/Trolleybus/Form1.Designer.cs @@ -129,9 +129,9 @@ namespace Trolleybus // // pictureBoxTrolleybus // - this.pictureBoxTrolleybus.Location = new System.Drawing.Point(12, 12); + this.pictureBoxTrolleybus.Location = new System.Drawing.Point(0, -1); this.pictureBoxTrolleybus.Name = "pictureBoxTrolleybus"; - this.pictureBoxTrolleybus.Size = new System.Drawing.Size(776, 413); + this.pictureBoxTrolleybus.Size = new System.Drawing.Size(800, 451); this.pictureBoxTrolleybus.TabIndex = 0; this.pictureBoxTrolleybus.TabStop = false; // diff --git a/Trolleybus/Trolleybus/Form1.cs b/Trolleybus/Trolleybus/Form1.cs index 07959cc..0fb3bf8 100644 --- a/Trolleybus/Trolleybus/Form1.cs +++ b/Trolleybus/Trolleybus/Form1.cs @@ -40,8 +40,8 @@ namespace Trolleybus 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), Location.X, Location.Y, pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); -// _trolleybus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); + //_trolleybus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), Location.X, Location.Y, pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); + _trolleybus.SetPosition(rnd.Next(10, 100), rnd.Next(pictureBoxTrolleybus.Size.Height - 150, pictureBoxTrolleybus.Size.Height - 100), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height); toolStripStatusLabelSpeed.Text = $"Скорость: {_trolleybus.Trolleybus.Speed}"; toolStripStatusLabelWeight.Text = $"Вес: {_trolleybus.Trolleybus.Weight}"; toolStripStatusLabelBodyColor.Text = $"Цвет: {_trolleybus.Trolleybus.BodyColor.Name}";